Obstacle Avoidance Module

by R Jordan Kreindler in Circuits > Arduino

8180 Views, 50 Favorites, 0 Comments

Obstacle Avoidance Module

IR Emitter and Receiver.jpg
IR Colision Avoidance Module Pins.jpg
IR Module and LED

I believe I have made this Instructable easy to understand. However, if after reading this you have any questions, please feel free to get in touch with me directly. You can contact me at transiintbox@gmail.com. (Please replace the second 'i' with an 'e' to contact me. Thank you.)

The IR Obstacle Avoidance Module is often found on smart cars or smart tanks. If an obstacle is found to be in front of the vehicle, i.e, is in front of the direction the vehicle is moving, the module senses this and implements code to move the vehicle in a different direction.

In fact, this is how the IR Obstacle Avoidance Module got its name, from its use in smart vehicles trying to avoid obstacles.

These IR Obstacle Avoidance Modules can usually, at the time of publication of this Instructable, be found for sale for less than $0.40 each, in bulk.

These typically have a working voltage of three point three (3.3) volts DC to five (5) volts DC.

Fortunately, this Module can do more than simply sense the need to change direction, or avoid obstacles.

The concept behind this Module is very easy to understand and its use is even easier. Thus, it is surprising it is not used in more Maker projects. Hopefully, this tutorial can help mitigate that situation.

It is probably best to think of this Module as a Momentary Button Switch that does not need to be touched. That is, it can be thought of as a Non-Contact Single-pole Momentary Obstacle (where the "hand" can be one such obstacle) detection sensor switch.

Many Maker projects use a Momentary Button Switch, and most online training courses for the Arduino UNO do as well. The IR Obstacle Avoidance Module can be used in place of a dedicated Momentary Button Switch. That is, this IR Module should probably be chosen and used more often than it is.

The IR Obstacle Avoidance Module typically comes configured with three pins, as can be seen in an attached photograph. The pins are labeled OUT, GND, and VCC. If an Arduino UNO is used, the GND pin on the Module connects to any ground header on the UNO, and the VCC pin on the Module connects to the 5 volts header on the UNO. These two connections provide power to the module.

Of course, if a small breadboard is available, ground and positive voltage power rails are quite handy to use, as that allows ground and five volts DC to be easily accessible for other components.

The module contains two (2) IR-related LEDs: an IR emitter LED (clear) and an IR receiver LED (black), as can also be seen in an attached photograph.

The emitter LED sends out an IR signal, and if an obstacle is close enough this IR signal is reflected back and sensed by the IR receiver LED.

The module contains four (4) LEDs in total, i.e., two additional Green LEDs (see text below).

The sensing of a reflected IR signal by the LED receiver, after processing by a comparator circuit, turns on a Green LED on the module. The first Green LED is turned on when the module has power. When the second (2nd) Green LED is turned on (that is, an obstacle is close), the Module sends a zero (0), LOW, signal to the OUT pin of the module, as well as turning On this second (2nd) Green LED.

The second (2nd) Green LED will only turn On when the Module already has power, and an obstacle is close.

The output of the OUT pin can be read, and appropriate action taken. This action is typically defined by a portion of a software Sketch, as shown below.

The module can detect obstacles from approximately two (2) to thirty (30) centimetres.

The detection range of the sensor can be controlled by adjusting the onboard potentiometer.

The IR Obstacle Avoidance Module can be paired with an LED, relay, 1602 LCD display, etc., as shown in the Steps that follow. In fact, it can be paired with many different devices.

The software determines what action(s) will be taken by/for the paired device.

Supplies

The supplies that are needed are shown in the Steps where they are needed.

Hardware Configuration to Turn On/Off an LED Using the IR Collision Avoidance Module

Supplies Step 2.jpg
Completed Assembly-1.1.jpg
Completed Assembly-1.2.jpg
Completed Assembly-1.3.jpg

Supplies: (see attached photograph)

- a small breadboard

- an IR Obstacle Avoidance Module

- a 10 mm Red LED (however, a 3, 5, or 8 mm LED of any color will do as well)

- a 220 ohm resistor

- an Arduino UNO

- Dupont wires to connect components

I used an experimental platform in my example, but that is an optional item.

The attached photographs show the hardware assembly, using the capability of the IR Obstacle Avoidance Module, to turn On/Off an LED.

