Wind speed measuring using hall sensor & Arduino

Hi!

I require your help regarding a problem I’m encountering.

I need to measure wind speed using Hall sensor. I have an Arduino code for that. But it shows nothing on the serial monitor. The code is below. Can help me figure what is wrong with it?

volatile byte revolutions;

unsigned int rpmilli;
float speed;

unsigned long timeold=0;

void setup()
{
Serial.begin(9600);
attachInterrupt(2, rpm_fun, RISING);

revolutions = 0;
rpmilli = 0;
timeold = 0;
}

void loop()
{
if (revolutions >= 1) {
//Update RPM every 20 counts, increase this for better RPM resolution,
//decrease for faster update

// calculate the revolutions per milli(second)
rpmilli = revolutions/(millis()-timeold);

timeold = millis();
revolutions = 0;
// WHEELCIRC = 2 * PI * radius (in meters)
// speed = rpmilli * WHEELCIRC * “milliseconds per hour” / “meters per kilometer”

// simplify the equation to reduce the number of floating point operations
// speed = rpmilli * WHEELCIRC * 3600000 / 1000
// speed = rpmilli * WHEELCIRC * 3600

speed = rpmilli * 2.074*3600;

Serial.print(“RPM:”);
Serial.print(rpmilli * 60000 ,DEC);
Serial.print(" Speed:");
Serial.print(speed,DEC);
Serial.println(" kph");
}
}

void rpm_fun()
{
revolutions++;
}

Thank you so much in advance for your help!

Hello @janith!

Did you configure the correct baud rate on the serial monitor?

Which hall sensor are you using?

1 Like

Baud rate set to 9600.
Sensor model: SE014

Try changing this line:

attachInterrupt(2, rpm_fun, RISING);

to


attachInterrupt(digitalPinToInterrupt(2), rpm_fun, RISING);

Let me know if that works

Yes. It did work. Thank you so much :heart_eyes:

1 Like