Creative Commons images are CC BY-NC-SA 3.0

14.95

added to your
shopping cart

quantity
23 available 23 in stock
14.95 1+ units
13.46 10+ units
11.96 100+ units

Description: Infrared proximity sensor made by Sharp. Part # GP2Y0A02YK0F has an analog output that varies from 2.8V at 15cm to 0.4V at 150cm with a supply voltage between 4.5 and 5.5VDC. 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.

This sensor is great for sensing objects up to 5 feet away!

Documents:

Comments 71 comments

  • Using this sensor, an Arduino Uno and Python 2.5 for data processing I made a single pixel camera. The sensor is attached to a servo rig allowing incremental rotation along X and Y axis. Python then takes the distance values and servo rotation coordinates, converts them to luminance and constructs an image pixel by pixel:
    Here’s a test scan:
    http://img413.imageshack.us/img413/2867/pointscan.jpg
    Image on the left is taken with a web camera and the image on the right is scanned with this Sharp Sensor (over the course of about 5 minutes). Used a single 0.1uF capacitor for signal filtering.
    The noise in the image comes primarily from the mechanical wobble of the rig (i.e. cheap Futaba servos).

    • By the way, this is what the rig looks like (pardon the webcam image quality).

      http://img443.imageshack.us/img443/4656/scannerx.jpg

      In the foreground - a servo mount with the sharp sensor. In the background - a battery pack (4xAA) with Arduino Uno and a ProtoShield on top.

      Python 2.5 processed the data using PySerial module for serial communication and PIL (Python Image Library) for image reconstruction.

    • That’s pretty cool.

  • Using the datasheet, we did a fourth degree approximation to get a close fitting formula to find the distance in cm from the voltage. Here is the formula we used:

    Distance = 16.2537 * x4 - 129.893 * x3 + 382.268 * x2 - 512.611 * x + 306.439 *Where x=Voltage read on ADC and Distance is in cm.

    • Do you have perhaps a second degree approximation for the inverse of the output?

      My Arduino can’t handle 4th degree equations at 50Hz… :(

      • 11 months later, but a common thing to do in this case is to use a lookup table, you can even initialized such lookup tables on boot, but for this particular application, its probably easier to just code it in.

      • First, for high order polynomials you should factor them like so: d = 306.439 + x * ( -512.611 + x * ( 382.268 + x * (-129.893 + x * 16.2537) ) ) The original equation had (ax4 = axxx*x) 4+3+2+1 = 10 multiplications and 4 additions/subtractions. Factored equation has 4 multiplications and 4 additions/subtractions.

        Second, I don’t know how you’re planning on running this at 50 Hz since the expected response time, based on the datasheet, is 38.3 ms (or ~26 Hz update frequency).

      • I don’t, but I’ve used the second plot from the data sheet (output voltage vs inverse of distance), called it a straight line from 30cm to 150cm, and a different straight line from 20cm to 30cm. Then it is easy enough to come up with two equations calculating distance from voltage.

  • Ah, just wanted to mention this since I didn’t see it here. For those looking for a quick and relatively simple way to estimate the relationship between voltage output and distance. Take the readings on the graph from the datasheet or get them from your sensor (multiply the raw output readings by 5volts and divide by 1024 to get the result in volts. slightly longer but more likely to fit your sensor).

    I then graphed those readings in Excel and and found the line of best fit that most accurately followed the curve between the stated operating distances of 20cm to 150cm. Excel popped out the equation. See here: http://tinypic.com/r/2lddtvc/6

    • Thank you - this worked out very well for me!

      Just to provide a summary in case that the picture gets unavailable (all credz goes to the kind sir/madam above):

      x = [value read from sensor]
      y = x * [your Arduino boards Vcc (5 or 3.3V)] / 1024
      distance = 61.681 * y ^ -1.133
      distance <-- in centimeters
      
  • lmao! “This is a really hard to find item! Limit 4 pieces per customer.” vs. $13.45 10-99 (10% off), $11.96 100+ (20% off) i think there is a problem here as an individual may want to purchase more than 10 perhaps

    • its just the Sparkfun standard. Every single item on site has these cheaper priced listed under it. And the change all that for just three items..? (I am referring to the other two sharp IR sensors that Sparkfun sells)

  • if your using the 3 wire connector then you need to wire the yellow to the analog in, the red to the 5V, and the black to GRD
    hope this helps

  • Here is my calibration for the sensor in inches.

    /*
    Calibration of Infrared Proximity Sensor Long Range - Sharp GP2Y0A02YK0F
    SparkFun Part#: SEN-08958 https://www.sparkfun.com/products/8958
    
    By Robert Hazlehurst, Castle View High School robert.hazlehurst@dcsdk12.org
    
    for use on RedBot Robot SparkFun Part#: ROB-12032 https://www.sparkfun.com/products/12032
    with RN42-XV Bluetooth Module - PCB Antenna installed in the Xbee port SparkFun Part#: WRL-11601 https://www.sparkfun.com/products/11601
    
    Equation:
    Distance (in inches) = 6202.3*SensorReading^-1.056 fit with an R² = 0.9914
    
    Raw Data: 
    Sensor          Distance (In)
    502         8
    434         10
    379         12
    329         14
    283         16
    257         18
    229         20
    213         22
    199         24
    139         36
    91          48
    
    */
    
    
    #include <RedBot.h>
    
    RedBotSoftwareSerial bluetooth;
    
    float sensor;
    double distance;
    
    void setup() 
    {
      Serial.begin(9600);  // Begin the serial monitor at 9600bps
      bluetooth.begin(115200);  // The Bluetooth Mate defaults to 115200bps
      bluetooth.print("$");  // Print three times individually
      bluetooth.print("$");
      bluetooth.print("$");  // Enter command mode
      delay(100);  // Short delay, wait for the Mate to send back CMD
      bluetooth.println("U,9600,N");  // Temporarily Change the baudrate to 9600, no parity
      // 115200 can be too fast at times for NewSoftSerial to relay the data reliably
      bluetooth.begin(9600);  // Start bluetooth serial at 9600
    }
    
    void loop() 
    {
      sensor = analogRead(A3); //read the sensor
      distance = 6202.3*pow(sensor,-1.056); //apply cal curve to convert to inches
      bluetooth.print("distance = "); //print distance to cell phone screen
      bluetooth.println(distance);
    }
    
  • is there a detection angle for these sensors? ie. does one have to be directly in front… or will it pickup +/- 30 degrees, etc…

    Thanks!

  • Hello Everyone, I am new to this sensor. I am aware of how distance is measured.

    Can someone tell me how I can determine the angle of incidence ?

    thanks

  • Great rangefinder with a solid 5-foot range. Range values may vary for different colored surfaces, making it difficult to tell the difference between a close-up IR-absorbing object or a far-away IR-reflecting object. In our experience, this difference was only a few inches. I would recommend making an Excel (or equivalent) spreadsheet of experimental ADC values vs distances and using the software to create a trend line with a corresponding equation for your software to use to estimate ranges. Runs well on a regulated 5V supply with a good-sized capacitor to counteract the ripple it will cause when it pulls current.

  • Hi I have one question i want to do this with ultrasonic sensor. The range of detection objects is 35-200cm, how to make from distance to picture. Did you make some scale for an example 35cm it will be white and 200cm will be black? If you have some advices pls write me i am new with this and i want to learn. Thank you in advance!

  • Can this sensor pass through transparent or translucent material? If no, is there any alternate distance sensor that can be used with Arduino? Thanks!

  • Can you PLEASE sell MORE kinds of these (especially the LONGER range ones)?

    Longer range ones (100 to 550cm) like this one: GP2Y0A710K0F

    http://www.sharpsma.com/webfm_send/1490

  • anyone know when these will be back in stock??

  • Can anyone hazard a guess as to this thing’s beam width and pattern? I’m looking to augment an ultrasonic rangefinder (EZ-1) for closer ranges (like 75cm - 150cm); i’m hoping this things beam is narrower than the EZ-1, or i can get away with constraining it with a black tube.

    • Infrared tends to be pretty narrow because any wide angles would cause bad data. However, it all depends on the application. Reading the datasheet suggests that you need to protect the sensor when in certain types of lighting scenarios (outside in sunlight is an example they give).

      In regards to using a tube around it… It all depends on the tube. How is the tube mounted, how long is it, how big is the diameter of the tube, etc.

      I have used predecessors of this sensor before, and they do pretty well, however not every sensor meets the curve outlined in the datasheet. So it is best to do calibration tests on all infrared sensors to map out the range and sensitivity.

      • the datasheet says nothing about beam width, but yeah, i will experiment, it’s easy enough. IR LEDs vary in beam width, a lot, generally speaking. i posted cuz i was wondering if anyone else had done these sorts of experiments. no problemo here. thanks.

        • I’ve done a couple of simple tests with a 4mm square balsa wood stick at ~30cm from the sensor. I shall refer to the data sheet for orientation description - so that the emitter is to the left or right of the detector (as opposed to above or below). When the stick was oriented vertically, and passed from one side to the other, it seemed to have a 2.5 degree detection beam. When the stick was also oriented horizontally, and passed from below to above (or vice-versa), it appeared to have a 3.0 degree detection beam. I hope this helps.

          • ‘hope this helps’? lol hell yes! thanks a ton, man/ma’m! that’s exactly what i needed. very, very helpful.

  • Hey Everyone, I am new to this type of sensor, I am using a 10kohm resistor between the pin back to my MIDItron. Does anyone know if I should connect the sensor without the 10kohm resistor? Also if anyone has any tips or hints on the codes using Max6/jitt I would greatly appreciate it. Thanks!

  • I am experiencing erratic behavior with my sensor ? Also it seems to be heating up alot when it is running is that normal? basically I a not getting the results I want from this page ? http://arduinomega.blogspot.com/2011/05/infrared-long-range-sensor-gift-of.html Does it may a difference that I am using arduino uno instead I would really like to get this working ? I can provide pics and wiring to help ?

    thanks !!

    • are you using capacitors to help to balance the electronic noise? These should work fine with all arduino boards

  • Does anyone know if the infrared proximity sensors can detect distance from behind glass?

    • I did some tinkering with this, and from what I figured it would only work behind glass, if its pressed right against it, leaving no gap between the sensor and the glass.

  • The datasheet is clear it’s not 15cm it’s 20cm.

  • can I use this one to determine a waterlevel?
    so fixing it in my watertank with its beam downwards.
    or does water not reflex enough to give a distance??

    • it works on water as well but just to be sure i’m using a pingpong ball in a tube to determine the waterlevel (see also: http://howmuchsnow.com/waterlevel/)

  • how to installl this on the arducopter?

  • Surprised at how little information this data sheet has. Even plain old LED spreadsheets usually have a Radiation pattern.

  • !ATTENTION!
    This sensor’s case has relatively low resistance (150 Ohms), be careful when mounting on other conductors.

  • hi guys
    what is the angle range of this sensor?
    thanks
    regards

  • very nice sensor. much easier to use than a ping sensor but does not have as much range. It is perfect though for my application.

  • I did line fitting based on datasheet
    For 10bit ADC such as Arduino (0-5V => 0-1023),R square = 0.9902
    distance = 30431 * pow (sensorValue,-1.169)

  • Can someone help me with the equation to convert the reading into actual distance i.e. 975 x 1.318359375 = 1285.4mm 975 = 128.5cm
    Is my thinking incorrect? or my math?
    2.8V @ 15cm
    0.4V @ 150cm
    2.4/1024 = 0.00234375V
    1500mm/1024 = 1.318359375mm

    • This link should help:
      http://www.acroname.com/robotics/info/articles/irlinear/irlinear.html

  • Does anyone know how these react to different color? Say I have a white board at 2 ft and take a reading (discard first, average 4), then switch to a red, green or blue board at the same distance and take another reading the same way. Will I get the same reading both/all times or even something close?

  • I was wondering if anyone can help me with my problem.
    I bought this sensor hoping for it to track the distance my hand is away from it, which it does. However, the numbers corresponding to the distance fluctuate very quickly despite how I hold my hand still. Is this normal?
    I plan to use these numbers as a way to control which sounds I play. However, if the numbers fluctuate so much it won’t work.
    I’m using an Arduino Uno and Max MSP for my project.
    I apologize if this isn’t the place to ask this question but hopefully someone here can help me. Thanks.
    Other than that the sensor is plug and play =)

    • Make sure your power supply is clean and filter it with capacitors if necessary.
      Putting a 0.1 uF ceramic capacitor on the IR sensor output may also smooth out some of the signal.
      You can also smooth out the signal by averaging a set of readings in your Arduino code. Something along the lines of:
      void loop()
      {
      sensorInput = (analogRead(sensorPin));
      bufferA = bufferB;
      bufferB = bufferC;
      bufferC = sensorInput;
      average = (bufferA + bufferB + bufferC) / 3;
      delay(x);
      }
      That example takes a sensor reading and puts it in bufferC the first time. Second time the loop runs, that value passes to bufferB and third time to bufferA. Essentially, you get to keep the last 3 readings that you can then average to get a smooth output. By increasing the number of samples or the delay you can increase smoothing at the expense of latency.

  • Can we use glass case to protect this sensor from weather? Would it be ideal for car backup monitor? the ultrasonic ones arent weather proof and putting a glass case will void the range finding.

    • Glass case can be used for protection, provided it is flat and clear, not refracting or scattering light. Don’t use plexiglass as it reduces or completely blocks the infrared light.
      Regarding the main question, this would be a very bad choice for car backup monitor as it performs poorly in sunlight or under any light containing infrared spectrum. It’s best suited for indoor use. Most car sensors are ultrasonic. I use this one for outdoors which has some weatherproofing http://www.sparkfun.com/products/9496. It is pricey and if you do get dirt into it, it’ll be absolutely impossible to clean.
      In your case I’d go with a cheap Maxsonar EZ series sensor, putting a PVC pipe extender onto it for weatherproofing. The longer the barrel, the less chances of something getting into it.
      Another issue with IR sensors is that they project a dot and are only able to detect what’s directly in front of them based on how well the dot is reflected. If the object is black, shiny or textured you may get a bad reading. A sonic sensor is a lot harder to fool. In addition it emits a cone-shaped sound wave, so the detection radius is much wider.

  • Will IR remote controller interfere with it?

    • Short answer - yes. Depth perception will get affected by a small amount in presence of a foreign IR light source, but the remote is very unlikely to cause a major misreading unless you shine it right into the sensor or have it against the obstacle that it’s scanning.
      This device projects an infrared dot and triangulates the distance based on where it sees the reflection. The dot itself is not perfectly sharp, so the triangulation result gets affected by reflective quality of the obstacle on which it lands. A dot on a white surface will appear to be slightly closer than one on a black plane. The ambient light (including sunlight) containing infrared spectrum will also increase the perceived radius of the dot.
      Most IR remotes project a soft cone of light as oppose to a focused beam, so they won’t cause much error in reading. A ray of sunlight, in comparison, will generate a measurement error 100x greater. The device is best suited for indoor applications with constant lighting containing the least amount of IR. To get the idea of what the sensor actually sees check out my post higher in the thread.

  • Hey, all these sharp proximity sensors are obselete!
    I almost used them on a project.

    • They work reasonably well and there doesn’t appear to be any single-component replacement available. Get ‘em while the getting is good.

  • The connector is a bit strange. I unsoldered it and soldered on a few 90 degree male header pins.

  • Had a chance to test these out today. Managed to reliably extract about 1/3 of the maximum stated range (60cm) off a 4.5 volt power supply. Increasing the voltage to 5.5v raised the max range all the way to the stated 1.5m. Much like with sonic sensors, the power supply affects the intensity of the dot/ping and the max detection range. However the input voltage does not change the min range cutoff, so if 15cm is too much for you, go with a mid or short range Sharp sensor.
    Overall, great value, fast response and negligibly low self-noise.

  • Would it be possible to raise the item limit to 5? The robots I build tend to have an odd number of proximity sensors for symmetrical obstacle detection. There’s a central sensor and a matching number for the left and right side. 3 sensors are enough for some setups, but for anything more complex (near/far side detection) or for motion tracking 4 just isn’t enough.
    Last time I needed to track linear movement, I had to go with a thermopile array, just because I couldn’t buy enough stand alone infrared detectors from Sparkfun.

    • You know, Jade, I’d be willing to bet if you explained your situation to Sparkfun, they’d let you buy the extra sensor. They’re reasonable folk.

  • 20 feet is pushing IR. I think Sharp makes one for that range. Beyond 20 feet, you’ll have to rely on LASER ranging ($$$). You might also try two parallel LASER beams and a TV camera, and try analyzing the number of pixels apart the two beam dots are, but that’s only theoretical and may require LASER power that could be harmful to human (and animal) eyes.

  • Do they make something like this that works up to 50 feet?

  • I hooked this up to my Arduino, but I am not getting any input voltage. How should the wires be connected?

    • Check the datasheet… One really fun gotcha of this component is that it needs two reads to really stabilize the data and get good information, but it will tell you the first read, meaning that if there is constant motion, or something JUST NOW stopped, your first read will be trash, and subsequent reads will actually have a basis in reality.

      • Re the comments on the “gotcha” - this comment threw me off a bit. I interpreted it as meaning every other read would be garbage..but actually it’s really just the very first read which (for me anyway) is no big deal.
        -Randy

    • I take that back. The input voltage seems to be random, and not related to how far an object is.

  • The equation I derived through measurements and am using with pretty good success is: y = 21208 * pow(x, -1.251);

    y = distance in inches. x = analog reading from sensor.

    The sensor works pretty good and buffering the values certainly helps with a more stable output. I’m buffering 10 values.

    I forgot to buy the 3 pin JST connectors with my sensors so placed an order for a bunch of 2, 3, 4, 6, & 8 pin PH connectors (male & female) from digikey.

    Sorry for multiple posts….The site is not compatible with Opera browser for posting comments.


Related Products