IR Sensor with Arduino

Introduction

Infrared (IR) sensors are widely used in automation, robotics, security systems, and remote controls. These sensors detect objects, measure distance, and even communicate through infrared signals. When integrated with an Arduino board, IR sensors can be used for various applications, including obstacle detection, line-following robots, and motion sensing.

This article explores IR sensors, their working principles, interfacing with Arduino, coding examples, applications, and troubleshooting common issues.

Understanding IR Sensors

An IR sensor consists of an IR LED (transmitter) and a photodiode (receiver). The IR LED emits infrared light, which reflects off an object and is detected by the photodiode. Based on the intensity of the reflected light, the sensor determines the presence or distance of an object.

Types of IR Sensors

  1. Active IR Sensors: Emit and detect infrared light to sense objects or measure distance.
  2. Passive IR Sensors (PIR): Detect infrared radiation emitted by living beings, commonly used in motion detection.
  3. Reflective IR Sensors: Measure the reflection of IR light from surfaces, often used in line-following robots.

Components Required

  • Arduino Board (Uno, Mega, Nano, etc.)
  • IR Sensor Module (e.g., IR obstacle avoidance sensor)
  • Jumper Wires
  • Buzzer/LED (Optional for alert system)

Interfacing IR Sensor with Arduino

Wiring Diagram

For an IR obstacle sensor:

  • VCC5V on Arduino
  • GNDGND on Arduino
  • OUTDigital Pin (D2, D3, etc.)

Arduino Code for Obstacle Detection

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

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

void loop() {
    sensorState = digitalRead(sensorPin);
    if (sensorState == LOW) {
        Serial.println("Obstacle Detected!");
        digitalWrite(ledPin, HIGH);
    } else {
        digitalWrite(ledPin, LOW);
    }
    delay(100);
}

Applications of IR Sensors

1. Obstacle Detection

IR sensors are commonly used in autonomous robots and security systems to detect nearby objects.

2. Line Following Robots

Reflective IR sensors help robots follow a predefined path by detecting black and white surfaces.

3. Motion Detection

PIR sensors detect human motion and are used in security and automation systems.

4. Remote Control Systems

IR sensors are used in TV remotes and other devices for wireless communication.

5. Industrial Automation

Used in conveyor systems and machine vision for detecting objects and obstacles.

Troubleshooting Common Issues

1. False Detections

  • Avoid bright light interference, which can affect sensor readings.
  • Use proper shielding to minimize noise.

2. No Detection

  • Ensure correct wiring and power supply.
  • Test with different distances to verify sensor functionality.

3. Unstable Readings

  • Adjust sensor sensitivity using the onboard potentiometer.
  • Ensure a stable power supply to the Arduino and sensor.
Categories: Uncategorized