Sharp IR Sensor testing…

Been testing a Sharp 10cm distance IR sensor, with some surprising results!…

The Sharp IR distance sensor GP2Y0A21YK is an infra-red distance sensor calibrated for 10cm distance sensing. It’s available for around $14 / £12 and so isn’t a bad price range for hobbyists.

I’ve found some interesting results in my testing.

Using a Arduino Pro Mini’s analog port, and powering the sensor using my Arduino’s VCC of 3.3V, I find the maximum reading is indeed at 10cm distance. there’s an interesting tail off either side of this though:-

Approx Distance Reading
Infinite (1.5m ceiling) 376
50cm 258
10cm 740
0cm 446

The points above are the extremes and the maxima/minima. As you see I can conclude:-

  • From 0cm to 10cm, reading increases with distance
  • After 10cm reading decreases until 50cm (reading of 258)
  • After 50cm reading starts increasing again until the maximum reading (i.e. my desk to ceiling)

The way I’m sensing is to take 200 readings and averaging out the value using floating point arithmetic. This seems pretty accurate, with the reading fluctuating up to 6 at infinite range, and by around 1-2 at 10cm.

A little hard to use just on it’s own though – is the obstacle at 30cm or 2cm? Kinda hard to tell. Combined with a sensor with, say, a 30cm range you can probably figure it out though.

Sample source code for the above can be found here:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.