The infrared obstacle avoidance sensor module (short for avoidance module) returns a signal when it detects an object in range. The sensor can detect a distance from 2 up to 40 cm. The module operates at 3.5 to 5 volts, and the working current is 20mA. There are 4 pins on this module, namely: the GND, "+", OUT and EN pins. The GND pin should be connected to the GND pin of Arduino, The "+" (VCC) pin should be connected to 5V pin of Arduino, the OUT (signal) pin should be connected to any digital pin of Arduino, and the EN (Enable) pin should be connected to any digital pin of Arduino.
The application of this module is typically used mostly to a wheeled robot, where it avoid obstacles with the use of this sensor module. The sensor detects the distance of an object based on the adjustable distance settings. The module has an infrared transmitter and receiver on board. The transmitter LED emits a certain frequency of infrared, in which the receiver LED will detect the signal from emitter and will trigger the digital on/off "signal" pin when a specific threshold "distance" has been detected. The module has two potentiometers. The potentiometer with the S02 label is for adjustment of trasmitter IR frequency, and the potentiometer with the E01 label is for adjustment of the distance from the object at which the sensor detects it. The function of this module is almost similar with the line tracking module functionality.
In the given code below, when the obstacle sensor detects signal, the LED flashes.
Code example for Avoidance Sensor Module
Upload the code to Arduino. Once uploaded, you may test the module by putting closer to a certain object (like wall, desk, etc.). Observe if the LED will change the display.
The line tracking sensor module (or sometimes called the hunt sensor module or line tracing sensor module ) detects if a light reflecting or absorbing area is in front of it. The sensor has a pair of infrared transmitter and receiver. The transmitter emits a certain frequency of infrared ray. If the light is reflecting, the module generates a LOW value (from 0 to 499 values). If the light is not reflecting back to the IR Led receiver, the module generates a HIGH value (from 500 up to 1023 values). The usual color to be used here is black and white color. Use black color (absorbing) for producing HIGH value by the line tracking sensor module, and use white color (reflecting) for producing LOW value by the module. The module has the potentiometer where it can be adjusted to change the distance settings.
The GND pin of the module should be connected to the GND pin of Arduino, the VCC should be connected to 5V of Arduino, and the OUT pin (or signal pin) should be connected to analog pin or digital pin.
Let us see the code example below using the digital pin in Arduino. In the code, if the light of the line tracking sensor did not return, or the light has been absorbed by the object in front of it, the module will produce a HIGH value. If the light from the sensor reflects because of the bright color of the object in front of it, it will produce a LOW value.
Line Tracking Sensor code example using digital pin
Let us see the code example below using the analog pin in Arduino. In the code, if the light of the line tracking sensor did not return, or the light has been absorbed by the object in front of it, using the analogRead() function, the module will produce a big value ranging from 500 up to 1023. If the light from the sensor reflects because of the bright color of the object in front of it, it will produce a small value ranging from 0 to 499.
Line Tracking Sensor code example - Analog pin
The line tracking sensor is typically used for movable robots or cars for tracking a specific line drawn on the floor using the black color.