Simple IR Distance Sensor Code

Hey guys,

For a design project I will have a plate being pushed toward another fixed plate with a spring in between the two (using a motor), once the plate separation reaches a certain distance the motor will stop, releasing the plate and launching a ball sitting on the other side of the plate into the air.

So, I need a sensor to sense the plate separation distance with fairly good accuracy and reliability.

The sensor will be mounted in a noise free environment and only moving close to one another one-dimensionally, so i was thinking just have an IR emitter on one plate, and a IR detector on the other plate because this would be the cheapest and easiest solution (provided the code isn't too crazy).

Would it be possible to detect distance by the amount of time it takes the signal to reach the IR detector from the emitter? how accurate would it be? and is there any code for this available?

Thank you very much for your help,
Sean

Stratos:
Hey guys,

For a design project I will have a plate being pushed toward another fixed plate with a spring in between the two (using a motor), once the plate separation reaches a certain distance the motor will stop, releasing the plate and launching a ball sitting on the other side of the plate into the air.

So, I need a sensor to sense the plate separation distance with fairly good accuracy and reliability.

The sensor will be mounted in a noise free environment and only moving close to one another one-dimensionally, so i was thinking just have an IR emitter on one plate, and a IR detector on the other plate because this would be the cheapest and easiest solution (provided the code isn't too crazy).

Would it be possible to detect distance by the amount of time it takes the signal to reach the IR detector from the emitter? how accurate would it be? and is there any code for this available?

Thank you very much for your help,
Sean

It's not practical to use time-of-flight LIDAR for short distances unless you can measure arrival times in picoseconds. The Arduino isn't very good for that.

If your release distance is fixed you would typically use a mechanical limit switch If you want a variable distance there are ways of detecting motor revolutions so you can measure how far the plate has been pushed. If you really need a non-contact sensor, Sharp makes an IR distance sensor. It uses triangulation to determine distance. Another choice would be an ultrasonic distance sensor.

Awesome! Do you think the Sharp GP2Y0A21YK - Infrared Proximity Sensor would be steady/accurate enough? We have to launch a ping pong ball to hit a target at a precise distance, so we will need to consistently have the distance between the plates be brought to the same value.

Does the distance change? if not you would probably be better served with a mechanical switch. They tend to be more repeatable than a non-contact sensor.

Yeah I think i'll just go with the mechanical switch. Thank you!