Creative Commons images are CC BY-NC-SA 3.0

13.95

added to your
shopping cart

quantity
In stock 296 in stock
13.95 1+ units
12.56 10+ units
11.16 100+ units

Description: 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.

Documents:

Comments 30 comments

  • 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

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

    • 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!!!

      • 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);
        }
        
      • 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.

          • 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.

  • 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

  • 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!

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

  • 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

  • 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.

  • 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/

  • 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?

  • 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 ???

  • how can i progrm this in ecapp(c language)

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

  • will any of these work with 3.3V ?

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

  • 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.

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

  • carful using these on real projects at work…there obsolete!

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


Related Products