This guide explains how to build and implement an Arduino-based height detection system at a tunnel entrance. The system detects over-height vehicles by monitoring an infrared (IR) beam. When a vehicle blocks the IR beam, a red LED illuminates and the LCD display shows the word “STOP” to prevent safety hazards. In the absence of blockage, the green LED remains active and the display indicates a clear path. This project involves careful planning of both the electronic circuit and the software logic using the Arduino IDE. Detailed wiring instructions, a circuit diagram, and annotated code examples are provided to help you successfully build the system.
Before starting, ensure you have all the necessary parts:
The circuit involves connecting the IR sensor, LEDs, and LCD display to the Arduino. Below is a detailed wiring guide along with a simplified diagram. Although a photo is recommended for clarity, the diagram below serves as a reference to help you correctly connect the components.
Connections:
Connections:
There are two common ways to connect an LCD display:
If you wish to provide an auditory warning:
The universal wiring layout is summarized in the table below:
Component | Connection | Arduino Pin / Note |
---|---|---|
IR Transmitter | VCC to 5V, GND to GND | Positioned to send IR beam |
IR Receiver | VCC to 5V, GND to GND, OUT to digital input | Digital Pin 2 (example) |
Green LED | Anode to digital output via 220Ω, Cathode to GND | Digital Pin 8 (example) |
Red LED | Anode to digital output via 220Ω, Cathode to GND | Digital Pin 9 (example) |
LCD Display (I2C) | VCC→5V, GND→GND, SDA→A4, SCL→A5 | I2C Address typically 0x27 |
Piezo Buzzer (Optional) | Positive lead to digital output, Negative lead to GND | Digital Pin 10 (example) |
The following Arduino sketch is designed to implement the height detection behavior. The code checks the IR receiver’s output to determine whether the IR beam is blocked by an over-height vehicle. If the beam is interrupted, the code turns on the red LED and the LCD displays "STOP". Otherwise, it keeps the green LED on and displays a safe message on the LCD.
// Include necessary libraries for LCD (I2C)
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
// Define LCD (adjust I2C address if needed)
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Define pin assignments
const int irReceiverPin = 2; // IR Receiver signal pin
const int greenLedPin = 8; // Green LED pin
const int redLedPin = 9; // Red LED pin
const int buzzerPin = 10; // Optional: Piezo buzzer pin
void setup() {
// Initialize serial communication for debugging (optional)
Serial.begin(9600);
// Initialize LCD
lcd.init();
lcd.backlight();
lcd.print("System Booting...");
// Set pin modes
pinMode(irReceiverPin, INPUT);
pinMode(greenLedPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
pinMode(buzzerPin, OUTPUT); // For audio warnings (optional)
// Initialize LED state (green on, red off)
digitalWrite(greenLedPin, HIGH);
digitalWrite(redLedPin, LOW);
noTone(buzzerPin); // Ensure buzzer is off
delay(2000); // Wait for 2 seconds for initialization
// Show system ready message
lcd.clear();
lcd.print("System Ready");
delay(1000);
}
void loop() {
// Read the state of the IR receiver
int irState = digitalRead(irReceiverPin);
// Debug output (optional)
Serial.print("IR State: ");
Serial.println(irState);
// If the IR beam is blocked (assuming LOW means blockage detected)
if (irState == LOW) {
// Indicate detection with LED and LCD
digitalWrite(greenLedPin, LOW);
digitalWrite(redLedPin, HIGH);
lcd.clear();
lcd.print("STOP");
// Optional: Activate audible warning
tone(buzzerPin, 1000); // Emit tone at 1000 Hz
} else {
// No blockage - safe to proceed
digitalWrite(redLedPin, LOW);
digitalWrite(greenLedPin, HIGH);
lcd.clear();
lcd.print("All Clear");
noTone(buzzerPin); // Stop the buzzer sound if active
}
delay(100); // Delay for stability (100 ms)
}
The program starts by including the necessary libraries: LiquidCrystal_I2C
for handling the LCD, and Wire
for I2C communication. This ensures that the LCD can easily be connected and controlled using just two data lines (SDA and SCL).
Each component is assigned a digital pin. The IR receiver’s output is on digital pin 2. Two digital pins are dedicated for LED output – one for the green LED and one for the red LED. An additional pin is optionally used for a piezo buzzer to generate an audible warning when the beam is blocked.
The setup()
function initializes the LCD and sets the correct pin modes (input for the IR receiver, output for LEDs and buzzer). The green LED is switched on to indicate that the path is clear, while the red LED remains off. A short delay allows the system to display an initial boot message before transitioning into a ready state.
The loop()
function continuously monitors the IR receiver. When the IR beam is interrupted (detected by a LOW state), the system responds by turning off the green LED and activating the red LED. The LCD then displays the word “STOP”, and if you have connected a buzzer, it issues a tone at 1000 Hz to alert nearby personnel. If the beam is uninterrupted, the system resets to a “clear” state by displaying "All Clear" on the LCD and reactivating the green LED.
While photos of the actual build can be extremely helpful, you can also refer to the following schematic diagram to visualize the circuit connections:
This schematic includes:
After setting up the circuit and uploading the code to your Arduino board, perform the following tests:
Depending on environmental conditions (lighting, distance, etc.), you may need to calibrate the sensitivity of your IR sensor. Adjust your positioning or add a comparator in the code if the sensor readings fluctuate. Additionally, check the alignment of the transmitter and receiver periodically to maintain system accuracy.
While the core system meets the primary objective of detecting over-height vehicles, you might consider some additional enhancements:
Since the system is intended for operational safety at critical infrastructure points, ensure that all components are securely housed in a weather-proof enclosure if deployed outdoors. Regular maintenance and calibration are key to reducing false positives or negatives. Always test the system under different conditions to ensure reliable performance.
Incorrect positioning of the IR transmitter and receiver is the most common issue. If the system does not detect vehicles reliably:
If the LEDs or LCD are not responding as expected, perform the following checks:
Utilize the Serial Monitor
to print sensor values and debug the logic. Verify that computed sensor readings correlate with physical observations. Adjust the threshold values in the code, if necessary, to optimize system response.
For more detailed guidance and community projects, please refer to the following resources:
To deepen your understanding or explore related projects, consider these searches: