{"product_id":"sharp-gp2y0a02yk0f-ir-distance-measuring-sensor-module","title":"Sharp GP2Y0A02YK0F IR Distance Measuring Sensor Module","description":"\u003cp\u003e\u003cspan\u003eUses Infrared (IR) to detect and measure the distance to the objects up to 5 feet\u003c\/span\u003e\u003c\/p\u003e\n\u003ch2\u003eDESCRIPTION\u003c\/h2\u003e\n\u003cp\u003eThe Sharp GP2Y0A02YK0F Distance Measuring Sensor Module uses Infrared (IR) to both detect obstacles and measure the distance to the objects in front of it.  The detection and measurement range is from 20cm up to 150cm (8″ to 60″).  We ship these sensors with a compatible 8″ JST pigtail cable for easy hook-up.\u003c\/p\u003e\n\u003ch2\u003ePACKAGE INCLUDES:\u003c\/h2\u003e\n\u003cul\u003e\n\u003cli\u003eSharp GP2Y0A02YK0F Distance Measuring Sensor module\u003c\/li\u003e\n\u003cli\u003eFemale JST 3-wire 8″ pig-tail cable\u003c\/li\u003e\n\u003c\/ul\u003e\n\u003ch2\u003eKEY FEATURES OF SHARP GP2Y-A-2YK0F DISTANCE MEASURING SENSOR MODULE:\u003c\/h2\u003e\n\u003cul\u003e\n\u003cli\u003eCompact design\u003c\/li\u003e\n\u003cli\u003eDetection range of 20 cm to 150 cm (8″ to 60″)\u003c\/li\u003e\n\u003cli\u003eAnalog output relative to the detection distance\u003c\/li\u003e\n\u003cli\u003e5V Operation\u003c\/li\u003e\n\u003c\/ul\u003e\n\u003cp\u003eThe sensors operate by transmitting 1 kHz bursts of IR which are repeated at a 24 Hz rate and detecting the reflected light using a PSD (Position Sensitive Detector) that allows it to both detect objects via reflection, as well as calculate the distance to the object.  This setup allows the sensor to detect most surfaces fairly well independent of how reflective the surface is.  The IR is not visible to the human eye, but can be observed by looking at the sensor with a cell phone camera which is sensitive to IR light as shown in one of the pics.\u003c\/p\u003e\n\u003cp\u003eThese types of sensors can be used in robotics for object detection and distance measurements such as for obstacle avoidance, but they also work well for implementing applications such as touch-less switches or proximity sensing as might be used at an ATM to detect that someone is standing in front of the machine.  The detection angle is not specified, but it is fairly narrow.  These types of sensors are sometimes mounted to servo motors, so that the sensor can ‘look around’ at more of its environment.\u003c\/p\u003e\n\u003cp\u003eThe output of the sensor is analog with the distance represented by an analog voltage that can be read by an ADC input on a uC.  The output voltage ranges from about 0.4V to 2.7V and increases as the distance gets shorter. \u003cspan\u003e \u003c\/span\u003e\u003cem\u003eTake careful note that once a minimum distance of about 15cm is reached, the voltage will reverse direction and begin to decrease as the distance continues to get shorter, so use care not to misinterpret the results once inside the valid measurement range.\u003c\/em\u003e\u003c\/p\u003e\n\u003ch3\u003eConnections\u003c\/h3\u003e\n\u003cp\u003eThere is a 3-pin header on the assembly.  The pins are not labeled, but by using the supplied cable harness wire colors, the pin-out is as shown below.\u003c\/p\u003e\n\u003cp\u003e\u003cstrong\u003e1 x 3 Header\u003c\/strong\u003e\u003c\/p\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cstrong\u003eRed Wire\u003c\/strong\u003e\u003cspan\u003e \u003c\/span\u003e–        Connect to 5V.\u003c\/li\u003e\n\u003cli\u003e\n\u003cstrong\u003eBlack Wire\u003c\/strong\u003e\u003cspan\u003e \u003c\/span\u003e–     Connect to system ground.  This ground needs to be in common with the microcontroller.\u003c\/li\u003e\n\u003cli\u003e\n\u003cstrong\u003eYellow Wire\u003c\/strong\u003e  –  Analog output.  Connect to any ADC input on microcontroller.\u003c\/li\u003e\n\u003c\/ul\u003e\n\u003ch2\u003eOUR EVALUATION RESULTS:\u003c\/h2\u003e\n\u003cp\u003eThis is a commonly used module for obstacle detection and basic range finding.  These modules are much more capable than the basic IR obstacle avoidance sensors that come in sensor kits and are highly recommended if you are building a motorized robotic car and want to implement a nicely capable obstacle avoidance system or just want to measure distance for some other reason using IR.   A possible alternative to consider for this application is an ultrasonic sensor which uses sound rather than light.\u003c\/p\u003e\n\u003cp\u003eThere is not a stated measurement accuracy for this sensor.  Empirical testing under typical use conditions indicates it seems reasonable to expect about a +\/- 10% accuracy which is adequate for most applications.\u003c\/p\u003e\n\u003cp\u003eThe maximum analog output of the sensor is less than 3V, so one technique to optimize distance measurement accuracy is to use an ADC reference voltage of 3V – 3.3V rather than the typical 5V.  This gives a finer resolution to the sensor readings.  Arduino boards have an AREF pin that can be used to input a specific voltage for the ADC to operate on.  If an external voltage is used, then the command\u003cspan\u003e \u003c\/span\u003e\u003cstrong\u003eanalogReference (EXTERNAL)\u003c\/strong\u003e\u003cspan\u003e \u003c\/span\u003emust be given to tell the microcontroller to use that external voltage.  Empirical bench testing indicated an accuracy improvement of about 0.25″ at a distance of 10″ when going from a 5V to 3V ADC reference voltage.  If using a 3.3V microcontroller, the ADC will already be running at 3.3V.\u003c\/p\u003e\n\u003cp\u003eThese sensors operate in a burst mode that creates fairly sharp current spikes on the power lines.  If the sensor is positioned remotely from the power supply, the manufacturer recommends that a 10uF or larger capacitor should be placed across the power and ground lines close to the sensor to reduce noise spikes.  We have measured a definite noise improvement with an O-Scope when that is done and it is good practice, but measurement accuracy did not seem to be affected much, especially if multiple readings are averaged as is done in the example code down below.\u003c\/p\u003e\n\u003cp\u003eThe program below implements a basic setup where the  measured range is displayed in centimeters and inches.  There are constants at the beginning of the program that allow you to change the number of readings to average together as well as setting the ADC voltage if changed from 5V.  If using an external ADC voltage, be sure to uncomment this line:  \u003cem\u003e\u003cspan\u003e \u003c\/span\u003e\/\/ analogReference(EXTERNAL);\u003c\/em\u003e\u003c\/p\u003e\n\u003ch3\u003eSharp GP2Y0A02YK0F Distance Measuring Sensor Module S Test Program\u003c\/h3\u003e\n\u003cpre class=\"copy-the-code-target\"\u003e\u003cspan\u003e\/*\u003c\/span\u003e\n\u003cspan\u003eSharp IR Sensor GP2Y0A02YK0F Test\u003c\/span\u003e\n\u003cspan\u003eBasic code for reading the the output of the sensor and converting that to distance\u003c\/span\u003e\n\u003cspan\u003eUses averaging over multiple readings to smooth the readings.\u003c\/span\u003e\n\u003cspan\u003e*\/\u003c\/span\u003e\n\u003cspan\u003eint\u003c\/span\u003e \u003cspan\u003econst\u003c\/span\u003e \u003cspan\u003eIR_PIN\u003c\/span\u003e \u003cspan\u003e=\u003c\/span\u003e \u003cspan\u003eA0\u003c\/span\u003e\u003cspan\u003e;\u003c\/span\u003e              \u003cspan\u003e\/\/ analog pin for reading the IR sensor\u003c\/span\u003e\n\u003cspan\u003eint\u003c\/span\u003e \u003cspan\u003econst\u003c\/span\u003e \u003cspan\u003eNUM_READINGS_TO_AVG\u003c\/span\u003e \u003cspan\u003e=\u003c\/span\u003e \u003cspan\u003e10\u003c\/span\u003e\u003cspan\u003e;\u003c\/span\u003e \u003cspan\u003e\/\/ Number of readings to average together\u003c\/span\u003e\n\u003cspan\u003efloat\u003c\/span\u003e \u003cspan\u003econst\u003c\/span\u003e \u003cspan\u003eADC_VOLTAGE\u003c\/span\u003e \u003cspan\u003e=\u003c\/span\u003e \u003cspan\u003e5.0\u003c\/span\u003e\u003cspan\u003e;\u003c\/span\u003e      \u003cspan\u003e\/\/ Voltage that ADC is operating at. \u003c\/span\u003e\n\u003cspan\u003efloat\u003c\/span\u003e \u003cspan\u003eADC_Step\u003c\/span\u003e\u003cspan\u003e;\u003c\/span\u003e                     \u003cspan\u003e\/\/ Holds the voltage per step\u003c\/span\u003e\n\u003cspan\u003e\/\/===============================================================================\u003c\/span\u003e\n\u003cspan\u003e\/\/  Initialization\u003c\/span\u003e\n\u003cspan\u003e\/\/===============================================================================\u003c\/span\u003e\n\u003cspan\u003evoid\u003c\/span\u003e \u003cspan\u003esetup\u003c\/span\u003e\u003cspan\u003e(\u003c\/span\u003e\u003cspan\u003e)\u003c\/span\u003e \n\u003cspan\u003e{\u003c\/span\u003e\n \u003cspan\u003e\/\/ analogReference(EXTERNAL);     \/\/ Uncomment this line if using an external ADC reference source\u003c\/span\u003e\n \u003cspan\u003eADC_Step\u003c\/span\u003e \u003cspan\u003e=\u003c\/span\u003e \u003cspan\u003eADC_VOLTAGE\u003c\/span\u003e \u003cspan\u003e\/\u003c\/span\u003e \u003cspan\u003e1024\u003c\/span\u003e\u003cspan\u003e;\u003c\/span\u003e   \u003cspan\u003e\/\/ calculate the voltage per ADC step \u003c\/span\u003e\n \u003cb\u003e\u003cspan\u003eSerial\u003c\/span\u003e\u003c\/b\u003e\u003cspan\u003e.\u003c\/span\u003e\u003cspan\u003ebegin\u003c\/span\u003e\u003cspan\u003e(\u003c\/span\u003e\u003cspan\u003e9600\u003c\/span\u003e\u003cspan\u003e)\u003c\/span\u003e\u003cspan\u003e;\u003c\/span\u003e              \u003cspan\u003e\/\/ Set comm speed for debug window messages\u003c\/span\u003e\n\u003cspan\u003e}\u003c\/span\u003e\n\u003cspan\u003e\/\/===============================================================================\u003c\/span\u003e\n\u003cspan\u003e\/\/  Main\u003c\/span\u003e\n\u003cspan\u003e\/\/===============================================================================\u003c\/span\u003e\n\u003cspan\u003evoid\u003c\/span\u003e \u003cspan\u003eloop\u003c\/span\u003e\u003cspan\u003e(\u003c\/span\u003e\u003cspan\u003e)\u003c\/span\u003e \n\u003cspan\u003e{\u003c\/span\u003e\n \u003cspan\u003efloat\u003c\/span\u003e \u003cspan\u003esum\u003c\/span\u003e \u003cspan\u003e=\u003c\/span\u003e \u003cspan\u003e0\u003c\/span\u003e\u003cspan\u003e;\u003c\/span\u003e\n \u003cspan\u003efor\u003c\/span\u003e \u003cspan\u003e(\u003c\/span\u003e\u003cspan\u003eint\u003c\/span\u003e \u003cspan\u003ei\u003c\/span\u003e\u003cspan\u003e=\u003c\/span\u003e\u003cspan\u003e0\u003c\/span\u003e\u003cspan\u003e;\u003c\/span\u003e \u003cspan\u003ei\u003c\/span\u003e\u003cspan\u003e\u0026lt;\u003c\/span\u003e\u003cspan\u003eNUM_READINGS_TO_AVG\u003c\/span\u003e\u003cspan\u003e;\u003c\/span\u003e \u003cspan\u003ei\u003c\/span\u003e\u003cspan\u003e++\u003c\/span\u003e\u003cspan\u003e)\u003c\/span\u003e  \u003cspan\u003e\/\/ Take the number of readings that you want to average\u003c\/span\u003e\n \u003cspan\u003e{\u003c\/span\u003e\n   \u003cspan\u003esum\u003c\/span\u003e \u003cspan\u003e+=\u003c\/span\u003e \u003cspan\u003eanalogRead\u003c\/span\u003e\u003cspan\u003e(\u003c\/span\u003e\u003cspan\u003eIR_PIN\u003c\/span\u003e\u003cspan\u003e)\u003c\/span\u003e\u003cspan\u003e;\u003c\/span\u003e\n \u003cspan\u003e}\u003c\/span\u003e\n \u003cspan\u003efloat\u003c\/span\u003e \u003cspan\u003evolts\u003c\/span\u003e \u003cspan\u003e=\u003c\/span\u003e \u003cspan\u003esum\u003c\/span\u003e \u003cspan\u003e\/\u003c\/span\u003e \u003cspan\u003eNUM_READINGS_TO_AVG\u003c\/span\u003e \u003cspan\u003e*\u003c\/span\u003e \u003cspan\u003eADC_Step\u003c\/span\u003e\u003cspan\u003e;\u003c\/span\u003e  \u003cspan\u003e\/\/ Calculate average * volts per ADC step \u003c\/span\u003e\n \u003cspan\u003efloat\u003c\/span\u003e \u003cspan\u003edistance\u003c\/span\u003e \u003cspan\u003e=\u003c\/span\u003e \u003cspan\u003e65\u003c\/span\u003e\u003cspan\u003e*\u003c\/span\u003e\u003cspan\u003epow\u003c\/span\u003e\u003cspan\u003e(\u003c\/span\u003e\u003cspan\u003evolts\u003c\/span\u003e\u003cspan\u003e,\u003c\/span\u003e \u003cspan\u003e-\u003c\/span\u003e\u003cspan\u003e1.10\u003c\/span\u003e\u003cspan\u003e)\u003c\/span\u003e\u003cspan\u003e;\u003c\/span\u003e    \u003cspan\u003e\/\/ Calculate distance from voltage.  Formula attributed to luckylarry.co.uk\u003c\/span\u003e\n \u003cb\u003e\u003cspan\u003eSerial\u003c\/span\u003e\u003c\/b\u003e\u003cspan\u003e.\u003c\/span\u003e\u003cspan\u003eprint\u003c\/span\u003e\u003cspan\u003e(\u003c\/span\u003e\u003cspan\u003edistance\u003c\/span\u003e\u003cspan\u003e)\u003c\/span\u003e\u003cspan\u003e;\u003c\/span\u003e                   \u003cspan\u003e\/\/ Printout the results to the Serial Monitor\u003c\/span\u003e\n \u003cb\u003e\u003cspan\u003eSerial\u003c\/span\u003e\u003c\/b\u003e\u003cspan\u003e.\u003c\/span\u003e\u003cspan\u003eprint\u003c\/span\u003e\u003cspan\u003e(\u003c\/span\u003e\u003cspan\u003e\" cm t\"\u003c\/span\u003e\u003cspan\u003e)\u003c\/span\u003e\u003cspan\u003e;\u003c\/span\u003e\n \u003cb\u003e\u003cspan\u003eSerial\u003c\/span\u003e\u003c\/b\u003e\u003cspan\u003e.\u003c\/span\u003e\u003cspan\u003eprint\u003c\/span\u003e\u003cspan\u003e(\u003c\/span\u003e\u003cspan\u003edistance\u003c\/span\u003e\u003cspan\u003e\/\u003c\/span\u003e\u003cspan\u003e2.54\u003c\/span\u003e\u003cspan\u003e)\u003c\/span\u003e\u003cspan\u003e;\u003c\/span\u003e\n \u003cb\u003e\u003cspan\u003eSerial\u003c\/span\u003e\u003c\/b\u003e\u003cspan\u003e.\u003c\/span\u003e\u003cspan\u003eprintln\u003c\/span\u003e\u003cspan\u003e(\u003c\/span\u003e\u003cspan\u003e\" in\"\u003c\/span\u003e\u003cspan\u003e)\u003c\/span\u003e\u003cspan\u003e;\u003c\/span\u003e\n \u003cspan\u003edelay\u003c\/span\u003e\u003cspan\u003e(\u003c\/span\u003e\u003cspan\u003e500\u003c\/span\u003e\u003cspan\u003e)\u003c\/span\u003e\u003cspan\u003e;\u003c\/span\u003e\n\u003cspan\u003e}\u003c\/span\u003e\n\u003cbutton class=\"copy-the-code-button\" data-style=\"svg-icon\" title=\"Copy\"\u003e\u003csvg aria-hidden=\"true\" role=\"img\" class=\"copy-icon\" viewbox=\"0 0 16 16\" width=\"16\" height=\"16\" fill=\"currentColor\" focusable=\"false\"\u003e\u003cpath d=\"M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 0 1 0 1.5h-1.5a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-1.5a.75.75 0 0 1 1.5 0v1.5A1.75 1.75 0 0 1 9.25 16h-7.5A1.75 1.75 0 0 1 0 14.25Z\"\u003e\u003c\/path\u003e\u003cpath d=\"M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0 1 14.25 11h-7.5A1.75 1.75 0 0 1 5 9.25Zm1.75-.25a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-7.5a.25.25 0 0 0-.25-.25Z\"\u003e\u003c\/path\u003e\u003c\/svg\u003e\u003c\/button\u003e\u003c\/pre\u003e\n\u003cp\u003eThe module has 2 holes that can be used for mounting.\u003c\/p\u003e\n\u003ch2\u003eBEFORE THEY ARE SHIPPED, THESE MODULES ARE:\u003c\/h2\u003e\n\u003cul\u003e\n\u003cli\u003eInspected\u003c\/li\u003e\n\u003cli\u003eBasic obstacle detection and range finding operation verified\u003c\/li\u003e\n\u003cli\u003ePackaged in a high quality resealable ESD bag for protection and easy storage.\u003c\/li\u003e\n\u003c\/ul\u003e\n\u003cp\u003e\u003cem\u003eNotes: \u003c\/em\u003e\u003c\/p\u003e\n\u003col\u003e\n\u003cli\u003e\u003cem\u003eTake note that once a minimum distance of about 15cm is reached, the voltage will reverse direction and begin to decrease as the distance continues to get shorter, so use care not to misinterpret the results once inside the valid measurement range.\u003c\/em\u003e\u003c\/li\u003e\n\u003c\/ol\u003e\n\u003chr\u003e\n\u003ch2\u003eTECHNICAL SPECIFICATIONS\u003c\/h2\u003e\n\u003ctable class=\"table table-hover\" width=\"1206\"\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd width=\"145\"\u003e\u003cstrong\u003eMaximum Ratings\u003c\/strong\u003e\u003c\/td\u003e\n\u003ctd width=\"264\"\u003e\u003c\/td\u003e\n\u003ctd width=\"229\"\u003e\u003c\/td\u003e\n\u003c\/tr\u003e\n\u003ctr\u003e\n\u003ctd width=\"145\"\u003e          V\u003csub\u003ecc\u003c\/sub\u003e\n\u003c\/td\u003e\n\u003ctd width=\"264\"\u003e\u003c\/td\u003e\n\u003ctd width=\"229\"\u003e4.5 – 5.5V  (5V typical)\u003c\/td\u003e\n\u003c\/tr\u003e\n\u003ctr\u003e\n\u003ctd width=\"145\"\u003e          I\u003csub\u003eMax\u003c\/sub\u003e\n\u003c\/td\u003e\n\u003ctd width=\"264\"\u003eMaximum Current Draw\u003c\/td\u003e\n\u003ctd width=\"229\"\u003e33mA (typical)\u003c\/td\u003e\n\u003c\/tr\u003e\n\u003ctr\u003e\n\u003ctd width=\"145\"\u003e\u003cstrong\u003eOperating Ratings\u003c\/strong\u003e\u003c\/td\u003e\n\u003ctd width=\"264\"\u003e\u003c\/td\u003e\n\u003ctd width=\"229\"\u003e\u003c\/td\u003e\n\u003c\/tr\u003e\n\u003ctr\u003e\n\u003ctd width=\"145\"\u003e          Frequency\u003c\/td\u003e\n\u003ctd width=\"264\"\u003eBurst Modulation\u003c\/td\u003e\n\u003ctd width=\"229\"\u003e1KHz\u003c\/td\u003e\n\u003c\/tr\u003e\n\u003ctr\u003e\n\u003ctd width=\"145\"\u003e\u003c\/td\u003e\n\u003ctd width=\"264\"\u003eBurst Frequency\u003c\/td\u003e\n\u003ctd width=\"229\"\u003e24Hz\u003c\/td\u003e\n\u003c\/tr\u003e\n\u003ctr\u003e\n\u003ctd width=\"145\"\u003e          Detection Range\u003c\/td\u003e\n\u003ctd width=\"264\"\u003e\u003c\/td\u003e\n\u003ctd width=\"229\"\u003e20cm – 150cm\u003c\/td\u003e\n\u003c\/tr\u003e\n\u003ctr\u003e\n\u003ctd width=\"145\"\u003e          Measurement Resolution\u003c\/td\u003e\n\u003ctd width=\"264\"\u003e\u003c\/td\u003e\n\u003ctd width=\"229\"\u003e+\/- 10% (typical)\u003c\/td\u003e\n\u003c\/tr\u003e\n\u003ctr\u003e\n\u003ctd width=\"145\"\u003e          Detection Angle\u003c\/td\u003e\n\u003ctd width=\"264\"\u003e\u003c\/td\u003e\n\u003ctd width=\"229\"\u003eUnspecified but very narrow\u003c\/td\u003e\n\u003c\/tr\u003e\n\u003ctr\u003e\n\u003ctd width=\"145\"\u003e         Output Voltage\u003c\/td\u003e\n\u003ctd width=\"264\"\u003e\u003c\/td\u003e\n\u003ctd width=\"229\"\u003e 0.4V – 2.7V (Typical)\u003c\/td\u003e\n\u003c\/tr\u003e\n\u003ctr\u003e\n\u003ctd width=\"145\"\u003e\u003cstrong\u003eDimensions\u003c\/strong\u003e\u003c\/td\u003e\n\u003ctd width=\"264\"\u003eL x W x H\u003c\/td\u003e\n\u003ctd width=\"229\"\u003e29.5 x 13 x 21.6mm (1.16 x 0.85″)\u003c\/td\u003e\n\u003c\/tr\u003e\n\u003ctr\u003e\n\u003ctd width=\"145\"\u003e\u003cstrong\u003eCountry of Origin\u003c\/strong\u003e\u003c\/td\u003e\n\u003ctd width=\"264\"\u003e\u003c\/td\u003e\n\u003ctd width=\"229\"\u003eChina\u003c\/td\u003e\n\u003c\/tr\u003e\n\u003c\/tbody\u003e\n\u003c\/table\u003e\n\u003cp\u003eClick for Sensor \u003cstrong\u003e\u003ca href=\"http:\/\/www.sharp-world.com\/products\/device\/lineup\/data\/pdf\/datasheet\/gp2y0a02yk_e.pdf\" rel=\"noopener noreferrer\" target=\"_blank\"\u003eDatasheet\u003c\/a\u003e\u003c\/strong\u003e\u003c\/p\u003e\n\u003c!----\u003e","brand":"Keszoox","offers":[{"title":"Default Title","offer_id":45681354146027,"sku":"","price":34.37,"currency_code":"USD","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0677\/1005\/8731\/files\/Sharp-GP2Y0A02YK0F-IR-Distance-Measuring-Module.jpg?v=1723005989","url":"https:\/\/keszooxstore.com\/products\/sharp-gp2y0a02yk0f-ir-distance-measuring-sensor-module","provider":"Keszoox","version":"1.0","type":"link"}