Build an IR Obstacle Detector
An IR obstacle detector uses invisible infrared light to detect nearby objects without physical contact. This simple project introduces infrared LEDs, phototransistors, transistor switching and sensor circuits.
Project Overview
An infrared obstacle detector is a simple electronic sensor that can detect an object when it comes close to the sensor.
The circuit works by transmitting infrared light toward the area being monitored. When an object enters the detection zone, some of the infrared light is reflected back toward the receiver.
The receiver detects the reflected infrared energy and produces an electrical signal. That signal can then be used to switch an LED, buzzer, transistor, relay or microcontroller input.
How Infrared Detection Works
The human eye cannot normally see infrared light, but infrared LEDs can produce it efficiently.
The basic system contains two important parts:
- An infrared LED that transmits infrared light.
- A phototransistor that detects reflected infrared light.
When there is no nearby object, relatively little infrared light reaches the receiver.
When an object enters the detection area, infrared light is reflected back toward the phototransistor.
IR LED
│
│ Infrared light
▼
\
\ Object
\ ███
\ ███
\ ███
\ /
V
Phototransistor
The resulting change in the receiver current can be converted into a useful switching signal.
Main Components
- Infrared LED
- Phototransistor
- LED indicator
- Resistors
- NPN transistor
- DC power supply
- Buzzer or other output device (optional)
A comparator such as the LM358 or LM393 can also be added when a clean digital switching signal is required.
Infrared Transmitter
The infrared LED is the transmitter in the sensor.
Like an ordinary LED, it requires a current-limiting resistor.
+V │ R │ IR LED │ GND
The resistor limits the current through the LED and prevents excessive current from damaging it.
The resistor value should be selected according to the supply voltage and the forward voltage and desired operating current of the particular infrared LED.
Phototransistor Receiver
A phototransistor converts incident infrared light into a change in collector current.
When more infrared light reaches the device, its conduction normally increases.
This changing current can be converted into a voltage using a resistor.
+V │ R │ ├──── Sensor Output │ Phototransistor │ GND
The exact polarity and circuit arrangement depend on the particular phototransistor being used.
Basic Detection Circuit
A simple detector can use the phototransistor to control an NPN transistor.
+V
│
LED
│
R
│
C
NPN
E
│
GND
Phototransistor
│
└──► Base of NPN
When the reflected infrared signal changes the phototransistor current, the NPN transistor can switch the indicator circuit.
For a more stable detector, a comparator can be used instead of relying only on the transistor switching threshold.
Using a Comparator
A comparator allows the sensor voltage to be compared with an adjustable reference voltage.
For example, an LM393 can compare the sensor voltage with a reference set using a potentiometer.
Phototransistor
│
▼
Sensor Voltage
│
├────────► Comparator
│ │
Reference ──────────►│
│
▼
Output
The potentiometer can be used to adjust the detection threshold.
Adjusting Detection Distance
The detection distance depends on several factors.
- Infrared LED power
- Receiver sensitivity
- Object reflectivity
- Distance between transmitter and receiver
- Sensor geometry
- Ambient infrared light
- Detection threshold
A white or light-colored object generally reflects more infrared light than a dark object.
Consequently, the same detector may respond at different distances depending on the surface of the object.
Reducing False Detection
Ambient light can interfere with infrared sensors.
Sunlight and some artificial light sources contain infrared energy that can reach the receiver.
Several techniques can improve reliability:
- Place the transmitter and receiver close together.
- Use physical shielding around the receiver.
- Use a suitable detection threshold.
- Modulate the infrared transmitter.
- Use a receiver designed for modulated infrared signals.
Modulated Infrared
More advanced infrared sensors do not simply turn the IR LED on continuously.
Instead, the transmitter can be driven with a modulated signal. The receiver then detects the expected modulation rather than simply responding to any infrared light.
This technique can significantly improve immunity to ambient light.
Indicator LED
An ordinary visible LED can be used to indicate when an object has been detected.
The LED should always have an appropriate current-limiting resistor.
+V │ R │ LED │ Transistor │ GND
The LED can be replaced or supplemented with a buzzer, relay or logic signal.
Adding a Buzzer
A buzzer can provide an audible indication when an obstacle is detected.
For a larger buzzer, the sensor circuit should drive a transistor rather than attempting to supply the buzzer directly from the sensor output.
Using a Relay
A relay can allow the detector to control another circuit.
Possible applications include:
- Automatic switching
- Object counters
- Door sensors
- Small automation systems
- Alarm systems
A transistor driver and flyback diode are normally required when controlling a relay coil.
Using the Sensor With a Microcontroller
The detector output can also be connected to a microcontroller such as an Arduino or ESP32.
The microcontroller can then perform additional functions such as:
- Counting objects
- Measuring detection events
- Controlling motors
- Displaying sensor status
- Activating alarms
- Building robotic systems
Common Applications
- Robot obstacle detection
- Object counters
- Automatic doors
- Alarm systems
- Industrial sensing
- Line-following robots
- Automatic switching
- Presence detection
- Simple automation projects
Testing the Sensor
After assembling the circuit, place a light-colored object in front of the sensor.
Move the object slowly toward and away from the sensor and observe the indicator output.
If the detection distance is too short, adjust the sensor geometry, LED current or detection threshold.
If the circuit triggers when no object is present, reduce the sensor sensitivity or improve shielding from ambient light.
Troubleshooting
No Detection
- Check the infrared LED polarity.
- Check the phototransistor orientation.
- Verify the supply voltage.
- Check the current-limiting resistor.
- Verify the transistor connections.
- Check the comparator reference voltage if used.
Detection Is Too Sensitive
- Reduce the receiver sensitivity.
- Adjust the comparator threshold.
- Shield the receiver from ambient light.
- Reduce the transmitter intensity if necessary.
Detection Is Unstable
- Check the power supply.
- Add appropriate supply decoupling.
- Reduce ambient-light interference.
- Improve the physical alignment of the transmitter and receiver.
- Use modulated infrared for demanding applications.
Safety Notes
- Use a low-voltage DC power supply.
- Always use a current-limiting resistor with the IR LED.
- Do not connect the circuit directly to mains voltage.
- Use appropriate protection when driving relays or inductive loads.
- Do not stare directly into high-power infrared sources.
Skills Learned
- Infrared sensing.
- Phototransistor operation.
- LED current limiting.
- Transistor switching.
- Comparator circuits.
- Sensor threshold adjustment.
- Basic electronic troubleshooting.
Key Points
- An IR LED transmits infrared light.
- A phototransistor detects reflected infrared light.
- An object can be detected without physical contact.
- A transistor or comparator can convert the sensor signal into a switching output.
- Detection distance depends strongly on object reflectivity and sensor geometry.
- Ambient infrared light can cause false detection.
- Modulated infrared can improve reliability.