Range problems w/ Sharp IR Distance Sensor

Hello everyone,

I've been struggling to properly measure distances with a Sharp IR Distance Sensor (Model gp2y0a21 - datasheet is here).

Despite the sensor being rated for distances of 10-80 cm, I've found that after about 30-33cm, the sensor seems to no longer pick up the object it's measuring and reverts back to its output of 20cm (which it usually displays if there's no nearby object it's measuring).

I've tried many things - I bought another of the same sensor, used the sensor on different objects, and tried different code - but this issue keeps occurring.

Why could the sensor be behaving in this way? as anyone else had this problem before?
And, what can I do to fix it?

By the way, I've seen people say that it's a good idea to use a capacitor with this sensor to get rid of voltage spikes. I haven't tried that because I think that's a different problem than what I'm facing right now.

The two different codes I've been using to turn the voltage output into distance is from these two videos:

  1. https://youtu.be/JFTJ2SS4xyA
  2. https://youtu.be/GL8dkw1NbMc

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.