Fan with hall sensor meter

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
}

Can you provide more information about the hall sensor. Do you have specifications? How is it wired? Can you provide a sketch of your wiring.

If you use a simple sketch with digitalRead() in a loop, can you place the magnet in front of the hall sensor and read a signal different from when the magnet is not present?

One quick thing to try would be to use a 4.7k ohm external pull up on the sensor output to the Arduino. The internal pullups may not be strong enough.

Perhaps add 'volatile' to the definition of 'pulse' eg

volatile int pulse=0;

Adding this marks it as something that can be modified inside an interupt

Perhaps you shouldn't be disabling interrupts while talking to the LCD...

Just disable interrupts while reading/writing the variable pulse, which needs to be volatile:

volatile int pulse = 0 ;
unsigned long last_time = 0 ;

#define DELAY 1000

void loop ()
{
  if (millis () - last_time >= DELAY)  // standard way to schedule action every DELAY ms
  {
    last_time += DELAY ;

    noInterrupts () ;   // read and write pulse safely
    int my_pulse = pulse ;
    pulse = 0 ;
    interrupts () ;

    //... handle writing to the LCD now
  }
  // other stuff here
}