# Sharp GP2Y0A710K0F IR sensor behaving strangely

**URL:** <https://forum.arduino.cc/t/sharp-gp2y0a710k0f-ir-sensor-behaving-strangely/394006>\
**Category:** Sensors\
**Created:** [June 25, 2016, 8:43pm UTC](https://forum.arduino.cc/t/sharp-gp2y0a710k0f-ir-sensor-behaving-strangely/394006 "2016-06-25T20:43:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![YaddyVirus](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/yaddyvirus/32/226673_2.png) [@YaddyVirus](https://forum.arduino.cc/u/YaddyVirus)\
**Post date:** [June 25, 2016, 8:43pm UTC](https://forum.arduino.cc/t/sharp-gp2y0a710k0f-ir-sensor-behaving-strangely/394006/1 "2016-06-25T20:43:44Z")

</div>

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

```cpp
    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.

Datasheet: [Microsoft OneDrive - Access files anywhere. Create docs with free Office Online.](https://1drv.ms/b/s!AnWPsNx8qqvugs0YNoXsvMuq2orDBQ)

---

<div class="post-metadata">

**Author:** ![Zahran\_Sajid](https://avatars.discourse-cdn.com/v4/letter/z/82dd89/32.png) [@Zahran\_Sajid](https://forum.arduino.cc/u/Zahran_Sajid)\
**Post date:** [June 26, 2016, 12:43pm UTC](https://forum.arduino.cc/t/sharp-gp2y0a710k0f-ir-sensor-behaving-strangely/394006/2 "2016-06-26T12:43:15Z")

</div>

// you should map the sensor from 0 t 1023 to 0 to 255  
//here's the code  
int sens = 0;  
int sensp = 0;  
void setup() {  
Serial.begin(9600);  
}  
void loop() {  
sens = analogRead(A0); //let the sensor be coonected there  
sensp = map(sens, 0,1023, 0,255);  
Serial.println(sensp);

---

<div class="post-metadata">

**Author:** ![knut\_ny](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/knut_ny/32/1013044_2.png) [@knut\_ny](https://forum.arduino.cc/u/knut_ny)\
**Post date:** [June 26, 2016, 12:45pm UTC](https://forum.arduino.cc/t/sharp-gp2y0a710k0f-ir-sensor-behaving-strangely/394006/3 "2016-06-26T12:45:46Z")

</div>

pin 1 and 5 =\> GND  
pin 2 and 3 =\> 5V  
pin 4 =\> analog input

* * *

Test ?  
Ground 1 and 5, power to pin 3  
Try reading the "uncertain" one.. 2 / 4

* * *

another look at the datasheet: pin 1 nearest edge

---

<div class="post-metadata">

**Author:** ![AkashCastelino](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@AkashCastelino](https://forum.arduino.cc/u/AkashCastelino)\
**Post date:** [January 17, 2018, 2:41am UTC](https://forum.arduino.cc/t/sharp-gp2y0a710k0f-ir-sensor-behaving-strangely/394006/4 "2018-01-17T02:41:34Z")

</div>

Hi,  
@Zahran_Sajid Can you please explain the reason why you are mapping 0 to 1023 to 0 to 255 ?  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 10:14am UTC](https://forum.arduino.cc/t/sharp-gp2y0a710k0f-ir-sensor-behaving-strangely/394006/5 "2021-05-06T10:14:01Z")

</div>

Closed on May 6, 2021, 10:14am UTC


