Hello,
I am trying to build a meter wich can calculate/test the RPM of an fan with a hall sensor. With the code i have so far it is not working.
What the code should do so far is counting the incoming pulses in one second. But as of now, it is not displaying anything on the display. i tried to display it on the serial monitor but it is still displaying zero's. Strange thing is, whenever i supply the arduino with some pulses it show's 6 or 7 pulses for 1 second and then jumps right back to zero pulses.
Can you guys give a quick look and maybe give me some advice what i should do different?
The code i've come up so far is this:
#include <LiquidCrystal.h> // lcd display library
LiquidCrystal lcd(12, 11, 6, 5, 4, 3); // data input pins for the lcd display
int pulse = 0; // variable to store the incoming pulses
const byte hallSensor = 2; //pin where the hall sensor is attached to
void setup()
{
lcd.begin(16,2); // lcd display = 16x2
pinMode (hallSensor, INPUT_PULLUP); // pin 2 = input with pull-up
attachInterrupt(digitalPinToInterrupt(hallSensor), pulses, FALLING); // interrupt for incoming pulses
}
void loop()
{
pulse = 0; // clear the variable "pulse"
interrupts(); // let the interrupts come in
delay(1000); // 1 second delay to let the interrupt come in to be stored in the variable "pulse"
noInterrupts(); // stop the interrupt so they can be written to the lcd screen
lcd.clear(); // clear the lcd display
lcd.print("RPM = ");
lcd.setCursor (6,0);
lcd.print(pulse); // RPM = "pulse value"
}
void pulses() // subroutine for counting the pulses coming in from the interrupt
{
pulse++; // pulse = pulse + 1
}