Pages

17 March, 2012

Arduino - IR Proximity Sharp GP2Y0A02YK0F


Today I received one of two packages from Sparkfun I have been waiting for. As I opened the box, I found an IR Proximity Sharp GP2Y0A02YK0F sensor. It was a bit smaller than expected, but then again all products I have ever received from Sparkfun are smaller than I first thought. In the box I also found a jumper wire with a 3 pin JST connector. I ordered this to make it easier to connect the sensor to my Arduino Uno. Lets see how it works...

Specifications
Range: 15 - 150 cm (2.8V - 0.4V)
Price: ~$14.95
Supply voltage: 4.5V - 5.5V DC

Connecting to an Arduino
The red wire, is connected to the supply voltage, which in out case is 5V. The black wire goes to ground (GND), and finaly the yellow, our signal, goes to one of the analog inputs.
Code
#define sensorPin 0

int input = 0;
int distance = 0;

void setup() 
{ 
  Serial.begin(9600);
} 

void loop() 
{
  input = analogRead(sensorPin);
  distance = map(input,512,0,15,150);
  Serial.println(distance);
  delay(200);
}

4 comments:

  1. how the sorcode if using sharp 2Y0A710 for range 100-550 cm???
    thanks

    ReplyDelete
  2. Hi, I coded and connected exactly. However I am still getting non-readable characters. Help is appreciated

    ReplyDelete
    Replies
    1. Have you checked that the baud rate of your terminal is the same as the one in the code?
      It is the number in the bottom right corner of this window:
      http://1.bp.blogspot.com/-oyVdPZ16gS0/T2PZ4N_orMI/AAAAAAAABSE/0PLhjLp2RLI/s1600/SerialPort.png

      I have used a baud rate of 9600 in the guide (you can see the line "Serial.begin(9600);"), but it should work with any baud rate as long as it is the same in the terminal and the code.

      Delete