DIY Miniature Smart City Arduino Automation Robotics Project

DIY Miniature Smart City 🏙️ Arduino Automation Robotics Project for Kids
🏙️ ROBOTICS FOR KIDS · LEVEL: INTERMEDIATE

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.

⏱️ 4–6 hours 🎂 Ages 10+ (with an adult) 📡 5 sensors + 3 servos

🚦 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.

🚦 Traffic Lights 💡 Streetlights 🅿️ Smart Parking 🚑 Emergency Priority 🚶 Pedestrian Crossing
🧰

What You'll Need

This is a bigger build with five mini systems, so gather everything first!

x1

Arduino Uno

The control tower brain for the whole city.

x3

SG90 Micro Servos

Parking gate, emergency boom barrier, pedestrian barrier.

x1

LDR (Light Sensor)

Turns the streetlight on automatically at night.

x1

Ultrasonic Sensor (HC-SR04)

Detects a car waiting to park.

x1

IR Sensor

Detects an approaching emergency vehicle.

x1

Push Button

Pedestrians press it to request a safe crossing.

x4

LEDs (Red, Yellow, Green, White)

Traffic light colors plus one streetlight bulb.

x1

Small Buzzer

Sounds an alert when an emergency vehicle is near.

x1

Breadboard + ~20 Jumper Wires

Connects every sensor and light.

x1

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.

Arduino Uno UNO A0 — LDR Pin 9 — Streetlight LED Pin 3,4,5 — Traffic LEDs Pin 6,7 — Ultrasonic Trig/Echo Pin 10 — Parking Servo Pin 2 — Emergency IR Pin 11 — Boom Barrier Servo Pin 8 — Buzzer Pin 13 — Pedestrian Button Pin 12 — Crossing Servo 5V GND LDR → Streetlight LED Red / Yellow / Green LEDs Ultrasonic Sensor Servo — Parking Gate IR Sensor — Emergency Servo — Boom Barrier Buzzer — Alert Button + Servo — Crossing
A0 = LDR (analog) Pins 3,4,5 = Traffic LEDs Pins 6,7 = Ultrasonic Trig/Echo Pins 9,10,11,12 = Servos & Streetlight Pin 2 = Emergency IR · Pin 13 = Pedestrian Button
🛠️

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!

1

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.

2

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!
3

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.

4

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.

5

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.

6

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.

7

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.

smart_city.ino
// 🏙️🤖 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.

🎉 Incredible work — you just built a real automated city! Dim the lights, roll a toy car up, and press the button to watch Civi run the whole show.

⬆️ Back to Materials List

Comments

Product Cards
Buddy Bot eBook
⭐ New 2026 Release
Build Your
Own Robot!
3D design, wiring &
Arduino coding.
Young inventors love it!
🖨️
3D Print
All parts
Wire it
Circuit guide
💻
Code it
Arduino IDE
🤖
Watch it
Walk & react
📋 Your Details
Enter your name
Valid 10-digit no.
Enter a valid email
Special Website Offer
₹499 300
🌍 International: $5 USD
One-time · Instant digital delivery
🔒 Secured by Razorpay · Your data is safe
📄 Download Free Sample Copy
🔒 Secured by Razorpay · Your data is safe
🍓
Raspberry Pi Pico Mastery
21 Projects
⚡ Launch Price — 80% OFF
Learn Pico
Build 21 Projects!
MicroPython · Wokwi
IoT · Certificate
Perfect for beginners!
🖥️
Wokwi
No hardware
🐍
MicroPy
From zero
🔨
21 Projects
IoT + sensors
📄
Certificate
Verified cert
📋 Your Details
Enter your name
Valid 10-digit no.
Enter a valid email
Special Launch Offer
₹999 200 80% OFF
🌍 International: $5 USD
One-time · Lifetime access · No subscription
🔒 Secured by Razorpay · UPI · Cards · NetBanking
🎉

You're in!

Payment successful! Your Buddy Bot eBook is ready. Time to build!

📖 Access Your eBook Now
🎉

Enrolled!

Payment successful! Lifetime access to all 21 Pico Projects is yours!

🍓 Go to My Course