Keyes IR obstacle avoidance sensor


The Funduino Tracking Maze Robot also comes with 3 IR Obstacle Avoidance Sensors. I couldn’t find any information about it, but i found information about similar ones and give it a try.

The sensor works by sending infrared rays of certain frequency. When the infrared ray meets an obstacle(reflection surface), it is reflected and received by receiver. Then the corresponding indicator light is on. The sensor has a potentiometer knob you can adjust to change the detection distance. I’ve managed to work with 10,5 cm (roughly 4.1 inches).

Although the sensor has 4 PINs, only the first 3 are used. The last PIN, apparently does nothing (but correct me if i’m wrong).  I went trying to work with it using the PIN – EN – as an activation sensor PIN (putting it in HIGH) and deactivating the sensor (putting it on LOW), but the result was the same. The sensor always worked. When reading, the input is always 1.

Here are the connections of the sensor (from GND to EN)

GND Vcc Input signal EN – not used

And, for testing with the Arduino, the connection PINs:

Sensor Arduino
+ 5v
Out PIN 9
EN Not used


Here a small code to test the sensor

By default, the sensor returns 1. When detecting something, the sensor returns 0.


15 Replies to “Keyes IR obstacle avoidance sensor

  1. Hi
    That’s a nice clear article. I have one of these that I have just picked up to play with with the view of using it in an Airharp. I found that these sensors have some sort of analogue output, which is quite useful although I have yet to find some variables and setings to calibrate it. The code I used was that from the Arduino Cookbook for the Sharp IR distance sensor. As you will see there is a lookup table in it to deal with the non-linearity of the sensor. At the moment the sketch just reads a value between 5000 and about 3500mV over a very short distance at around 10cm. So, as I say there is a need for me to calibrate this device and or the lookup table properly. Is it suitable for an Airharp? Probably not.

    IR Distance Sketch from the Arduino Cookbook
    This sketch is designed for the Sharp IR Distance Sensor
    but I am trying the KeyesIR Obstacle Avoidance Sensor module

    Pins are:
    5V to + on module
    GND to GND
    A0 to output on module
    EN (Enable) on module is not connected to anything.


    const int ledPin = 13;
    const int sensorPin = 0;

    const long referenceMv = 5000;

    void setup()
    pinMode(ledPin, OUTPUT);

    void loop()
    int val = analogRead(sensorPin);
    int mV = (val*referenceMv)/1023;

    int cm = getDistance(mV);



    const int TABLE_ENTRIES = 12;
    const int firstElement = 250;
    const int INTERVAL = 250;
    static int distance[TABLE_ENTRIES] = {150,140,130,100,60,50,40,35,30,25,20,15};

    int getDistance(int mV)
    return distance[TABLE_ENTRIES-1];
    int index = mV/INTERVAL;
    float frac = (mV % 250)/(float)INTERVAL;
    return distance[index] – ((distance[index]-distance[index+1])*frac);

  2. I got one of these in a kit and it works great but I was curious; there are 2 10K ohm pots; 1 changes sensitivity for distance but does anyone know what the 2nd one does?

      1. The second one changes IR frequency, it should be labled (do not touch) & I suspect was placed there to test your willpower, or lack thereof 🙂

  3. Hi!
    To get the E pin to work you have to remove the jumper, the jumper sets the E (enable) pin to ground.

  4. Hey there, I’m using the exact same sensor and code. But the serial monitor only shows that there is an object. Even when there isn’t. Kindly​ help .

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.