Two IR sensor counter

Hello,

I trying to have two sharp IR sensors track movement of a rod rotating at its center. I have attached a picture as a reference. The diagram is from a top-down view. Both IR sensors are pointing upwards. The rotating rod would pass above the IR sensors. I need each sensor to count every other pass of the rod, i.e., Having each sensor count only the odd pass numbers and ignore the even pass numbers. When the IR sensor is pointing to the ceiling, the arduino has a reading of around 10 or less units. When the rod passes over a sensor, the reading on the arduino is over 100. I tried to have the code count when the sensor reading is above 100 (again, doing this every other turn).
The problem is the IR sensor does many readings per second, per pass. This would make the arduino count several times for only a single pass of the rod. I was wondering if there was a way to tell the arduino that when it receives a reading of more than a hundred, no matter how many times, it will only count as one. It would wait untill it receives a small number (like 10) to continue the count once it receives a large number (like 100) again. This is all including the arduino ignoring every other turn.

I would greatly appreciate any help with this. Thanks.

2 IR sensors.jpg

Well, this is really just a software problem. Create variables like “CurrentReading” and one like “PreviousReading”. See the semi-pseudo code below.

int currentReading = 0;
int previousReading = 0;
int counter = 0;

void CheckingTheSensor()
{
   currentReading = readFromSensor();
   if ((currentReading>100) && (previousReading=<100))
         counter++;
   previousReading = currentReading;
}

Using IR sensors sounds a bit fishy. They are probably not fast enough on higher speeds. Consider using something which is more appropriate for the purpose, for example reed relays.

Also what is the point using two sensors? Based on your drawing one of them is redundant (except if one of them is safety backup sensor), because they will signal you at the same time.