Infrared Proximity Sensor - Sharp GP2Y0A21YK

Infrared proximity sensor made by Sharp. Part # GP2Y0A21YK has an analog output that varies from 3.1V at 10cm to 0.4V at 80cm. The sensor has a Japanese Solderless Terminal (JST) Connector. We recommend purchasing the related pigtail below or soldering wires directly to the back of the module.

Infrared Proximity Sensor - Sharp GP2Y0A21YK Product Help and Resources

Resources & Going Further

For more project ideas about the IR Sensor? Check out the following blog posts::


Core Skill: Programming

If a board needs code or communicates somehow, you're going to need to know how to program or interface with it. The programming skill is all about communication and code.

2 Programming

Skill Level: Rookie - You will need a better fundamental understand of what code is, and how it works. You will be using beginner-level software and development tools like Arduino. You will be dealing directly with code, but numerous examples and libraries are available. Sensors or shields will communicate with serial or TTL.
See all skill levels


Core Skill: Electrical Prototyping

If it requires power, you need to know how much, what all the pins do, and how to hook it up. You may need to reference datasheets, schematics, and know the ins and outs of electronics.

1 Electrical Prototyping

Skill Level: Noob - You don't need to reference a datasheet, but you will need to know basic power requirements.
See all skill levels


Comments

Looking for answers to technical questions?

