IR Sensors

Complete guide to infrared sensors for proximity, reflectance, and object detection

IR Sensor Module

IR Sensor Overview

IR sensors detect infrared light, typically used for proximity sensing, object detection, and reflectance measurement in the 850nm-950nm wavelength range.

  • Non-contact Detection: Detects objects without physical contact
  • Fast Response: Typically responds in microseconds
  • Adjustable Sensitivity: Most modules have potentiometer for threshold adjustment
  • Digital/Analog Output: Provides both digital (on/off) and analog (intensity) outputs
  • Wavelength: Typically 850nm-950nm infrared light
  • Low Cost: Inexpensive sensing solution
  • Simple Interface: Easy to connect to microcontrollers
  • Works in Darkness: Doesn't require visible light
  • Reliable: Not affected by most ambient light
  • Versatile: Many applications from line following to object detection
  • Obstacle Detection: Robotics and automation
  • Line Following: Robot navigation
  • Proximity Sensing: Object presence detection
  • Reflectance Measurement: Surface characterization
  • Object Counting: Industrial applications

IR Sensor Types

Standard IR Sensor Module

Standard IR Sensor Module

  • IR LED transmitter and photodiode receiver
  • 3-pin interface (VCC, GND, OUT)
  • Adjustable detection distance (2cm-30cm)
  • Digital (HIGH/LOW) output
  • Onboard potentiometer for sensitivity
Common Low Cost
Reflective IR Sensor

Reflective IR Sensor

  • Detects reflected IR light
  • Used for line following and surface detection
  • Analog output for reflectance measurement
  • Shorter range (typically <5cm)
  • More sensitive to surface properties
Reflective Analog
IR Break Beam Sensor

IR Break Beam Sensor

  • Separate transmitter and receiver units
  • Detects objects breaking the beam
  • Longer range (up to several meters)
  • Higher reliability for object counting
  • More expensive than reflective sensors
Through-beam Precise

Comparison of IR Sensor Types

Parameter Standard Module Reflective Break Beam
Detection Method Reflective (object reflects IR back) Reflective (surface reflectance) Beam interruption
Typical Range 2cm-30cm 0.5cm-5cm 5cm-5m
Output Type Digital Analog/Digital Digital
Accuracy Medium High (for surface detection) Very High
Price Range $0.50-$2 $1-$5 $5-$20

How IR Sensors Work

IR Sensor Working Principle

Working Principle

  1. IR Emission: IR LED emits infrared light (typically 850nm-950nm)
  2. Reflection/Interruption: Light either reflects off object or is interrupted
  3. Detection: Photodiode or phototransistor detects IR light
  4. Signal Processing: Onboard circuit processes the signal
  5. Output: Provides digital or analog output based on detection

Key Components

  • IR LED: Emits infrared light (invisible to human eye)
  • Photodiode/Phototransistor: Detects reflected IR light
  • Comparator Circuit: Converts analog signal to digital output
  • Potentiometer: Adjusts detection threshold
  • Output Indicator LED: Visual detection indicator

Typical Response Characteristics

IR Sensor Response Curve

Detection Optimization

  • Positioning: Mount sensor perpendicular to target surface
  • Sensitivity Adjustment: Set threshold for reliable detection
  • Surface Considerations: Different materials reflect IR differently
  • Environmental Factors: Account for ambient IR sources
  • Multiple Sensors: Combine for better coverage

Pinout and Wiring

IR Sensor Pinout

Standard 3-Pin Module

  1. VCC (3.3V-5V): Power supply
  2. GND: Ground connection
  3. OUT: Digital output (LOW when object detected)
IR Sensor Circuit

Module Components

  • IR LED: Infrared light emitter
  • Photodiode: IR light detector
  • LM393 Comparator: For digital output
  • Potentiometer: Adjusts detection threshold
  • Status LED: Visual detection indicator

Typical Wiring Diagram

IR Sensor Wiring Diagram

Important Wiring Notes

IR Sensor Code Examples

Basic Arduino Example

// Basic IR Sensor Example
#define IR_SENSOR_PIN 2

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

void loop() {
    int sensorState = digitalRead(IR_SENSOR_PIN);
    
    if(sensorState == LOW) {
        Serial.println("Object detected!");
    } else {
        Serial.println("No object detected");
    }
    delay(100);
}

Analog IR Sensor Example

// Analog IR Sensor Example
#define IR_ANALOG_PIN A0

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

void loop() {
    int sensorValue = analogRead(IR_ANALOG_PIN);
    Serial.print("IR Reflectance: ");
    Serial.println(sensorValue);
    
    // Adjust threshold based on your sensor and surface
    if(sensorValue > 500) {
        Serial.println("Light surface detected");
    } else {
        Serial.println("Dark surface detected");
    }
    delay(200);
}

Object Counter Example

// IR Sensor Object Counter
#define IR_PIN 2

int objectCount = 0;
bool lastState = HIGH;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;

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

void loop() {
    int reading = digitalRead(IR_PIN);
    
    // Debounce the input
    if(reading != lastState) {
        lastDebounceTime = millis();
    }
    
    if((millis() - lastDebounceTime) > debounceDelay) {
        if(reading == LOW && lastState == HIGH) {
            objectCount++;
            Serial.print("Object count: ");
            Serial.println(objectCount);
        }
    }
    
    lastState = reading;
}

Project Ideas

Line Following Robot

Use multiple IR sensors to follow a black line on white surface.

IR Sensors Motors Arduino

Object Counter

Count objects passing on a conveyor belt using IR break beam.

IR Break Beam LCD Display Counter

Proximity Alarm

Alert when objects get too close to sensitive equipment.

IR Sensor Buzzer LED

Smart Trash Can

Automatically open lid when hand is detected.

IR Sensor Servo Battery

Surface Reflectance Meter

Measure and compare different material surfaces.

Analog IR OLED Data Log

IR Remote Decoder

Use IR receiver to decode TV remote signals.

IR Receiver Arduino Serial Monitor

Advanced Project: Gesture Control System

// Components needed:
- 5x IR sensors (array)
- Arduino/ESP32
- Servo motors
- OLED display
- Power supply

// Features:
1. Detect hand gestures (left, right, up, down)
2. Control devices based on gestures
3. Visual feedback on OLED
4. Calibration mode
5. Multiple control modes

// Implementation Tips:
- Arrange IR sensors in cross pattern
- Implement gesture recognition algorithm
- Add debounce for reliable detection
- Create calibration routine
- Add visual feedback for user
- Consider wireless control option

Best Practices & Tips

Calibration

  • Adjust potentiometer for desired detection range
  • Test with actual target objects
  • Account for surface reflectivity
  • Document settings for reproducibility
  • Re-calibrate if environment changes

Installation

  • Mount at proper height/distance
  • Ensure clear path for IR beam
  • Protect from dust and moisture
  • Avoid direct sunlight interference
  • Consider multiple sensors for reliability

Signal Processing

  • Use debouncing for digital signals
  • Implement moving average for analog
  • Set appropriate detection thresholds
  • Add hysteresis to prevent flickering
  • Log data for performance analysis

Common Mistakes to Avoid

Mistake Consequence Solution
Improper calibration False detections or missed objects Calibrate in actual operating environment
Ignoring ambient light Unreliable operation Shield sensor or account in software
No signal processing Noisy, unstable readings Implement filtering and debouncing
Wrong sensor type Poor performance Choose sensor appropriate for application
No maintenance Degraded performance over time Regularly clean and check calibration