Esp32 with Anemometer need help in coding

Teddy123
Posts: 2
Joined: Sat Apr 02, 2022 3:26 pm

Esp32 with Anemometer need help in coding

Postby Teddy123 » Mon Apr 04, 2022 8:21 am

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++;
}

rpiloverbd
Posts: 101
Joined: Tue Mar 22, 2022 5:23 am

Re: Esp32 with Anemometer need help in coding

Postby rpiloverbd » Tue Apr 05, 2022 10:02 am

I think you'll get more responses if you kindly share the connection diagram of your circuit.

lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: Esp32 with Anemometer need help in coding

Postby lbernstone » Wed Apr 06, 2022 12:02 am

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: No registered users and 96 guests