Hello everybody,
I am completely new to arduino and one of the first projects am working on is this tachometer from pyroelectro.com. The link to the tutorial is given below:
http://www.pyroelectro.com/tutorials/tachometer_rpm_arduino/index.html
I followed all the steps exactly as described (almost blindly, I must say) and used the same exact components on an arduino UNO. But am not able to make the tachometer work properly.
The values (in RPM) that I am obtaining on my LCD display are extremely erratic. The values fluctuate very greatly and never stabilize. Often negative values are obtained too.
The sketch used is shown below:
In my opinion, the error may be comes from the sketch. From the basic knowledge that I have acquired (may be i am completely wrong), I find that the function fan_interrupt() is not used anywhere in the LOOP section. Is this correct?
Any help would be much appreciated.
Thanks
I am completely new to arduino and one of the first projects am working on is this tachometer from pyroelectro.com. The link to the tutorial is given below:
http://www.pyroelectro.com/tutorials/tachometer_rpm_arduino/index.html
I followed all the steps exactly as described (almost blindly, I must say) and used the same exact components on an arduino UNO. But am not able to make the tachometer work properly.
The values (in RPM) that I am obtaining on my LCD display are extremely erratic. The values fluctuate very greatly and never stabilize. Often negative values are obtained too.
The sketch used is shown below:
Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(3, 5, 9, 10, 11, 12);
volatile float time = 0;
volatile float time_last = 0;
volatile int rpm_array[5] = {0,0,0,0,0};
void setup()
{
//Digital Pin 2 Set As An Interrupt
attachInterrupt(0, fan_interrupt, FALLING);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Current RPM:");
}
//Main Loop To Calculate RPM and Update LCD Display
void loop()
{
int rpm = 0;
while(1){
//Slow Down The LCD Display Updates
delay(400);
//Clear The Bottom Row
lcd.setCursor(0, 1);
lcd.print(" ");
//Update The Rpm Count
lcd.setCursor(0, 1);
lcd.print(rpm);
////lcd.setCursor(4, 1);
////lcd.print(time);
//Update The RPM
if(time > 0)
{
//5 Sample Moving Average To Smooth Out The Data
rpm_array[0] = rpm_array[1];
rpm_array[1] = rpm_array[2];
rpm_array[2] = rpm_array[3];
rpm_array[3] = rpm_array[4];
rpm_array[4] = 60*(1000000/(time*7));
//Last 5 Average RPM Counts Eqauls....
rpm = (rpm_array[0] + rpm_array[1] + rpm_array[2] + rpm_array[3] + rpm_array[4]) / 5;
}
}
}
//Capture The IR Break-Beam Interrupt
void fan_interrupt()
{
time = (micros() - time_last);
time_last = micros();
}
In my opinion, the error may be comes from the sketch. From the basic knowledge that I have acquired (may be i am completely wrong), I find that the function fan_interrupt() is not used anywhere in the LOOP section. Is this correct?
Any help would be much appreciated.
Thanks