Infrared Sensor with Arduino

Introduction

Infrared (IR) sensors are widely used in electronics and automation projects for object detection, proximity sensing, line tracking, and remote control applications. These sensors work by emitting and detecting infrared radiation, which is invisible to the human eye. When combined with an Arduino, IR sensors enable a wide range of applications, from security systems to robotics.

This article explores the working principles of infrared sensors, how to interface them with an Arduino, coding examples, applications, and troubleshooting common issues.

Understanding Infrared Sensors

Types of IR Sensors

Infrared sensors are categorized based on their functionality:

  • Active IR Sensors: Emit infrared light and detect reflections to determine proximity or motion (e.g., IR proximity sensors).
  • Passive IR Sensors (PIR): Detect infrared radiation emitted by objects, commonly used for motion detection.
  • IR Remote Sensors: Receive signals from IR remote controls, such as those used in televisions.

Working Principle

IR sensors work by emitting infrared light from an IR LED. The reflected light is detected by a photodiode, which converts the light into an electrical signal. This signal is then processed to determine the presence, distance, or motion of an object.

Interfacing an Infrared Sensor with Arduino

Components Required

  • Arduino Board (Uno, Mega, Nano, etc.)
  • IR Sensor Module (IR proximity sensor or PIR sensor)
  • Jumper Wires
  • LED or Buzzer (optional for indication)

Wiring Diagram

For an IR proximity sensor:

  • VCC5V on Arduino
  • GNDGND on Arduino
  • OUTD2 (Digital Pin on Arduino)

Arduino Code for Object Detection

int sensorPin = 2;
int ledPin = 13;

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

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

Arduino Code for IR Remote Control

For IR remote applications, install the IRremote library and use the following code to receive signals:

#include <IRremote.h>

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn();
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume();
  }
}

Applications of Infrared Sensors

1. Object Detection

Used in automatic doors, obstacle avoidance robots, and industrial automation.

2. Motion Sensing

PIR sensors detect motion for security systems, lights, and alarms.

3. Line Following Robots

Used in robotic vehicles to follow a predefined path based on infrared reflectance.

4. IR Remote Control

Enables wireless control of home appliances and electronics.

5. Hand Gesture Recognition

Advanced IR applications detect hand movements for interactive control.

Troubleshooting Common Issues

1. Sensor Not Detecting Objects

  • Ensure correct wiring and power supply.
  • Adjust the sensitivity potentiometer (if available).
  • Use a reflective surface for better detection.

2. False Triggering or Noise

  • Avoid bright sunlight or infrared interference.
  • Use a resistor to stabilize sensor output.

3. IR Remote Not Responding

  • Ensure correct receiver pin and baud rate.
  • Check battery and signal strength of the remote.
Categories: Uncategorized