Arduino IR Beam Break Detection Project
Overview
This project creates an invisible IR beam that triggers an LED when broken. Perfect for security systems, people counters, or automatic door sensors.
Components Needed
- Arduino Uno (or compatible)
- IR LED (940nm recommended)
- IR photodiode or phototransistor (e.g., TEPT4400)
- Regular LED (any color for indicator)
- 220Ω resistor (for indicator LED)
- 100Ω resistor (for IR LED)
- 10kΩ resistor (pull-up for IR receiver)
- Breadboard and jumper wires
- Optional: Buzzer for audio alert
Circuit Wiring
IR Transmitter (IR LED):
- IR LED anode (+) → 100Ω resistor → Arduino pin 3
- IR LED cathode (-) → Arduino GND
IR Receiver (Photodiode):
- Photodiode cathode (-) → Arduino pin A0
- Photodiode anode (+) → Arduino 5V
- 10kΩ resistor between A0 and GND (pull-down)
Indicator LED:
- LED anode (+) → 220Ω resistor → Arduino pin 13
- LED cathode (-) → Arduino GND
Optional Buzzer:
- Buzzer (+) → Arduino pin 12
- Buzzer (-) → Arduino GND
Arduino Code
// IR Beam Break Detection System
// When IR beam is broken, LED lights up
const int irLedPin = 3; // IR LED transmitter
const int irReceiverPin = A0; // IR photodiode receiver
const int indicatorLed = 13; // Visual indicator LED
const int buzzerPin = 12; // Optional buzzer
int beamThreshold = 512; // Adjust based on your setup
int baselineReading = 0; // Baseline IR reading
bool beamBroken = false; // Current beam state
unsigned long lastTrigger = 0; // For debouncing
const unsigned long debounceDelay = 100; // Debounce time in ms
void setup() {
// Initialize pins
pinMode(irLedPin, OUTPUT);
pinMode(indicatorLed, OUTPUT);
pinMode(buzzerPin, OUTPUT);
// Start serial communication for debugging
Serial.begin(9600);
// Turn on IR LED
digitalWrite(irLedPin, HIGH);
// Delay to let sensor stabilize
delay(100);
// Get baseline reading when beam is unobstructed
calibrateSensor();
Serial.println("IR Beam Break System Ready!");
Serial.print("Baseline reading: ");
Serial.println(baselineReading);
Serial.print("Trigger threshold: ");
Serial.println(beamThreshold);
}
void loop() {
// Read current IR sensor value
int currentReading = analogRead(irReceiverPin);
// Check if beam is broken (significant drop in IR reading)
if (currentReading < beamThreshold && !beamBroken) {
// Debounce - make sure it's not just noise
if (millis() - lastTrigger > debounceDelay) {
beamBroken = true;
triggerAlarm();
lastTrigger = millis();
Serial.println("BEAM BROKEN!");
Serial.print("Reading: ");
Serial.println(currentReading);
}
}
// Check if beam is restored
else if (currentReading >= beamThreshold && beamBroken) {
if (millis() - lastTrigger > debounceDelay) {
beamBroken = false;
clearAlarm();
lastTrigger = millis();
Serial.println("Beam restored");
Serial.print("Reading: ");
Serial.println(currentReading);
}
}
// Optional: Print readings for debugging
// Serial.println(currentReading);
delay(50); // Small delay for stability
}
void calibrateSensor() {
// Take several readings to establish baseline
long total = 0;
int numReadings = 20;
Serial.println("Calibrating sensor...");
for (int i = 0; i < numReadings; i++) {
total += analogRead(irReceiverPin);
delay(50);
}
baselineReading = total / numReadings;
// Set threshold as 80% of baseline reading
beamThreshold = baselineReading * 0.8;
// Make sure threshold is reasonable
if (beamThreshold < 100) {
beamThreshold = 100;
}
}
void triggerAlarm() {
// Turn on indicator LED
digitalWrite(indicatorLed, HIGH);
// Optional: Sound buzzer
tone(buzzerPin, 1000, 200); // 1kHz tone for 200ms
}
void clearAlarm() {
// Turn off indicator LED
digitalWrite(indicatorLed, LOW);
// Stop buzzer
noTone(buzzerPin);
}
// Advanced version with multiple trigger modes
void advancedTrigger() {
// Flash LED pattern
for (int i = 0; i < 3; i++) {
digitalWrite(indicatorLed, HIGH);
delay(100);
digitalWrite(indicatorLed, LOW);
delay(100);
}
// Different tones for different detection patterns
tone(buzzerPin, 800, 100);
delay(150);
tone(buzzerPin, 1200, 100);
}
How It Works
- IR Transmission: The IR LED continuously emits invisible infrared light
- IR Reception: The photodiode receives the IR light and converts it to an electrical signal
- Baseline Calibration: On startup, the system measures the normal IR level when the beam is unobstructed
- Detection: When something breaks the beam, the IR signal drops significantly
- Triggering: When the signal drops below the threshold, the LED lights up and optional buzzer sounds
- Debouncing: The system includes delays to prevent false triggers from noise
Setup Tips
- Alignment: Carefully align the IR LED and photodiode for maximum signal
- Distance: Start with components 1-3 feet apart, can extend to 10+ feet
- Environment: Avoid direct sunlight or strong IR sources that can interfere
- Sensitivity: Adjust
beamThresholdvalue if too sensitive or not sensitive enough - Testing: Use serial monitor to see real-time sensor readings
Troubleshooting
LED always on/off: Check alignment and adjust threshold value False triggers: Increase debounce delay or move away from IR interference No detection: Verify wiring and check if IR LED is working (use phone camera to see it) Inconsistent readings: Add capacitor (100µF) across power rails for stability
Enhancements
- Add multiple beam pairs for larger coverage
- Use interrupts for faster response
- Add wireless communication (ESP32/WiFi)
- Create web interface for remote monitoring
- Add time stamping and logging
- Implement different alert patterns for different sensors
Applications
- Security perimeter detection
- Automatic door sensors
- People/vehicle counters
- Pet door automation
- Garage door safety beam
- Industrial automation sensors