We welcome your comments and suggestions below. However, if you are looking for solutions to technical questions please see our Technical Assistance page.

  • lesto / about 9 years ago / 1

    hi, someone can tell me how much dies this module weight?

  • Member #320271 / about 12 years ago / 6

    Distance on graph is definitely in Centimeters. I just did some testing for a class project and this equation fits the data pretty spot on:

    distance (cm) = 41.543 * (Voltage + 0.30221) ^ -1.5281 (matlab EzyFit tool)

    This is valid for ~0.5 - 3V

    Hope this helps

  • doggenj / about 13 years ago / 3

    Arduino library for the Sharp GP2Y0A21YK IR Distance sensor: http://code.google.com/p/gp2y0a21yk-library/

    • ThomasW / about 10 years ago / 1
    • FOR ALL THAT USE THESE SENSORS::::: In the library, it says it's in cenimeters but really it's in inches---I noticed this when attempting to use this on my robot I'm building and realized the data was coming nowhere close to the 80 cm the product page said it would---checked it with a tape measure and realized it was measured in inches rather than centimeters!!!! SAVE YOURSELF THE HASSLE!!! remember this fact!!!

      • oscarvs / about 12 years ago / 2

        To get centimeters:

        int i;
        int val;
        int redpin=0;
        void setup() {
            pinMode(redpin,OUTPUT);
            Serial.begin(9600);
        }
        void loop() {
            i=analogRead(redpin);
            val=(6762/(i-9))-4;
            Serial.println(val);
        }
        

      • doggenj / about 12 years ago / 1

        Could you please clarify why you state that my library gives the values in inch instead of centimeters.

        I just checked my code, but everything seems to be ok.

        If you look at the output voltage graph here: http://www.acroname.com/robotics/info/articles/sharp/sharp.html

        and my calculations: http://code.google.com/p/gp2y0a21yk-library/source/browse/#hg%2FCalculations

        they show similar values.

        I live in Belgium and use the metric system, so it would be very strange for me to make this mistake.

        • Maybe there's a change in the library---I'm not sure but when I check the measurements using the "centimeters" library, the serial reading shows it in inches!! I originally checked with a metric ruler and I thought the readings were all wrong. But then I checked with an inches ruler and the measurements were accurate (but in inches, not centimeters). And I don't have a dysfunctional sensor---I have 5 of them that I use and they all show the same thing. Maybe it's something that changes in United States' Arduino software, but the readings (for me at least) are 100% in inches, not centimeters.

          • Ogre / about 10 years ago / 1

            I found the same thing. Was frustrating the frick out of me when the reading was maxing out around 28-29 and I was expect it to be more around 75-80. I put inch measurements in my code and it started acting properly. Just be aware!

          • doggenj / about 12 years ago * / 1

            Maybe you made a mistake when configuring the sensor? The correct analog ADC reference value needs to be set in hardware and in software.

            The source file, linked below, contains two look-up-tables, one for 5V reference and one for 3.3V reference.

            http://code.google.com/p/gp2y0a21yk-library/source/browse/DistanceGP2Y0A21YK/DistanceGP2Y0A21YK_LUTs.h

            Using a value from the wrong table results in an wrong measurement. The measured value is approx. thee times too big around the middle of the sensor range. Maybe this lead you to the conclusion that the measurement were expressed in inches?

            • There is no mistake in the sensor, or while I was setting anything up. It perfectly matches inches on a ruler so I don't think that it was a misreading or something. For the fact that the math shows centimeters and it outputs inches surprises me greatly.

  • pjwerneck / about 15 years ago / 3

    These sensor are great, however, if you want precision I recommend getting one with at least 1.5x the max range you expect. The output isn't linear and if you check the curve on the graph you'll see how the resolution gets lower with distance.

  • If I were to put a capacitor near this, which on should I use? I've never used capacitors before and it seems capacitors are necessary for the large pulses of electricity it draws

  • Alvarete / about 12 years ago / 2

    Hello, I would to ask one question about this sensor. When I connect it to 5V of Vcc, the light emitter works without problems, but the light detector doesn't receive any voltage ( V0 = 0 ). I don´t know if my sensor is damaged due to a surge voltage. ¿How I can solve it?. Thanked I expect an answer. Greetings!

  • Alchitry / about 17 years ago / 2

    Great little sensor. It does take large pulses of power so make sure you have a capacitor near it.
    Justin
    http://coilgunpower.com

  • Member #541176 / about 11 years ago / 1

    hey everyone, hope anybody can help me with this one: for my project i use 2 sharp sensors, (ranges 100-550 and 20-150) building kind of guiding device/obstacle detector for blind. unfortunately both sensors have the same 'problem' i can't fix. as you can see from the datasheet, the output as a function of distance is parabola - therefore every output voltage may have 2 options for distance. despite the fact i want to use only the range 100-550 (for ex.), the sensor does also react to 0-100 giving different outputs which may be interpreted as other distances leading my blindman to hit the wall or something.. . i'm using the sensors with Arduino, and can't find a way to handle this double values problem.

    will be very very grateful for solutions or ideas Gary

  • Member #418727 / about 11 years ago / 1

    Could this work to determine the depth of water in a fish tank? Will it reflect reliably off the surface of the water? I'm thinking that even if it does, if the water is rippling a lot it might give a lot of unreliable data.

    • ronaldlees / about 10 years ago / 1

      Exactly what was on my mind! Thinking about using the device to make a very inexpensive digital rain gauge!!!

      What is the potential precision over say, a 20 cm range? Of course, one could make a water amplifier (large plate to collect water at 10x area) - and spread it out to 120 cm or something like that, which would refine the device quite a lot. Seems like a project!

      • ronaldlees / about 10 years ago / 1

        Wouldn't need to reflect from water, could put a buoy (float) in the column. Or, I imagine one could implement a lightweight shaft from the float to a (larger) target plate on top of the column.

      • ronaldlees / about 10 years ago / 1

        er, 200 cm. Not enough coffee!

  • Ezu / about 12 years ago / 1

    This is one of the best infrared sensor. simple and with a friendly interface the sharp sensor has high accuracy for its price. many more infrared sensors could be found here http://www.intorobotics.com/infrared-sensors-list-for-simple-to-advanced-applications/

  • Member #309525 / about 12 years ago * / 1

    I know it has been asked before but I just want to ask again. Will this work at Vcc=3.3 V? The datasheet says that it is within the acceptable input voltage range. If not, any ideas on how I can interface this with a 3.3 V microcontroller? According to the graph, the output never exceeds 3.3V so I should technically be safe when I supply a 5 V Vcc to the sensor? What do you think?

  • Member #430076 / about 12 years ago / 1

    Hello,,, could anyone guide me with my project?? I would like to know how to get this sensor to trigger different video clips projected onto a wall at specific distances ???

  • Member #378998 / about 12 years ago / 1

    how can i progrm this in ecapp(c language)

  • Adam Davis / about 14 years ago / 1

    Please consider adding these proximity sensors (there are three in your catalog) to the proximity sensor category.

  • oz-solutions / about 14 years ago / 1

    will any of these work with 3.3V ?

    • Eggman / about 14 years ago / 1

      Sadly, they don't. At 3.3V you can get some wild voltage swings even when the distance to target is fixed.

  • Dloranger / about 14 years ago / 1

    I bought one of these modules to add vision to a robot I am working on and the output can't drive the ADC (ATMEGA uC) input. When I measure with a DMM (10MOhm) output is as expected, but trying multiple ADC inputs, the reading is about 60% and won't move.
    Good sensor, but recommend adding an analog buffer in series with the output just in case.

    • TomBot / about 14 years ago / 1

      Make sure you don't have the internal pullups (~40k) enabled. (digitalWrite() the pin to 0 to disable)

  • Engineer04915 / about 14 years ago / 1

    carful using these on real projects at work...there obsolete!

  • Landon / about 16 years ago / 1

    These a great little devices. I have used them extensively in a speed climbing timing system I'm building: http://twurl.nl/1gpjdj

Customer Reviews

4.7 out of 5

Based on 3 ratings:

Currently viewing all customer reviews.

4 of 5 found this helpful:

Good sensor

This sensor gives readings that can be converted in distances very easily. My only concern is that is a little noisy and the measurements are not completely stable, they vary within a 2-3 cm range of the real measurement but is normal considering the low cost of the device. The sensor is good for applications that do not require high precision.