0
#include<LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 6, 5, 4, 3);
float value = 0;
float rev = 0;
int rpm;
int oldtime = 0;
int time;

void isr() //interrupt service routine
{
  rev++;
}

void setup()
{
  lcd.begin(16, 2);                //initialize LCD
  attachInterrupt(0, isr, RISING); //attaching the interrupt
}

void loop()
{
  delay(1000);
  detachInterrupt(0);           //detaches the interrupt
  time = millis() - oldtime;    //finds the time
  rpm = (rev / time) * 60000;   //calculates rpm
  oldtime = millis();           //saves the current time
  rev = 0;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("___TACHOMETER___");
  lcd.setCursor(0, 1);
  lcd.print(     rpm);
  lcd.print(" RPM");
  lcd.print("   ");
  attachInterrupt(0, isr, RISING);
}

enter image description here

  • rev should be volatile unsigned long and not float – chrisl Sep 6 at 17:28
  • 1
    Is the LCD connected correctly? How does it behave, when you don't use the interrupt (just the LCD code) – chrisl Sep 6 at 17:29
  • Brother ...i dont have much idea about arduino....can you help me out with new code....i can assure that connections are correct – USAMA ARAB Sep 7 at 5:52
  • Comment all the calls to attachInterrupt() and detachInterrupt() out by adding double slash // at the start of these lines. Then program the Arduino again and see, if the LCD now shows something correct. Just to make sure, that the interrupt is not the problem – chrisl Sep 7 at 7:38
  • Ok i will try and let you know – USAMA ARAB Sep 7 at 23:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.