IR Obstacle Avoidance Module

These IR proximity sensors work by detecting the reflected IR from an LED on an object in front of them. An IR photodiode sees the illuminated spot on the object and compares it to the voltage setpoint given by a potentiometer. The output is a digital on/off signal that can be read by a digital pin on the Arduino. The signal goes low when an object (obstacle) is detected, and high when the object is no longer seen.

How does it work?

A little object that is light and shiny triggers at 6 inches, while a darker object triggers at one inch. Curved, dull, and/or dark objects trigger closer, while flat, shiny, and/or light colored objects trigger farther away. This results in dark objects appearing farther away than they really are.

I would think that might make it less useful for it's intended use, which is obstacle avoidance, and more useful for detection of static objects, like objects on an assembly line, the edge of a door as it opens, etc. I can envision one looking at the top of the garage door to see if it is open or closed, or even open partway. Since it has a mounting hole, you can put it in a fixed position and adjust the detection distance.

The IR proximity module connected to the Arduino Uno. It is just a 3-wire device, with +5V, ground, and output. I addded an LED so I could see that it was actually being read. There is a pair of LEDs on the board, one of which shows the triggered state of the device, but it doesn't show that the signal is making it to the Uno.

The board draws 38mA at 5V when out of range, and 41mA when it is detecting an object. That is mostly the IR LED current, but a small part of it, maybe 6mA, is the power LED and the trigger LED. It draws 21mA/23mA at 3.3V, with a much reduced range of detection.


void setup() {

  pinMode(2, INPUT);
  pinMode(3, OUTPUT);
}

void loop() {

  digitalWrite(3, digitalRead(2));
}
    

The program simply writes to the LED anything it reads from the sensor. When the sensor detects an object the output goes low. The program puts that low on the cathode of the LED, lighting it. If you were using this device for obstacle avoidance, you would pick a direction to turn when the signal goes low, and turn until it is no longer low.


void loop() {

  if (digitalRead(2) == 0)
  {
    stopForward();
    startRightTurn();
    while (digitalRead(2) == 0);
    stopRightTurn();
    startForward();
  }
}
    

This pseudo code shows a method of avoiding an obstacle. You detect the obstacle, stop forward motion, and start a turn, which takes some time to complete. You continue to turn until the obstacle is no longer seen, then stop the turn and restart forward motion.

Arduino Board Logo

 

Arduino-Board is the go-to source for information on many available Arduino and Arduino-like boards, tutorials and projects.

Help and Support

Arduino-Board

Stay updated

Sign up if you would like to receive our once monthly newsletter.