0

I have just purchased a new Sharp GP2Y0A710K0F IR sensor online. As a sanity check, I wrote this simple code to check if the sensor is working correctly. The code is expected to print output voltage from the sensor, which is based on the distance

int sensorpin = A5;     
int val = 0;    

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

void loop()
{
val = analogRead(sensorpin);
Serial.println(val);   
delay(100); 
}

Now the output is quite strange. The output values start from zero and keep on increasing until they reach 1023, and then gradually decrease down to zero and this keeps on happening, even if something is kept in front of the sensor.

Is my sensor a faulty one? or is it supposed to give out similar outputs. If it has to, how do I convert these values to meter or centimeters.

The product description on the manufacturer's website said that it has a 3 pin interface, however it has a 5 pin one, the wires being Red, Black, Yellow, White, Green if seen from the left side. I guessed from the datasheet that Red and Black are for power and Yellow for signal output and hence I have connected only these 3 wires. The Green and White wires are unconnected. Also, pin numbers aren't marked.

  • The datasheet says there are 5 pins. 2 are Vcc and 2 are ground. – Majenko Jun 25 '16 at 20:45
  • How close is "in front of the sensor"? – Majenko Jun 25 '16 at 20:46
  • @Majenko , so I connected the Red and Black wires as Vcc and ground respectively. Used the yellow wire for output. – YaddyVirus Jun 25 '16 at 20:46
  • @Majenko roughly 40-50 cm away, it is supposed to be atleast 100 cm away right? – YaddyVirus Jun 25 '16 at 20:47
  • Well, that's probably why then. Does the graph on page 5 of the datasheet look like what you are describing? Also, did you note the description? Distance Measuring Sensor Unit Measuring distance: 100 to 550 cm Analog output type – Majenko Jun 25 '16 at 20:49
1

I suspect you have it wired wrongly.

You need to consult the outline diagram in the datasheet and work out which colour wire is which function. It's this bit:

enter image description here

By your wiring description it sounds like you may be powering it through Vo and reading the result through VCC, which won't work - and at worst may damage it.

  • Did the experiment, connected pin 3 to 5v on Arduino, 5 to GND on Arduino and 4 to A5. This time the readings start off with 927 and go to 1023 and then come back to 927 and the process repeats. – YaddyVirus Jun 25 '16 at 21:15
  • I think I have got it working. Connected both the postives to 5v and both the ground to 5v, I then get the voltage readings ranging between 355-388. If that's 3.5 to 3.8v, its horribly wrong as then according to the graph,it should be roughly 2v as the object is 1.5 m away from the sensor – YaddyVirus Jun 25 '16 at 21:30
  • 1
    Those are raw ADC values. You have to convert them to voltage. – Majenko Jun 25 '16 at 21:31
  • But anyways, since I've got the sensor working, how to read its values is another question. Thanks – YaddyVirus Jun 25 '16 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.