IR Obstacle Avoidance Sensor Module

../_images/09_IR_obstacle_module.png

Introduction

An IR Obstacle Sensor works in accordance with the infrared reflection principle to detect obstacles. When there is no object, the infrared receiver receives no signals; when there is an object ahead which blocks and reflects the infrared light, the infrared receiver will receive signals.

Principle

An obstacle avoidance sensor mainly consists of an infrared transmitter, an infrared receiver and a potentiometer. According to the reflecting character of an object, if there is no obstacle, the emitted infrared ray will weaken with the distance it spreads and finally disappear. If there is an obstacle, when the infrared ray encounters it, the ray will be reflected back to the infrared receiver. Then the infrared receiver detects this signal and confirms an obstacle in front. The detection range can be adjusted by the built-in potentiometer.

../_images/09_IR_obstacle_module_1.png

Usage

Hardware components

  • Arduino Uno R4 or R3 board * 1

  • IR Obstacle Avoidance Sensor Module * 1

  • Jumper Wires

Circuit Assembly

../_images/09_IR_obstacle_module_circuit.png

Code



Code explanation

  1. Define pin number for sensor connection:

    const int sensorPin = 2;
    

    Connect the sensor’s output pin to Arduino pin 2.

  2. Setup serial communication and define sensor pin as input:

    void setup() {
      pinMode(sensorPin, INPUT);
      Serial.begin(9600);
    }
    

    Initialize serial communication at 9600 baud rate to print to serial monitor. Set sensor pin as input to read input signal.

  3. Read sensor value and print to serial monitor:

    void loop() {
      Serial.println(digitalRead(sensorPin));
      delay(50);
    }
    

    Continuously read digital value from sensor pin using digitalRead() and print value to serial monitor using Serial.println(). Add 50ms delay between prints for better viewing.

Note

If the sensor is not working properly, adjust the IR transmitter and receiver to make them parallel. Additionally, you can adjust the detection range using the built-in potentiometer.

Additional Ideas

  • Add buzzer that beeps when obstacle is detected

More Projects