Hey everyone,
got a littler problem with my project. I want to display the rpm on a LCD.
I have a Hall Sensor with works fine. The whole programm works and the RPM gets displayed very well.
But: After some time running (around 5 seconds) the value on the Display does not get updatet anymore. i don't find a solution
Seems that the arduino fails or something..
Please help
Regards Phil
// read RPM
#include <LiquidCrystal.h>
int half_revolutions = 0;
int rpm = 0;
unsigned long lastmillis = 0;
int led = 13;
LiquidCrystal lcd(12, 11, 5, 4, 3, 8);
void setup(){
Serial.begin(9600);
attachInterrupt(0, rpm_fan, FALLING);
pinMode(led, OUTPUT);
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
}
void loop(){
if (millis() - lastmillis == 333){ //Uptade every 1/3 second, this will be equal to reading 1/3 frecuency (Hz).
detachInterrupt(0);//Disable interrupt when calculating
rpm = half_revolutions * 6; // Convert frecuency to RPM, note: 6 because 1/3 frequency and multiplied by 2 because of half recolutions 6 = 2 * 3.
if(rpm < 10){
lcd.clear();
lcd.setCursor(0, 2);
lcd.print(rpm);
}
if(rpm > 10){
lcd.setCursor(0, 2);
lcd.print(rpm);
}
if(rpm > 100){
lcd.clear();
lcd.setCursor(0, 2);
lcd.print(rpm);
}
half_revolutions = 0; // Restart the RPM counter
lastmillis = millis(); // Uptade lasmillis
attachInterrupt(0, rpm_fan, FALLING); //enable interrupt
} } // this code will be executed every time the interrupt 0 (pin2) gets low.
void rpm_fan(){
half_revolutions++;
}