# IR Sensor only returning max values regardless of distance

**URL:** <https://forum.arduino.cc/t/ir-sensor-only-returning-max-values-regardless-of-distance/606750>\
**Category:** Sensors\
**Created:** [August 17, 2019, 9:52am UTC](https://forum.arduino.cc/t/ir-sensor-only-returning-max-values-regardless-of-distance/606750 "2019-08-17T09:52:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ConnorBarkley30](https://avatars.discourse-cdn.com/v4/letter/c/b19c9b/32.png) [@ConnorBarkley30](https://forum.arduino.cc/u/ConnorBarkley30)\
**Post date:** [August 17, 2019, 9:52am UTC](https://forum.arduino.cc/t/ir-sensor-only-returning-max-values-regardless-of-distance/606750/1 "2019-08-17T09:52:56Z")

</div>

Hi, I'm using a GP2Y0A02YK0F IR sensor and just trying to get a basic read from it. The values it returns are between ~950 to 1023 regardless of the distance. I've tried using other pins (changing code respectively) but I'm unsure of what the problem could be. I've got my code below. Cheers 🙂

```cpp
#define sensorIR A2
float sensorValue;

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

void loop(){
  sensorValue=analogRead(sensorIR);
  Serial.print("Sensor Value: ");
  Serial.println(sensorValue);
  delay(150);
}

```

---

<div class="post-metadata">

**Author:** ![arduarn](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/arduarn/32/239170_2.png) [@arduarn](https://forum.arduino.cc/u/arduarn)\
**Post date:** [August 17, 2019, 12:38pm UTC](https://forum.arduino.cc/t/ir-sensor-only-returning-max-values-regardless-of-distance/606750/2 "2019-08-17T12:38:31Z")

</div>

Welcome to the forum and well done for using code tags in your first post!

Are you using the bare sensor or a breakout board? If a breakout board, which one.  
How do you have your circuit wired? Post a photo and/or, if you are able, draw a circuit diagram on a page and post a picture of it.  
Did you add a power supply by-pass capacitor as recommended in the [GP2Y0A02YK0F datasheet](https://www.pololu.com/file/0J156/gp2y0a02yk_e.pdf) ([pololu.com](http://pololu.com))?

---

<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:26am UTC](https://forum.arduino.cc/t/ir-sensor-only-returning-max-values-regardless-of-distance/606750/3 "2021-05-06T10:26:41Z")

</div>

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


