Using a Sharp GP2Y0D810Z0F for sensing walls with Arduino Uno

Hello all, I hope that someone could help me with this. Here's a little run-down of my project plan;

I'm trying to create a robot that continues until it senses a wall about 5 to 10 millimeters away (in it's front sensor) and evaluates which way it can turn. I have no problem programming everything else, but I'm having a hard time getting started with this sensor that I purchased.

Here is the link to it: https://www.adafruit.com/products/1927

I would like to be able to have it simply read a 0 or a 1 depending on whether or not a wall was the mentioned distance in front of it, but I can't seem to get it to work. I have plugged it into A0, but I keep getting many values, not 0 or 1. If anyone would be able to simply provide this code to have it register a value of 1 or 0, that would be fantastic!

Thanks in advance! (let me know if you need any more info)

Hi, I haven’t used your sensor but I have experience with similar SHARP IR. Take a look at this library, you might be able to adapt it to your needs. http://playground.arduino.cc/Main/SharpIR

However, I believe it would be much easier to just create a condition based on the values that the sensor is returning. For instance, let’s say that when the sensor is returning 24 you are 5 cm distance, just use the 24 in a condition and check against it. All the values you see are the voltage level of the sensor. You can find some math to translate those into actual cm distance but it might be not worth doing this. (example here http://home.roboticlab.eu/en/examples/sensor/ir_distance)

Also keep in mind that the sensor values are usually not really stable (that’s why the library above is calculating a mean) and that below 2 cm (stated by the specs of your sensor) if might return weird values, then do not use them in your calculation. For instance, let’s say you want to detect 5 cm from the position of the sensor. You have to calculate 5+2 with the real distance, otherwise you’ll get only 3 cm. (it’s easier to do than to explain :D)

Bye

I have plugged it into A0, but I keep getting many values, not 0 or 1.

The Sharp GP2Y0D810Z0F is a digital device, not an analog device. You should be using digitalRead(), not analogRead().

Make sure you have connected it properly. Adafruit recommends

If you place a large capacitor (more than 10uF) between power and ground you should see an increase in performance.

smills1149: I'm trying to create a robot that continues until it senses a wall about 5 to 10 millimeters away (in it's front sensor) and evaluates which way it can turn.

Are you sure you mean millimeters? Very tight for turning.... impossible, I'd say. (Not to mention the fact that the inertia of your robot might take it into the wall even though you command it to stop.) You mean centimeters?