9 years, 5 months ago.

Using opto reflective sensor output as input to DigitalIn pin

I am attempting to use a opto reflective object sensor to detect a reflective strip and count up each time this happens. The problem is that as the sensor moves past the reflective tape, numerous counts are accumulated. I need to find a way to only count once each time the opto reflective object sensor passes over reflective tape. The sensor output is input as a mbed DigitalIn pin. How can I limit Digital in to only count once?

Thanks-

2 Answers

9 years, 5 months ago.

Try using: http://developer.mbed.org/users/AjK/code/DebounceIn/. That works for mechanical switches, but should also work for your issue. Although there are other options, in general you need to make sure that there is a delay between reads, so it will not notice multiple very fast transitions.

9 years, 5 months ago.

I would do this with InterruptIn method and set a rise/fall edge. I assume, that the output of the output from the sensor is somehow square. It's nonsense periodically polling the input.

RGDS