Author: kingScarH
Language: C (Arduino)
Platform: Arduino UNO
Last Updated: October 2025
This project automatically opens and closes a gate using an HC-SR04 Ultrasonic Sensor and an SG90 Servo Motor.
When a vehicle is detected within a set range, the gate opens automatically, accompanied by LED and buzzer indicators.
The system follows industrial-style programming structure and coding conventions.
| Component | Description |
|---|---|
| Arduino UNO | Main microcontroller board |
| HC-SR04 Ultrasonic Sensor | Vehicle distance detection |
| SG90 Servo Motor | Gate actuator |
| LEDs (Red/Green) | Status indicators |
| Buzzer | Audio alert system |
- Ultrasonic Sensor continuously measures the distance to detect nearby vehicles.
- If a vehicle is within 20 cm, the servo rotates from 180° → 90° (gate open).
- The green LED turns ON and the buzzer beeps twice.
- After 3 seconds or when no vehicle is detected, the servo returns to 180° (gate closed).
- The red LED turns ON and the buzzer beeps thrice.
| Arduino Pin | Connected To | Description |
|---|---|---|
| 2 | TRIG | Ultrasonic Trigger |
| 3 | ECHO | Ultrasonic Echo |
| 5 | GREEN LED | Gate Open Indicator |
| 6 | RED LED | Gate Closed Indicator |
| 7 | BUZZER | Audio Alert |
| 9 | SERVO | Gate Actuator |
| File | Description |
|---|---|
main.c |
Complete source code written in MISRA C-style format |
README.md |
Project documentation and setup guide |
- MISRA-inspired naming conventions
- Modular structure using static functions
- Well-commented industrial-style C
- No magic numbers, clear constants
-Compatible with Arduino IDE
- Open Arduino IDE
- Copy contents of
main.cinto a new sketch - Select Board: Arduino UNO and correct COM Port
- Upload the code
- Power your setup and observe automatic gate operation
- Add IR or RFID-based vehicle access
- Integrate with Wi-Fi for IoT-based logging
- Implement FSM (Finite State Machine) for multi-gate control
- Add low-power (sleep) mode with interrupt wakeup
This project is open-source and free to use for educational and research purposes.
© 2025 kingScarH – All Rights Reserved.