Build a Mini Smart City Where Everything Runs Itself!
Meet Civi — an Arduino-powered control tower that automates a tiny city! Streetlights switch on at night, cars park themselves in, pedestrians get a safe crossing, and emergency vehicles always get the green light first.
🚦 Say hi to Civi, your smart city control tower!
What Is a Smart City, Anyway?
A smart city uses sensors and computers to make everyday things — like traffic lights and parking — react automatically, without a person controlling them by hand. In this project, one Arduino "control tower" will watch five different sensors and instantly control lights, gates, and barriers all across our miniature city.
What You'll Need
This is a bigger build with five mini systems, so gather everything first!
Arduino Uno
The control tower brain for the whole city.
SG90 Micro Servos
Parking gate, emergency boom barrier, pedestrian barrier.
LDR (Light Sensor)
Turns the streetlight on automatically at night.
Ultrasonic Sensor (HC-SR04)
Detects a car waiting to park.
IR Sensor
Detects an approaching emergency vehicle.
Push Button
Pedestrians press it to request a safe crossing.
LEDs (Red, Yellow, Green, White)
Traffic light colors plus one streetlight bulb.
Small Buzzer
Sounds an alert when an emergency vehicle is near.
Breadboard + ~20 Jumper Wires
Connects every sensor and light.
Cardboard City Base
Roads, buildings, and a parking lot layout.
The Circuit Diagram
Five systems, one Arduino! Here's how every sensor, light, and servo connects.
Step-by-Step Build Instructions
We'll build one system at a time, then connect them all to Civi. Work with an adult on the wiring!
Lay out your city base
Draw roads, an intersection, a parking lot, and a crosswalk on a large cardboard sheet. Add small building blocks along the streets.
Build the smart streetlight
Mount the LDR facing upward near a streetlight LED. When the room gets dark, the LDR's reading drops, and the Arduino turns the LED on automatically.
💡 Tip: Cover the LDR with your hand to test — the streetlight should switch on!Set up the traffic light
Place red, yellow, and green LEDs at your intersection. The Arduino will cycle through them automatically using timed delays, just like real traffic lights.
Add smart parking
Mount the ultrasonic sensor at the entrance to your parking lot and the gate servo right behind it. When a toy car gets close enough, the gate lifts automatically.
Wire the emergency vehicle lane
Place the IR sensor along a special emergency lane. When an emergency toy vehicle passes, the boom barrier servo lifts instantly, the traffic light switches to green, and the buzzer sounds a warning.
Build the pedestrian crossing
Add a push button near your crosswalk. When pressed, it pauses traffic and swings the small pedestrian barrier servo open so a toy figure can "cross" safely.
Connect everything and test
Double-check all five systems against the circuit diagram, upload the code, and watch your whole miniature city come alive!
The Arduino Code
This code runs all five smart city systems together. Copy it into the Arduino IDE and click Upload.
// 🏙️🤖 Civi the Smart City Control Tower — Arduino Automation Project // Automates: streetlights, traffic lights, parking, emergency priority, pedestrians #include <Servo.h> Servo parkingGate; Servo boomBarrier; Servo crossingGate; // ---- Pin setup ---- const int ldrPin = A0; const int streetlightPin = 9; const int redPin = 3; const int yellowPin = 4; const int greenPin = 5; const int trigPin = 6; const int echoPin = 7; const int emergencyIRPin = 2; const int buzzerPin = 8; const int pedButtonPin = 13; // ---- Traffic light timing (non-blocking) ---- unsigned long lastChange = 0; int lightState = 0; // 0 = green, 1 = yellow, 2 = red const long greenTime = 4000, yellowTime = 1000, redTime = 3000; void setup() { parkingGate.attach(10); boomBarrier.attach(11); crossingGate.attach(12); pinMode(streetlightPin, OUTPUT); pinMode(redPin, OUTPUT); pinMode(yellowPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(emergencyIRPin, INPUT); pinMode(buzzerPin, OUTPUT); pinMode(pedButtonPin, INPUT_PULLUP); parkingGate.write(0); boomBarrier.write(0); crossingGate.write(0); } void loop() { handleStreetlight(); handleParking(); // Emergency vehicles always come first! if (digitalRead(emergencyIRPin) == HIGH) { handleEmergency(); } else if (digitalRead(pedButtonPin) == LOW) { handlePedestrianCrossing(); } else { handleTrafficLight(); } } // 💡 Turns the streetlight on automatically when it's dark void handleStreetlight() { int lightLevel = analogRead(ldrPin); if (lightLevel < 400) { // dark room digitalWrite(streetlightPin, HIGH); } else { digitalWrite(streetlightPin, LOW); } } // 🅿️ Opens the parking gate when a car gets close void handleParking() { long distance = readDistanceCM(); if (distance > 0 && distance < 10) { parkingGate.write(90); // lift gate } else { parkingGate.write(0); // lower gate } } // 📏 Measures distance using the ultrasonic sensor long readDistanceCM() { digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); long duration = pulseIn(echoPin, HIGH, 20000); return duration * 0.034 / 2; } // 🚑 Gives emergency vehicles instant priority void handleEmergency() { digitalWrite(greenPin, HIGH); digitalWrite(yellowPin, LOW); digitalWrite(redPin, LOW); boomBarrier.write(90); // lift barrier tone(buzzerPin, 1000); delay(2000); noTone(buzzerPin); boomBarrier.write(0); } // 🚶 Safely stops traffic so a pedestrian can cross void handlePedestrianCrossing() { digitalWrite(greenPin, LOW); digitalWrite(yellowPin, LOW); digitalWrite(redPin, HIGH); delay(500); crossingGate.write(90); // open crossing delay(3000); // time to cross crossingGate.write(0); } // 🚦 Cycles the normal traffic light using millis() (non-blocking) void handleTrafficLight() { unsigned long now = millis(); if (lightState == 0 && now - lastChange > greenTime) { digitalWrite(greenPin, LOW); digitalWrite(yellowPin, HIGH); lightState = 1; lastChange = now; } else if (lightState == 1 && now - lastChange > yellowTime) { digitalWrite(yellowPin, LOW); digitalWrite(redPin, HIGH); lightState = 2; lastChange = now; } else if (lightState == 2 && now - lastChange > redTime) { digitalWrite(redPin, LOW); digitalWrite(greenPin, HIGH); lightState = 0; lastChange = now; } }
How Does Civi Actually Work?
This project packs in five real robotics ideas used in actual smart cities!
Analog Sensing
The LDR gives a range of values, not just on/off. The Arduino reads a number (0–1023) and decides "is it dark enough?" — this is called analog input.
Distance with Sound
The ultrasonic sensor sends a sound pulse and times how long it takes to bounce back — the same trick bats use to "see" in the dark!
Priority Logic
Notice how the code checks for an emergency vehicle before anything else. This is called priority — the most important task always runs first.
Non-Blocking Timing
Instead of freezing the whole program with delay(), the traffic light uses millis() to keep track of time while still checking other sensors.
🧑🔬 Safety First!
- Build with an adult, especially for wiring the ultrasonic sensor and buzzer.
- Keep small pieces like LEDs and jumper wires away from little siblings.
- Never stare directly into an LED up close.
- Double-check wiring before plugging in power — mixed-up wires can damage components.
- This is a model city for learning, not a real traffic control system!
Frequently Asked Questions
Do I need five separate Arduinos for five systems?
No! One Arduino Uno has enough pins to run all five systems at once, as long as you follow the pin plan in the circuit diagram carefully.
What if my LDR readings look backwards?
Some LDR wiring setups give higher numbers in the dark instead of lower. Just flip the comparison in handleStreetlight() from < to > and test again.
Why does the emergency vehicle interrupt everything?
In the code's loop(), we check the emergency sensor first, before the normal traffic light logic. That's exactly how real cities prioritize ambulances and fire trucks too!
Can I add more systems later?
Definitely! You could add a rain sensor to close a stadium roof, or a sound sensor for noise-activated streetlights — the same input → decide → output pattern works for almost anything.

Comments
Post a Comment