Introduction
Have you ever thought about how parking gates open automatically when a car approaches?
Well.. in this project, I set out to build a smart parking gate using an Arduino UNO R3, a servo motor, and an ultrasonic sensor.
The idea is simple: detect when a car (or an object.. anything basically) is near, and automatically lift the gate.
It’s a small but fun automation project that combines electronics, coding, and real-world application!
What You’ll Need
- Arduino UNO (or any microcontroller)
- Ultrasonic sensor (HC-SR04) or IR sensor
- Servo motor (to act as the gate arm)
- Breadboard and jumper wires
- Power supply (USB or battery pack)
- (Optional) LED lights & an LCD display for additional signals
How It Works

Simple diagram of the project, made in Wokwi
- First, the ultrasonic sensor continuously measures the distance in front of the gate. To get this reading accurately, I averaged multiple samples from the ultrasonic sensor:
float getAverageDistance() { long total = 0; const int samples = 5;
for (int i = 0; i < samples; i++) { digitalWrite(PIN_TRIG, LOW); delayMicroseconds(2); digitalWrite(PIN_TRIG, HIGH); delayMicroseconds(10); digitalWrite(PIN_TRIG, LOW);
long duration = pulseIn(PIN_ECHO, HIGH, 30000); float distance = duration * 0.034 / 2;
if (distance > 0 && distance < 400) { total += distance; } else { total += 400; // assume max range if error } delay(10); } return total / samples;}This helps filter out noisy readings and ensures the servo only reacts when a car is actually present.
- When a car comes within a set distance (e.g., 10 cm), the Arduino sends a signal to the servo motor and other indicators (in here, I used a 16x2 LCD and 2 LEDs).
if (jarak > 0 && jarak <= 10) { palangServo.write(90); // open gate digitalWrite(PIN_LED_R, LOW); digitalWrite(PIN_LED_G, HIGH); lcd.print("Status: Buka"); isOpen = true; lastOpenTime = currentTime;}The green LED turns on when the gate is open, while the red LED remains off.
- After 2 seconds, the system closes the gate again:
else { palangServo.write(0); // close gate digitalWrite(PIN_LED_R, HIGH); digitalWrite(PIN_LED_G, LOW); lcd.print("Status: Tutup"); isOpen = false;}Here, the red LED turns on, indicating that the gate is closed.
- (Optional, last step) LCD + RemoteXY connection and display.
I also experimented with adding a 16x2 LCD to display the distance and status, plus the RemoteXY app so I could monitor the gate from my phone over a Wi-Fi point (this requires an additional ESP8266 module).
Full Code
The full code will be released on 17th of September.. 😉
The End!
Thank you for reading this far into this first guide that I made, hopefully this can inspire you guys to build more awesome and usefull stuff for everyday activities!
Happy coding!