arduino hall sensor rpm code example
Example: arduino rpm sensor
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
const int pinIRSensor = 2;
float rpm = 0;
float rev = 0;
unsigned long oldtime = 0;
unsigned long time;
void isr() {
rev++;
}
void setup() {
lcd.begin();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(" RPM-IR-Sensor: ");
attachInterrupt(digitalPinToInterrupt (pinIRSensor), isr, RISING);
}
void loop() {
delay(1000);
detachInterrupt(digitalPinToInterrupt(pinRPM));
time = millis() - oldtime;
rpm = ((float) rev / (float) time) * 60000.f;
oldtime = millis();
rev = 0;
lcd.setCursor(0, 1);
lcd.print(rpm);
lcd.print(" r/min");
attachInterrupt(digitalPinToInterrupt(pinRPM), isr, RISING);
}