The configuration is quite simple. Power is provided to the positive and ground rails on a small breadboard. Power from these rails is in turn connected to the GND and VCC pins of the IR Module, to provide power to this Module.

The OUT pin from this IR Module is connected to digital header 7 of an Arduino UNO, in this example.

The positive side of a 10 mm Red LED is connected to one side of a 220 Ohm resistor the other side of this resistor goes to the 5 volt DC rail on the small breadboard.

The negative side of the LED goes to the ground power rail on the same small breadboard.

The Sketch to turn the LED On/Off is shown in the next step.

The Sketch to Turn an LED On/Off Without Physical Contact

IR Module and LED

Below is the Sketch that uses the IR Collision Avoidance Module to turn an LED On and Off.

Pictured here is a video showing the results of that Sketch in action.

Note: there is not need for physical contact with any of the components shown in the previous Step.

The operation of this Sketch is quite straightforward.

First the OUT pin of the IR Collision Avoidance Module is read, if the value is zero (0), LOW (that is, an obstacle is close) then the if loop is executed. The LED is turned On and Off, and the Sketch continues to execute the loop function to see if an obstacle is still/again close or not.

/*

TurnOn LED

Written June 19, 2020

by R Jordan Keindler

Uses an Arduino UNO

*/

int IRModulePinNumber = 7; // Set the OUT pin for the IR Obstacle Avoidance Module

// as header 7 on a UNO

int LED1 = 8; // Set the LED to digital pin 8 on a UNO

int val; // Make val an integer

void setup()

{

pinMode(IRModulePinNumber, INPUT); // Set the IR Obstacle Avoidance Module for input

pinMode(LED1, OUTPUT); // Set the LED for output

}

void loop() {

val = digitalRead(IRModulePinNumber); // Read the IR Collision Avoidance OUT pin

if (val == 0) // If an obstacle is near, perform the if loop

{

digitalWrite(LED1, HIGH); // Set the LED On

}

digitalWrite(LED1, LOW); // Turn the LED Off

}

Hardware Configuration to Turn On/Off a Single Channel Relay

Supplies.jpg

Supplies: (see attached photograph)

- a small breadboard

- an IR Obstacle Avoidance Module

- a single channel relay with dual LEDs that activates on LOW

- an Arduin0 UNO

- Dupont wires to connect components.

I used an experimental platform in my example, but that is not a necessary item.

The configuration is quite simple. We simply replace the LED and current limiting resistor used in the earlier Step 2, of this Instructable, with a LOW signal activated single channel relay with two LEDs.

Power is provided to the positive rail and ground rail on a small breadboard. Power from these rails is first connected to the GND and VCC pins to provide power to an IR Obstacle Avoidance Module which turns its first (1st) Green LED.

Power from the breadboard rails is also connected to the GND and VCC pins of a single channel LOW signal activated relay, to provide power to that relay.

Power to the relay lights its Red LED.

When the relay is activated not only is the Red LED On, but the Green LED is lighted as well. That is, when the relay is active, both its LEDs are turned On.

The Sketch to Turn On/Off a Relay Without Physical Contact

Relay in Use

Below is the Sketch that works with the single channel relay.

There are some changes from the earlier Sketch using an LED. Since the relay is activated by a LOW signal, unlike the LED which turns On with a HIGH signal, the digitalWrite() functions are reversed here from the LED sketch.

That is, the digitalWrite() function writes a LOW when an obstacle is close, i.e., it turns ON the second Green LED on the relay.

As can be seen in the attached video this activates the relay. We can see this as the Green LED comes On when an object is brought near the IR Obstacle Avoidance Module.

Since the relay is active, we can control any high power device, e.g., a lamp, coffee maker, etc., through the relay's output.

Of course, we will need to insure that we can provide sufficient external power to that high power device, as the Arduino UNO headers are not capable of providing much current, (possible only current as great as 40 ma).

If we want the relay to stay On longer we can add a delay() function after the digitalWrite(relay1, LOW), and set the delay() function to whatever time we wish for the relay to stay On.

/*

TurnOnOff Relay

Written June 19, 2020

by R Jordan Keindler

Uses an Arduino UNO

*/

int IRModulePinNumber = 7; // Set the OUT pin for the IR Obstacle Avoidance Module

// as header 7 on a UNO

int relay1 = 8; // Set the LED to digital pin 8 on a UNO

