Innovative Height Detector for Tunnel Safety
Designing an Arduino-Based Infrared Detection Circuit for Over-Height Vehicles
Highlights
- Accurate Detection: Uses an IR sensor setup to detect when a vehicle blocks the beam.
- Visual Alerts: Changes LED indicators from green to red and displays a warning on an LCD.
- Customizable Setup: Flexible Arduino circuit design and code for adapting to various tunnel environments.
Overview
Setting up a height detection system at a tunnel entrance is essential for preventing over-height vehicles from entering. This project leverages an Arduino Uno, an infrared (IR) sensor module, dual-color LED indicators (green and red), and an LCD display. When a vehicle that exceeds a preset height threshold interrupts the IR beam, the system alerts by turning the LED indicator red and displaying a "STOP" message on the LCD.
The following guide outlines the circuit design, provides a detailed schematic of component connections, and includes a comprehensive Arduino code snippet. It also describes how to fine-tune sensor sensitivity and ensure a robust setup in various lighting conditions.
Components and Circuit Design
Required Components
- Arduino Uno (or similar variant)
- IR Sensor Module (includes both an IR transmitter and receiver)
- 16x2 LCD Display (compatible with the LiquidCrystal library)
- Green and Red LEDs
- Resistors (typically 220Ω for LED current limiting)
- Breadboard and Jumper Wires
- Optional: Piezo Buzzer for audio alerts
- Potentiometer (for adjusting LCD contrast if necessary)
- Power Supply (regulated 5V supply from Arduino or external source)
Circuit Schematic
Below is a table summarizing the connections and components for your circuit:
| Component | Connection | Notes |
|---|---|---|
| IR Sensor - VCC | Arduino 5V | Power for sensor |
| IR Sensor - GND | Arduino GND | Common ground |
| IR Sensor - OUT | Arduino Digital Pin 2 | Signal input |
| Green LED (Positive) | Arduino Digital Pin 13 | With a series 220Ω resistor |
| Red LED (Positive) | Arduino Digital Pin 14 (or Pin 10/9 as design flexibility) | With a series 220Ω resistor |
| LCD - RS | Arduino Digital Pin 7 | LCD register select |
| LCD - E | Arduino Digital Pin 8 | LCD enable pin |
| LCD - D4, D5, D6, D7 | Arduino Digital Pins 9, 10, 11, 12 | Data lines; may vary based on your wiring |
| LCD - VCC and GND | Arduino 5V and GND | Ensure correct contrast wiring via potentiometer if needed |
| Optional - Buzzer | Digital Pin 10 (or designated output pin) / GND | Audio alert on detection |
Assembling the Circuit
Follow these step-by-step instructions to assemble your height detection system:
Step 1: IR Sensor Setup
Mount the IR sensor at the entrance so that the transmitter and receiver beam covers the defined height clearance. Connect the sensor's VCC pin to the Arduino 5V pin, the GND pin to the Arduino GND, and the OUT pin to digital pin 2.
Step 2: LED Indicators
Connect the anode (longer leg) of the green LED to digital pin 13 via a 220Ω resistor and the cathode to GND. Similarly, connect the anode of the red LED to another digital output (for example, pin 14 or 10/9 in alternative configurations) with a current-limiting 220Ω resistor, and the cathode to GND.
Step 3: LCD Display Connection
Wire the LCD to the Arduino following these guidelines: connect RS, E, D4, D5, D6, and D7 pins to the corresponding Arduino digital pins as summarized in the table. Be sure to power the LCD using the Arduino's 5V and GND pins. Use a potentiometer for contrast adjustment if your LCD module requires it.
Step 4: Optional Audio Alert
If you choose to include a buzzer, connect its positive lead to a free digital pin (such as pin 10) and its negative lead to GND. The buzzer can serve as an additional alert mechanism by sounding when an over-height vehicle is detected.
Arduino Code Implementation
The following Arduino code combines all functionalities, including sensor reading, LED indicator control, and LCD display updates. Adapt the pin numbers if your wiring differs from the example.
// Include the LiquidCrystal library for LCD interfacing
#include <LiquidCrystal.h>
// ----- Define LCD Pins -----
// Adjust these pins based on your wiring
const int rs = 7;
const int en = 8;
const int d4 = 9;
const int d5 = 10;
const int d6 = 11;
const int d7 = 12;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// ----- Define Sensor and LED Pins -----
const int irSensorPin = 2; // IR sensor output connected here
const int greenLedPin = 13; // Green LED indicating safe height
const int redLedPin = 14; // Red LED indicating over-height
// Optional buzzer pin
const int buzzerPin = 10;
void setup() {
// Begin serial communication at 9600 baud
Serial.begin(9600);
// Initialize LCD: set dimensions (16x2 display)
lcd.begin(16, 2);
lcd.print("Height Detector");
// Configure pin modes
pinMode(irSensorPin, INPUT);
pinMode(greenLedPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
pinMode(buzzerPin, OUTPUT); // for optional buzzer
// Initial LED setup: safe to pass (green on)
digitalWrite(greenLedPin, HIGH);
digitalWrite(redLedPin, LOW);
digitalWrite(buzzerPin, LOW);
// Wait briefly before beginning loop operations
delay(2000);
lcd.clear();
lcd.print("System Ready");
delay(1000);
}
void loop() {
// Read the state of the IR sensor
int sensorState = digitalRead(irSensorPin);
// Check if the IR beam is obstructed
if(sensorState == LOW) {
// Over-height vehicle detected: turn on red LED, turn off green LED
digitalWrite(greenLedPin, LOW);
digitalWrite(redLedPin, HIGH);
// Optional: sound buzzer for additional alert
tone(buzzerPin, 1000); // 1000 Hz tone
// Update LCD message
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("STOP!");
lcd.setCursor(0, 1);
lcd.print("TOO HIGH");
// Debugging output
Serial.println("Vehicle detected: height exceeds limit.");
} else {
// Path is clear: turn on green LED, turn off red LED
digitalWrite(greenLedPin, HIGH);
digitalWrite(redLedPin, LOW);
noTone(buzzerPin); // Stop buzzer if running
// Update LCD message for safe entry
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Safe to Enter");
// Debugging output
Serial.println("Clear path: vehicle height is acceptable.");
}
// Optional: Use a delay for stability and noise reduction in readings
delay(200);
}
Understanding the Code
Key Functionalities
IR Sensor Reading: The digital input from pin 2 monitors the IR sensor state. When a vehicle interrupts the IR beam (often resulting in a LOW signal), the system determines that the vehicle is over the preset height limit.
LED Control: The green LED indicates that the vehicle height is acceptable, and the red LED signals a blockage. Switching between these states is controlled based on the sensor input.
LCD Update: The LCD communicates the system status by displaying either "STOP! TOO HIGH" or "Safe to Enter". Such feedback is useful for drivers and system monitors.
Optional Buzzer: An additional layer of alert is achieved via an optional piezo buzzer. A tone is produced when an over-height vehicle is detected to complement the visual alerts.
Additional Considerations
Sensor Calibration: Ambient IR light may affect sensor accuracy. Consider calibrating the sensor in your specific installation environment by adjusting sensitivity thresholds or employing shielding techniques.
Power Supply: Ensure a stable power source. Use a regulated 5V supply whether using the Arduino’s onboard regulator or an external power source to support steady operation of the sensor and display.
Debouncing and Delay: A short delay (around 200 ms) in the loop helps mitigate issues of false triggering due to transient obstructions. In more refined applications, you may implement averaging algorithms for a more robust signal.
Component Table Overview
| Functionality | Component | Pin/Connection | Purpose |
|---|---|---|---|
| IR Sensing | IR Sensor Module | VCC to 5V, GND to GND, OUT to Digital Pin 2 | Detects vehicle interference with IR beam |
| LED Indicator | Green LED | Digital Pin 13 (through 220Ω resistor) | Indicates safe vehicle height |
| LED Indicator | Red LED | Digital Pin 14 (or alternative, through 220Ω resistor) | Warns when vehicle height exceeds limit |
| User Display | 16x2 LCD | RS: Pin 7, EN: Pin 8, D4-D7: Pins 9, 10, 11, 12 | Displays "Safe to Enter" or "STOP! TOO HIGH" |
| Audible Alert | Buzzer (Optional) | Digital Pin 10 and GND | Provides additional audio warning |
Customization & Troubleshooting Tips
Calibration Advice
Depending on your particular setup, ambient conditions (like bright sunlight or reflective surfaces) may alter the reliability of the IR detection. Test your setup with varying light conditions and adjust the orientation or add shielding to the sensor as needed.
Consider installing a mechanical housing for the sensor and the electronics, protecting it from environmental variations. The proper calibration of the IR sensor is crucial to avoid false positives and negatives.
Power & Connectivity
Ensure every component has a proper connection with adequate power. If you experience flickering LEDs or LCD instability, examine the wiring for loose connections and consider adding decoupling capacitors across the power lines.
Moreover, if your system is installed outdoors or in harsh conditions, using waterproof enclosures and robust connectors might improve overall reliability.
Expandability Options
The basic system can be easily expanded to include more complex functionalities. For instance, integrating a remote monitoring system or data logging functionalities via SD card or wireless communication (Wi-Fi, Bluetooth) can enhance system efficiency.
Additionally, if precise height measurements are required, consider combining the IR sensor with additional sensors (e.g., ultrasonic sensors) for redundancy.
References
- Interfacing IR Sensor Module With Arduino - Instructables
-
How to Use IR Sensor Module With Arduino - How2Electronics
- IR Sensor Interfacing With Arduino - Robocraze
- LiquidCrystal Library Reference - Arduino
- Interfacing IR Sensor Module With Arduino - Circuit Digest
Recommended Additional Queries
Last updated March 24, 2025