Hi guys, I met a problem in coding while using Esp32 with Anemometer in Arduino software. The serial monitor did not give a proper output. However, with the same coding, I can get the correct output when I use Arduino Uno microcontroller with the Anemometer.
Sample code:
#define READ_TIME 1000 //ms
#define WIND_SENSOR_PIN 2 //wind sensor pin
#define WIND_SPEED_20_PULSE_SECOND 1.75 //in m/s this value depend on the sensor type
#define ONE_ROTATION_SENSOR 20.0
volatile unsigned long Rotations; //Cup rotation counter used in interrupt routine
float WindSpeed; //Speed meter per second
unsigned long gulStart_Read_Timer = 0;
void setup(){
Serial.begin(9600);
pinMode(WIND_SENSOR_PIN,INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(WIND_SENSOR_PIN),isr_rotation, CHANGE); //Set up the interrupt
Serial.println("Rotations\tm/s");
sei(); //Enables interrupts
gulStart_Read_Timer - millis();
}
void loop()
{
if((millis() - gulStart_Read_Timer) >= READ_TIME)
{
cli(); //Disable interrupts
//convert rotation to wind speed in m/s
WindSpeed = WIND_SPEED_20_PULSE_SECOND/ONE_ROTATION_SENSOR*(float)Rotations;
Serial.print(Rotations); Serial.print("\t\t");
Serial.println(WindSpeed);
sei(); //Enables interrupts
Rotations = 0; //Set Rotations count to 0 ready for calculations
gulStart_Read_Timer = millis();
}
}
// This is the function that the interrupt calls to increment the rotation count
void isr_rotation()
{
Rotations++;
}
Esp32 with Anemometer need help in coding
-
- Posts: 101
- Joined: Tue Mar 22, 2022 5:23 am
Re: Esp32 with Anemometer need help in coding
I think you'll get more responses if you kindly share the connection diagram of your circuit.
-
- Posts: 826
- Joined: Mon Jul 22, 2019 3:20 pm
Re: Esp32 with Anemometer need help in coding
Post the output you are expecting, and what you are getting. Saying "there is a problem" is not very helpful.
Who is online
Users browsing this forum: Baidu [Spider] and 69 guests