Grove - 80cm Infrared Proximity Sensor


3.3V 5.0V Analog

The 80cm Infrared Proximity Sensor is a General Purpose Type Distance Measuring Sensor. This sensor SharpGP2Y0A21YK, boasts a small package and very low current consumption, takes a continuous distance reading and returns a corresponding analog voltage with a range of 10cm (4”) to 80cm (30”). Can be used in TVs, personal computers, cars and so on.


  • Easy to use
  • Wide supply voltage range: 2.5V–7V
  • Grove Interface


More details about Grove modules please refer to Grove System

Application Ideas

  • Waterdrop conservation
  • Toys
  • Robotics


Item Minimum Typical Maximum
Working Voltage 2.5V 5V 7V
Analog Output Voltage(80cm) 0.25V 0.4V 0.5V
Average Current Consumption - 33mA 50mA

Platforms Supported


With Arduino

The Infrared Proximity sensor is easy to use. The relationship between the voltage reading and the distance as shown below. When we read the voltage, which indicate the distance from the object in front to this sensor.

  • Connect the 3-pin connector to the sensor, and connect the 4-pin connector to the A1 port of the Grove-Base Shield.


This sensor is quite small and use a tiny connector called the Japan Solderless Terminal (JST) connector. These connectors have three wires: Ground, Vcc, and the Output signal. Because this sensor fires continuously and doesn't need any clock to initiate a reading cycle, it is easy to interface with any microcontroller. For Arduino & Seeeduino, we prepared a 4-pin to 3-pin wire to convert the 3-pin connecter on the sensor to 4-pin connecter on the Grove Base Shield, to compatible with the Seeeduino Grove interface.
  • Connect Arduino/Seeeduino via a USB cable.

  • Copy and paste code below to a new Arduino sketch.
    #define IR_PROXIMITY_SENSOR A1 // Analog input pin that  is attached to the sensor
    #define ADC_REF 5//reference voltage of ADC is 5v.If the Vcc switch on the Seeeduino
                     //board switches to 3V3, the ADC_REF should be 3.3
    float voltage;//the sensor voltage, you can calculate or find the distance
                    // to the reflective object according to the figures
                    //on page 4 or page 5 of the datasheet of the GP2Y0A21YK.

    void setup()
        // initialise serial communications at 9600 bps:

    void loop()
        voltage = getVoltage();
        Serial.print("sensor voltage  = " );                       
        // wait 500 milliseconds before the next loop
    /*Function: Get voltage from the sensor pin that is connected with analog pin*/
    /*Parameter:-void                                                       */
    /*Return:   -float,the voltage of the analog pin                        */
    float getVoltage()
        int sensor_value;
        int sum;  
        // read the analog in value:
        for (int i = 0;i < 20;i ++)//Continuous sampling 20 times
            sensor_value = analogRead(IR_PROXIMITY_SENSOR);
            sum += sensor_value;
        sensor_value = sum / 20;
        float voltage;
        voltage = (float)sensor_value*ADC_REF/1024;
        return voltage;
  • Upload the code.
  • Open the Serial Monitor, you can get the voltage. you can calculate or find the distance to the reflective object according to the below figures.


Because of some basic trigonometry within the triangle from the emitter to reflection spot to receiver, the output of the detector is non-linear with respect to the distance being measured.

With Raspberry Pi

1.You should have got a raspberry pi and a grovepi or grovepi+.

2.You should have completed configuring the development environment, otherwise follow here.


  • Plug the sensor to grovepi socket D4 by using a grove cable.

4.Navigate to the demos’ directory:

   cd yourpath/GrovePi/Software/Python/
  • To see the code
    nano    # "Ctrl+x" to exit #
    import time
    import grovepi

    # Connect the Grove Infrared Distance Interrupt Sensor to digital port D4
    sensor = 4


    while True:
            # Sensor returns LOW and onboard LED lights up when the
            # received infrared light intensity exceeds the calibrated level
            if grovepi.digitalRead(sensor) == 0:
                print "found something"
                print "nothing"


        except IOError:
            print "Error"

5.Run the demo.

    sudo python


This new rangers use triangulation and a small linear CCD array to compute the distance and/or presence of objects in the field of view. The basic idea is this: a pulse of IR light is emitted by the emitter. This light travels out in the field of view and either hits an object or just keeps on going. In the case of no object, the light is never reflected and the reading shows no object. If the light reflects off an object, it returns to the detector and creates a triangle between the point of reflection, the emitter, and the detector.

The angles in this triangle vary based on the distance to the object. The receiver portion of these new detectors is actually a precision lens that transmits the reflected light onto various portions of the enclosed linear CCD array based on the angle of the triangle described above. The CCD array can then determine what angle the reflected light came back at and therefore, it can calculate the distance to the object.

This new method of ranging is almost immune to interference from ambient light and offers amazing indifference to the color of object being detected. Detecting a black wall in full sunlight is now possible.


Help us make it better

Thank you for choosing Seeed. A couple of months ago we initiated a project to improve our documentation system. What you are looking at now is the first edition of the new documentation system. Comparing to the old one, here is the progresses that we made:

  • Replaced the old documentation system with a new one that was developed from Mkdocs, a more widely used and cooler tool to develop documentation system.
  • Integrated the documentation system with our official website, now you can go to Bazaar and other section like Forum and Community more conveniently.
  • Reviewed and rewrote documents for hundreds of products for the system’s first edition, and will continue migrate documents from old wiki to the new one.

An easy-to-use instruction is as important as the product itself. We are expecting this new system will improve your experience when using Seeed’s products. However since this is the first edition, there are still many things need to improve, if you have any suggestions or findings, you are most welcome to submit the amended version as our contributor or give us suggestions in the survey below, Please don’t forget to leave your email address so that we can reply.

Happy hacking