samson241
Posts: 81
Joined: Fri Apr 05, 2013 7:07 am
Location: Western United States

IR distance sensor GP2Y0A21YK0F Voltage to range?

Thu Jun 20, 2013 10:07 pm

Does anyone know how to convert this? :( :( :( :( :( :( :(
http://www.adafruit.com/products/164
I realize this question must seem stupid and i apologize in advance.

User avatar
joan
Posts: 14936
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: IR distance sensor GP2Y0A21YK0F Voltage to range?

Fri Jun 21, 2013 8:31 am

You're out of luck I'm afraid. The Pi only has digital gpios. You need to read that from a device with at least some analogue gpios.

PiGraham
Posts: 3939
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: IR distance sensor GP2Y0A21YK0F Voltage to range?

Fri Jun 21, 2013 8:53 am

As Joan says, the Pi only has digital interfaces on board.

This sensor outputs 0.3V to 3V so you could use it as a fixed distance sensor that would change a digital input 0 - 1 at some distance 10cm - 80cm.

The alternatives is to use a ADC add on and read the analogue voltage. Perhaps something like this:
http://www.abelectronics.co.uk/products ... -converter

Here is a blog post on using the Sharp IR sensors with a Pi.
http://davstott.me.uk/index.php/2013/06 ... -infrared/

User avatar
joan
Posts: 14936
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: IR distance sensor GP2Y0A21YK0F Voltage to range?

Fri Jun 21, 2013 10:51 am

PiGraham wrote:...
This sensor outputs 0.3V to 3V so you could use it as a fixed distance sensor that would change a digital input 0 - 1 at some distance 10cm - 80cm.
...
I have a GP2D12 (I think it's the same device).

I hooked it up to the Pi (5V, GND, gpio4). It gives logic 1 at about 12 cms and closer.

samson241
Posts: 81
Joined: Fri Apr 05, 2013 7:07 am
Location: Western United States

Re: IR distance sensor GP2Y0A21YK0F Voltage to range?

Fri Jun 21, 2013 3:32 pm

joan wrote:
PiGraham wrote:...
This sensor outputs 0.3V to 3V so you could use it as a fixed distance sensor that would change a digital input 0 - 1 at some distance 10cm - 80cm.
...
I have a GP2D12 (I think it's the same device).

I hooked it up to the Pi (5V, GND, gpio4). It gives logic 1 at about 12 cms and closer.
Thanks for the help, but this is irrelevant. I have Arduino piping the analog number to pi through the piserial into python. Does anyone know the equation that will decode it from analog to range?
sorry... my fault for not including info...
I realize this question must seem stupid and i apologize in advance.

User avatar
joan
Posts: 14936
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: IR distance sensor GP2Y0A21YK0F Voltage to range?

Fri Jun 21, 2013 3:37 pm

PiGraham posted a blog link which gives that information.

samson241
Posts: 81
Joined: Fri Apr 05, 2013 7:07 am
Location: Western United States

Re: IR distance sensor GP2Y0A21YK0F Voltage to range?

Fri Jun 21, 2013 4:56 pm

joan wrote:PiGraham posted a blog link which gives that information.
oh thanks... missed that... right now I'm using the digital which works fine
I realize this question must seem stupid and i apologize in advance.

Return to “General programming discussion”