int val; // Make val an integer

void setup()

{

pinMode(IRModulePinNumber, INPUT); // Set the IR Obstacle Avoidance Module for input

pinMode(relay1, OUTPUT); // Set the LED for output

}

void loop() {

val = digitalRead(IRModulePinNumber); // Read the IR Collision Avoidance OUT pin

if (val == 0) // If an obstacle is near, perform the if loop

{

digitalWrite(relay1, LOW); // Set the relay On

}

digitalWrite(relay1, HIGH); // Turn the relay Off

}

Configuration Using the IR Obstacle Avoidance Sensor to Control an I2C 1602 Display

1602 Assembly-1.jpg
1602 Assemble-2.jpg
1602 Assembly-3.jpg

In a previous Instructable, "Arduino, 1602, & IR Sensor, CDC Guidelines, Non-Contact", I paired an I2C 1602 LCD display with the IR Obstacle Avoidance Module to show seconds for a wash hands module. (See attached photographs to show the configuration I used).

In fact it was this use that got me interested in the IR Collision Sensor,

This step shows the configuration needed for that timer display, and is a repeat of the Sketch included in the earlier Instructable.

The supplies needed for this project are,
- An Arduino UNO board

- A small breadboard -

- An IR Obstacle Avoidance Module

- An I2C 1602 LCD

- Dupont cables to connect components.

As before, I used an experimental platform, but it is not absolutely necessary, although it may prove useful. I used an experimental platform to make it easier to move the assembly as a single unit.

The Sketch to Make the I2C 1602 LCD Timer Function

CDC Guidelines Timer I2C LCD and Obstacle Avoidance Module

The Sketch to invoke the timer functionality is shown below.

The text between the brackets. i.e., that is the greater than and less than brackets, of a #include is generally missing in an Instructable, but is provided here in the attached text file. The first two includes should have brackets and text between these less than and greater than brackets. That is, there should be brackets and text after the #includes. The text these brackets should enclose are Wire.h and LiquidCrystal_I2C.h respectively


/*

Wash Hands Timer

Written June 14, 2020

by R Jordan Keindler

Uses an I2C 1602, An IR Obstacle Avoidance Module,

and an Arduino UNO

*/

#include // See text

#include // See text

LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display

int IRModulePinNumber = 7;

int delay1 = 1000;

int i;

int val;

void setup()

{

pinMode(IRModulePinNumber, INPUT);

lcd.init(); // initialize the lcd

Serial.begin(9600);

}

void loop() {

val = digitalRead(IRModulePinNumber); // Read the IR Collision Avoidance OUT pin

Serial.print(val);

Serial.print("\n");

if (val == 0) // If a hand is near

{

lcd.backlight(); // Turn on the backlight

lcd.clear(); // Clear the LCD and place cursor at first position on first line

lcd.print("Wash Hands Timer"); // Print "Wash Hands Timer" on first line of LCD

lcd.setCursor(0, 1); // Position display cursor on second line

lcd.print("Elapsed time: "); // Print "Elapsed time: " on second line of LCD

for (i = 1; i <= 60; i++) { // Count the seconds

lcd.setCursor(14, 1);

lcd.print(i);

delay(delay1);

}

lcd.noBacklight(); // Turn backlight Off

}

The timer runs from one (1) second to sixty (60) seconds.That is, its upper time in seconds exceeds CDC minimum guidelines, should a user care to wash longer than these CDC minimum recommendations.

When the assembly completes its sixty (60) second cycle it goes dark (to sleep), and waits until another hand is brought close to the IR Collision Avoidance Module to begin the one (1) to sixty (60) second cycle once again.

Afterwards

Test IR Obstacle Avoidance Module

If you have come to this point - congratulations. You should now have a basic understanding of some of the key elements of an IR Obstacle Avoidance Module, and how to use one in your projects.

If you like this Instructable, you may want to read some of my other Instructables.

Also, if you liked this Instructable, please be kind enough to check "Favorited" box at the top of this Instructable. Thank you.

If you have any comments, suggestions, or questions related to this Instructable, please be kind enough to add these to the comments below, if there are any already there.

If you have any thoughts or questions, about related items not covered in this Instructable, or any suggestions for how I could improve this Instructable, I would be pleased to hear from you. You can contact me directly at transiintbox@gmail.com. (Please replace the second 'i' with an 'e' to contact me).