Newbie Help: Project with Sharp Distance sensor

Hi all,

I am a newbie to the Arduino world; have completed the tutorials on the website, but still feel lost in one of the project i am working on.

The idea of the project is to use Sharp Distance sensor (GP2Y0A21) as input. Output will be different range of sound. For example, at different distance, the program will play a different key or tones.

However, I have no idea whatsoever how to program or connect this thing.

Please help. Thank you.

Did you look at the data sheet for the sensor. It only has three wires. There is a +V line that requires 4.5 to 5.5 volts in. What do you know, the Arduino has a +5V pin. Put the red wire there.

There is a Gnd wire. Plug that into one of the Gnd pins.

The third wire is the output from the sensor. The output is analog, so plug it into one of the analog pins.

Then, write so code that declares the pin you selected to be an INPUT pin. In loop, call analogRead to see what the value of that pin is.

The value will be a number from 0 to 1023.

The data sheet says that the output voltage has a range of 1.9V typically, so you will probably see a smaller range of numbers (greater than 0 but less than 1023).

Experiment with the sensor, to see what range of values you actually get. Then, add some code to do something with the value.