IR based obstacle counter

I have this IR tx+rx module pair onboard with 3 pins corresponding +5v, Gnd and output. It triggers an output when the infrared light is reflected back from the TX to the RX diode. The output pin is fed to digital pin and I can read it from digitalRead(). This module is similar to the one shown on this: http://exploreembedded.com/wiki/images/thumb/6/6e/IR_Sensor.JPG/680px-IR_Sensor.JPG

I want to make use of this as an obstacle counter, but I'm stuck at the programming, as my program detects and obstacle, but then constantly increments the counter. I'm not adding my code here as I have tried various methods to increment counter and to print it's intermediate values, but I'm not having success.

I intend to count the number of rotations on a wheel which contains one metal strip as an obstacle per circumference of the wheel. But the my program keeps counting the obstacle when the wheel i stopped at the metal strip. (This strip is 2-3mm wide and I may alter it's dimensions to suit my project)

Can someone offer a code for this?

I want to make use of this as an obstacle counter, but I'm stuck at the programming, as my program detects and obstacle, but then constantly increments the counter.

You want to count when the switch value BECOMES pressed, not when the switch value IS pressed. The state change detection example shows how.

Can someone offer a code for this?

$100/hr; minimum 2 hours; 1/2 up front.

It sounds like you are trying to set-up a wheel encoder. PaulS is correct. The best method to achieve this is to use an interrupt and to increment a counter only on the rising edge. See this thread for sample code and some things to watch out for:

http://forum.arduino.cc/index.php?topic=131571.0