IR sensor need debounce or not

I'm looking to move a stepper along few obstacles. I'm using an IR sensor installed on the stepper looking to detect each obstacle then to record their position. The size of each obstacle is cca 5mm.

Since I'm getting random results (0 or 1) from the IR sensors I'm asking if I need to debounce these IR sensors, maybe with Bounce2, or it's not the way to go? Some IR debouncer code example will be very helpfull also.

Tomaxix:
I'm looking to move a stepper along few obstacles. I'm using an IR sensor installed on the stepper looking to detect each obstacle then to record their position. The size of each obstacle is cca 5mm.

Since I'm getting random results (0 or 1) from the IR sensors I'm asking if I need to debounce these IR sensors, maybe with Bounce2, or it's not the way to go? Some IR debouncer code example will be very helpfull also.

Debounce is sometimes necessary for MECHANICAL devices like switches. I don't think IR sensors use mechanical switches.

I guess more research may be necessary.

Paul

I'm aware about using debounce in the case of mechanical switches indeed.
Since I'm getting repetitive or random signals from my IR sensor, I'm looking for a solution.

I would need, maybe, after I've registered first LOW signal from the sensor... to find a way to suspend any new signal reception for a small period of time (1-3 seconds // this is the time it takes for the stepper to arrive to the next obstacle).

For example: digitalWrite(IRsensor, HIGH)... but how to delay this command for few secons without delaying the loop entirely? Something with millis()... but I don't know what to find exactly to better learn and understand.

If I had your problem, I would begin to test and document the use of your device and the IR responses you find. What do you get with NO obstacles? Only one obstacle. Can you force a "false" response?

Do you have obstacles that reflect IR light? What is the geometry of your obstacles? Round, Flat, angular?

Paul

I get nothing with not obstacles.
With only one obstacle I get repetitive signals (LOW, LOW, HIGH, LOW...).
The obstacles are round metal so reflect IR.

If I cand shut down / ignore the signal for 2-3 seconds immediate after the first LOW , I'll have time to take out the stepper from that area and move on the the next obstacle.