Measuring RPM with IR led and Photodioide.

I have been measuring the RPM of a few AC devices like (Juicers, Mixer\grinders etc) using an IR led attached to a coin cell(which is connected to the rotating arm of the appliance) and a photodiode connected to the arduino.

Although my RPM count is coming out to be pretty accurate, i have observed that the IR led and photodiode pair interacts for more time than I want. Which leads me to a suspicion that the calculated RPM may be more than the actual.

Please suggest how to use ir led + photodiode as a reliable sensor.

Following is my arduino code:

int SensePin = 04;

int RotationCount=0; 
// the setup function runs once when you press reset or power the board
void setup() {
  Serial.begin(9600);

  pinMode(SensePin, OUTPUT);

}


// the loop function runs over and over again forever
void loop() {
      int sensorValue; 
      digitalWrite(SensePin,HIGH);
      sensorValue = analogRead(A0);
      if (sensorValue < 1023)
      {
      RotationCount++;
      Serial.println(RotationCount);
      delay(3); // dirty fix to sense ir led+photdiode only once
      }
      
}

Hi,

You could try detecting the "edge" of the signal from the photodiode, rather than its current value. Make a global variable to record the value returned by analogRead() last time it was read. Then each time you take a new reading, compare (i.e. subtract) it to the last reading. If the value has changed by a significant amount, increment you count. What "significant" means, you will have to determine by experiment. You may still need the delay() to prevent double-counting, but you may be able to get away with a shorter delay, enabling you to measure higher speeds.

Paul