Creative Commons images are CC BY 2.0

### \$ 13.95

shopping cart

 quantity Out of stock out of stock 13.95 1+ units 13.25 25+ units 12.56 100+ units

We do not currently have an estimate of when this product will be back in stock.

Need larger quantities?
Check out our Volume Sales program

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:

## Recommended Products

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

• 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() {
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

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.

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

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

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.

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

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

• er, 200 cm. Not enough coffee!

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

• They are now cross-listed in both categories.

• Should be fixed. Thanks for pointing that out

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

• Engineer04915:

carful using these on real projects at work…there obsolete!
Apparently so is the use of the proper “They’re”…

• As well as the use of the proper “careful”…

• 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 out of 5

Based on 1 ratings:

Currently viewing all customer reviews.

3 of 3 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.

In 2003, CU student Nate Seidle blew a power supply in his dorm room and, in lieu of a way to order easy replacements, decided to start his own company. Since then, SparkFun has been committed to sustainably helping our world achieve electronics literacy from our headquarters in Boulder, Colorado.

No matter your vision, SparkFun's products and resources are designed to make the world of electronics more accessible. In addition to over 2,000 open source components and widgets, SparkFun offers curriculum, training and online tutorials designed to help demystify the wonderful world of embedded electronics. We're here to help you start something.