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.
For more project ideas about the IR Sensor? Check out the following blog posts::
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.
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
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.
Skill Level: Noob - You don't need to reference a datasheet, but you will need to know basic power requirements.
See all skill levels
Based on 3 ratings:
4 of 4 found this helpful:
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.
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.
Log in or register to post comments.
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/
Note that this project is now here: https://github.com/jeroendoggen/Arduino-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:
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.
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.
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!
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