Infrared Line Detector

From Bespoke Robot Society
Jump to navigation Jump to search
Infrared Line Detector Module
Function Line Following Sensor
Type Sensor Module
Operating Voltage 3.3V – 5V
Interface Digital output (active LOW)
Typical Cost $0.50 USD (bulk) / $0.75 (single)

The Infrared Line Detector Module (also called "Infrared Obstacle Avoidance Sensor" or "IR Reflectance Sensor") is a simple digital sensor used for line-following robots. It detects the contrast between light and dark surfaces by measuring reflected infrared light.

Overview

This ubiquitous sensor module consists of an infrared LED and an infrared phototransistor positioned side-by-side. The LED emits IR light, which reflects off the surface below. The phototransistor detects the reflected light, and an onboard comparator (typically LM393) converts the analog signal to a digital output.

The module is designed to detect:

  • Black lines on white surfaces (typical for line-following)
  • White lines on black surfaces (inverted mode)
  • Edges and drop-offs (cliff detection)
  • Proximity to obstacles (though range is limited)

Key Features

  • Simple Digital Output: HIGH or LOW based on detected surface
  • Adjustable Sensitivity: Onboard potentiometer to set detection threshold
  • Active LOW Output: Output goes LOW when dark surface detected
  • Low Cost: Often sold in packs of 20 for $10 USD
  • Low Power: Typically <20mA at 5V
  • Compact Size: ~30mm × 15mm typical module size

Module Components

  1. IR LED: Emits infrared light (typically 940nm wavelength)
  2. IR Phototransistor: Detects reflected IR light
  3. LM393 Comparator: Converts analog signal to digital
  4. Potentiometer: Adjusts detection threshold
  5. Power LED: Indicates module is powered
  6. Detection LED: Lights when dark surface detected

Pin Configuration

Typical 3-pin module:

  • VCC: 3.3V to 5V power supply
  • GND: Ground
  • OUT (or DO): Digital output (active LOW)

Some modules also provide:

  • AO: Analog output (raw sensor voltage, if available)

How It Works

  1. The IR LED constantly emits infrared light downward
  2. Light reflects off the surface below
  3. Light surfaces (white/reflective) reflect more IR light → phototransistor conducts more → output HIGH
  4. Dark surfaces (black/absorptive) reflect less IR light → phototransistor conducts less → output LOW
  5. The potentiometer adjusts the threshold between "light" and "dark"

Adjustment Procedure

  1. Power the module
  2. Place it over a white surface
  3. Adjust the potentiometer until the detection LED turns OFF
  4. Move it over a black line
  5. Verify the detection LED turns ON and output goes LOW
  6. Fine-tune potentiometer for consistent detection at desired height

Typical detection height: 3mm to 15mm above the surface.

Usage in BRS Projects

SimpleBot uses two infrared line detector modules for line following:

  • Mounted on sensor sleds: Adjustable position under the chassis
  • Two-sensor configuration: One on each side of the line
  • Detection pattern:
    • Both sensors on white → drive straight
    • Left sensor on line → turn right
    • Right sensor on line → turn left
    • Both sensors on line → stop or special behavior

The SimpleBot chassis provides adjustable sensor mounts to fine-tune sensor spacing and height above the ground.

Wiring Example

Sensor Module → Microcontroller:
- VCC → 3.3V or 5V
- GND → GND
- OUT → GPIO pin (with internal pull-up enabled)

Since the output is active LOW, enable the microcontroller's internal pull-up resistor or add an external 10kΩ pull-up.

Code Example (MicroPython)

from machine import Pin

# Configure line sensors (active LOW)
left_sensor = Pin(10, Pin.IN, Pin.PULL_UP)
right_sensor = Pin(11, Pin.IN, Pin.PULL_UP)

def read_line_sensors():
    """Read both line sensors"""
    left_on_line = not left_sensor.value()   # Invert because active LOW
    right_on_line = not right_sensor.value()

    if not left_on_line and not right_on_line:
        return "STRAIGHT"  # Both on white
    elif left_on_line and not right_on_line:
        return "TURN_RIGHT"  # Left sensor on line
    elif right_on_line and not left_on_line:
        return "TURN_LEFT"  # Right sensor on line
    else:
        return "BOTH_ON_LINE"  # Both on line or at intersection

# Main loop
while True:
    state = read_line_sensors()
    print(state)
    # Add motor control logic here

Limitations

  • Detection Range: Only works at close range (3-15mm typically)
  • Ambient Light Sensitivity: May be affected by bright sunlight or other IR sources
  • Surface Dependency: Works best on matte surfaces; glossy or textured surfaces can cause issues
  • Binary Output: Digital modules don't provide position information within the line

Alternatives

  • Analog Reflectance Sensors: Provide continuous position data (e.g., Pololu QTR sensor arrays)
  • Color Sensors: Detect colored lines or surfaces
  • Camera-Based Vision: For complex line patterns or multi-colored lines
  • Custom Sensor Array: Multiple sensors for better line tracking

Multi-Sensor Arrays

For more sophisticated line following, use multiple sensors (3-8 typical) arranged in a row:

  • Better line tracking through curves
  • Position calculation within the line
  • Intersection and branching detection
  • Lost line recovery

Common Issues

  • No Detection: Sensor too far from surface or potentiometer needs adjustment
  • Always Detecting: Sensor too close or potentiometer too sensitive
  • Inconsistent Detection: Ambient IR interference or uneven surface
  • Slow Response: Normal for these modules; they're not designed for high-speed line following

See Also

  • SimpleBot - Uses two IR line detectors for line following
  • Line Following - Algorithms and techniques for line-following robots
  • Optical Odometry - Different use of optical sensors for distance measurement