Arduino Tachometer using IR

Thread Starter

electro_2015

Joined Jan 1, 2015
10
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:

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
 

ScottWang

Joined Aug 23, 2012
7,400
The hardware has some problems.
The voltage of c of darlington maybe too high and it can't pull the base of T3 down to ground, it means that the T3 can't turn off, so the photo transistor won't affect anything.

There are two ways to fix the problems.
1. R2 change to 10K, in series with a 2.2K resistor between the base of T3 and c of darlington.
2. R2 change to 10K,, remove the c of T1 from c of T2, and c of T1 in series with a 10K resistor connecting to +5V.
try again.
 
Last edited:

Thread Starter

electro_2015

Joined Jan 1, 2015
10
There are two ways to fix the problems.
1. R2 change to 10K, in series with a 2.2K resistor between the base of T3 and c of darlington.
2. R2 change to 10K,, remove the c of T1 from c of T2, and c of T1 in series with a 10K resistor connecting to +5V.
try again.
I tried both solutions but none of them worked. The values on the LCD remain at 0 rpm when the IR beam is cut by the blades.
 

ErnieM

Joined Apr 24, 2011
8,377
First off do not be discouraged because you got your LCD display to display meaningful characters; if you search out this forum you will find hundreds and hundreds of posts of people struggling to do this very basic accomplishment.

I quite agree with bertus and Scott that the LED is damaged/dead. It's hard to check out an IR LED so just stick a new one in there, but first change R1 to something around 500 ohms so you don't blow out another.

Next, do you have a voltmeter? If you are serious about electronics you need one. Harbor Freight sells what is a decent digital voltmeter for $10, or $2 on sale. It even has a battery. EBay can be your friend here too.

With your voltmeter you cam make measurements around the circuit. The most important one is pin 2 of the Arduino: that should be very low (say less than 0.2V) and very high (again 4.8V or more) when the light is blocked or not blocked between the LED and the phototransistor.

I would not mess around with anything else in the circuit. R3 may be a little low but should work as is. If T1 is still on when in the dark add a 100K (or larger) resistor from base to emitter (if there is a base on that device).

fan_interrupt() may not seem to be called but is truly is called all the time, but the call is not done in software, it is done by the hardware every time pin 2 changes. That is what an interrupt is: a break in the normal flow of code to some other tasks; when that task is complete the normal flow of code resumes. Try Googling "interrupt service routine".
 

Thread Starter

electro_2015

Joined Jan 1, 2015
10
Hello,

What are the specs of the IR-led?
With 10 Ohms on 5 Volts , the current will be around 380 mA.

Bertus
The maximum allowable current of this IR LED is 150 mA according to RS.
Of course, I have changed that 10 ohms resistor to a much higher value so that the current is now less than 20mA

I regularly check that my IR LED is still OK by using my phone camera.
Till now it is still OK
 
Well, i designed a similar project detecting heart-beats using IR. Problem i faced was that the output-change in signal (input to controller) was very low (order of millis), so i used amplifiers to clean and amplify the change in the signal which work like a charm. Amplifier that i used was LM358 (rail-to-rail output) compatible with 5v logic.
 
Top