AI Crowd Density Monitor Robot

AI Crowd Density Monitor Robot | Kids Robotics Project | MakeMindz
MakeMindz Robotics Project

Build an AI Crowd Density Monitor Robot!

A super cool robotics project that uses sensors and code to detect overcrowding and keep people safe in public places!

⭐ Ages 12+ ⏱ 3–4 Hours 🟢 Beginner–Intermediate 🐍 MicroPython / Python

Have you ever seen a super crowded place — like a concert, a market, or a train station — and wondered how people know when it's TOO crowded? What if a robot could do that job? 🤩

In this project, you'll build an AI-powered crowd density monitor using a Raspberry Pi, ultrasonic sensors, and Python code. It counts how many people are nearby and sends out alerts when things get too crowded. Real engineers build systems like this for stadiums, airports, and shopping malls!

🌍 Why Does This Matter?

Every year, accidents happen in overcrowded places because nobody knew it was getting too dangerous. Our robot acts like a smart safety guard — it watches, counts, and warns people before things get unsafe. That's AI working for the real world! 🦺

🔍 What We're Building

How Will Our Robot Work?

Your finished robot will do all of this automatically:

1
Detect People

Ultrasonic sensors spot movement

2
Count Them

Code counts entries and exits

3
Analyse Density

AI logic checks the crowd level

4
Show Status

LEDs + LCD display the level

5
Sound Alert

Buzzer warns if overcrowded

🟢

SAFE

0–5 people — Green LED on

🟡

MODERATE

6–10 people — Yellow LED on

🔴

OVERCROWDED!

11+ people — Red LED + Buzzer

🛒 Step 1 — Gather Supplies

What You'll Need

Everything below can be found online or at an electronics store. Total cost: around ₹800–1200 (or $12–18 USD).

🧠
Raspberry Pi Pico W
The brain of our robot — runs MicroPython
📡
2× HC-SR04 Sensors
Ultrasonic sensors that detect objects
💡
3 LEDs (R, Y, G)
Red, Yellow, and Green status lights
🖥️
16×2 LCD Display
Shows crowd count and status text
🔔
Piezo Buzzer
Makes noise when it's overcrowded
🔌
3× 330Ω Resistors
Protect the LEDs from too much power
🔧
Breadboard + Jumpers
Connect everything without soldering
💻
USB Cable + Thonny IDE
To program and power the Pico
🔋
I2C Module for LCD
Makes connecting the LCD screen easy
⚠️

Safety First!

Always ask an adult before buying parts or working with electronics. Keep liquids away from the breadboard and never connect to mains power — USB only for this project!

🔬 Step 2 — Understand the Science

The Cool Science Behind It

🦇

Ultrasonic Sensors — Bat Tech!

The HC-SR04 sensor works just like a bat's echolocation! It sends out a high-pitched sound pulse (too high for humans to hear), and waits for the echo to bounce back. By measuring the time it takes, it calculates the distance to an object.

Distance = (Time × Speed of Sound) ÷ 2
The ÷2 is because the sound travels to the object AND back!

🚶

Counting People — Entry & Exit Logic

We place two sensors side by side (Sensor A and Sensor B). When someone walks in, they trigger Sensor A first, then Sensor B → the counter goes up. When someone walks out, they trigger Sensor B first, then Sensor A → the counter goes down. This is called a bi-directional counter!

🤖

The AI Part — Decision Making

The "AI" in this project is an if-elif-else decision tree — the same idea used in real machine learning classifiers! Based on the current count, the program decides which category we're in (Safe / Moderate / Overcrowded) and triggers the right outputs. It's rule-based AI, just like early expert systems.

🧠 Did You Know? Fun Facts About Crowd Tech!

  • Tokyo's train stations use AI cameras to monitor up to 3 million passengers every day 🚆
  • Mecca uses real-time crowd density AI during Hajj to prevent stampedes and keep 2 million pilgrims safe 🕌
  • Singapore's smart city systems count pedestrians on every busy street automatically 🌆
  • The Kumbh Mela in India is the world's largest human gathering — AI helped monitor 50 million people in 2019! 🇮🇳
⚡ Step 3 — Build the Circuit

Circuit Diagram

Study this diagram carefully before wiring anything up. Double-check each connection before powering on!

AI CROWD DENSITY MONITOR — CIRCUIT DIAGRAM Raspberry Pi Pico W GP14 → GP15 → GP16 → GP17 → GP18 → GP19 → ↑ SDA/SCL (I2C) ↑ ← GP2 ← GP3 ← GP4 ← GP5 ← GP6 ← GND → Sensor A (Entry) HC-SR04 VCC → 3.3V TRIG → GP14 ECHO → GP15 Sensor B (Exit) HC-SR04 VCC → 3.3V TRIG → GP16 ECHO → GP17 Status LEDs G GP2 + 330Ω Y GP3 + 330Ω R GP4 + 330Ω Buzzer GP5 → Buzzer+ 16×2 I2C LCD Display VCC → 3.3V GND → GND SDA→GP18 SCL→GP19 I2C Address: 0x27 (default) Signal wire Dashed = jumper wire

Wiring Checklist — Do These in Order!

  • Connect Pico's 3.3V pin to the breadboard's positive rail (+)
  • Connect Pico's GND to the breadboard's negative rail (–)
  • Wire both HC-SR04 VCC pins to the 3.3V rail
  • Wire both HC-SR04 GND pins to the GND rail
  • Sensor A: TRIG → GP14, ECHO → GP15
  • Sensor B: TRIG → GP16, ECHO → GP17
  • Green LED: long leg → 330Ω resistor → GP2, short leg → GND
  • Yellow LED: long leg → 330Ω resistor → GP3, short leg → GND
  • Red LED: long leg → 330Ω resistor → GP4, short leg → GND
  • Buzzer (+) → GP5, Buzzer (–) → GND
  • LCD I2C Module: VCC→3.3V, GND→GND, SDA→GP18, SCL→GP19
💡

Pro Tip: LED Polarity

LEDs have a positive (anode) and negative (cathode) leg. The longer leg is positive (+) and goes through the resistor to the GPIO pin. The shorter leg is negative (–) and goes to GND. Getting this backwards means the LED won't light up!

💻 Step 4 — Install Software

Set Up MicroPython

1

Install Thonny IDE

Download Thonny from thonny.org — it's a free, beginner-friendly Python editor. It works on Windows, Mac, and Linux. Install it like any normal app.

2

Flash MicroPython onto Pico

Hold the BOOTSEL button on your Pico, plug it into your computer via USB, then release. It will appear as a USB drive. In Thonny, go to Run → Configure Interpreter → Install MicroPython and flash it onto the Pico.

3

Install the LCD Library

Download the lcd_api.py and pico_i2c_lcd.py library files from GitHub (search: "T-622 MicroPython LCD"). Copy them to the Pico using Thonny's file panel → right-click → Upload to Pico.

🐍 Step 5 — Write the Code

The Python Code

Copy this code into Thonny, save it as main.py, and upload it to your Pico. Read through the comments (the green bits!) to understand what each part does.

main.py — Crowd Density Monitor
# ════════════════════════════════════════════════ # AI CROWD DENSITY MONITOR — MakeMindz Project # Hardware: Raspberry Pi Pico W + HC-SR04 × 2 # Language: MicroPython # ════════════════════════════════════════════════ from machine import Pin, I2C import utime from pico_i2c_lcd import I2cLcd # ── PIN SETUP ────────────────────────────────── # Ultrasonic Sensor A (Entry side) TRIG_A = Pin(14, Pin.OUT) ECHO_A = Pin(15, Pin.IN) # Ultrasonic Sensor B (Exit side) TRIG_B = Pin(16, Pin.OUT) ECHO_B = Pin(17, Pin.IN) # LED pins LED_GREEN = Pin(2, Pin.OUT) LED_YELLOW = Pin(3, Pin.OUT) LED_RED = Pin(4, Pin.OUT) # Buzzer pin BUZZER = Pin(5, Pin.OUT) # LCD setup using I2C (SDA=GP18, SCL=GP19) i2c = I2C(1, sda=Pin(18), scl=Pin(19), freq=400000) LCD_ADDR = 0x27 lcd = I2cLcd(i2c, LCD_ADDR, 2, 16) # ── SETTINGS ─────────────────────────────────── MAX_CAPACITY = 10 # Alert when crowd exceeds this WARN_CAPACITY = 6 # Warning starts here DETECT_DIST = 80 # Detection range in centimetres COOLDOWN = 1.5 # Seconds to wait after each count crowd_count = 0 # People counter (starts at zero) # ── HELPER: Measure distance with HC-SR04 ────── def get_distance(trig, echo): trig.low() utime.sleep_us(2) trig.high() utime.sleep_us(10) trig.low() # Wait for echo pulse start (timeout after 30ms) timeout = utime.ticks_ms() while echo.value() == 0: if utime.ticks_diff(utime.ticks_ms(), timeout) > 30: return 999 # No object detected start = utime.ticks_us() while echo.value() == 1: if utime.ticks_diff(utime.ticks_ms(), timeout) > 30: return 999 end = utime.ticks_us() # Distance = (time in microseconds × 0.0343) ÷ 2 duration = utime.ticks_diff(end, start) return (duration * 0.0343) / 2 # ── HELPER: Control LEDs based on crowd level ── def update_leds(count): if count >= MAX_CAPACITY: # 🔴 OVERCROWDED LED_GREEN.low() LED_YELLOW.low() LED_RED.high() BUZZER.high() utime.sleep_ms(500) BUZZER.low() elif count >= WARN_CAPACITY: # 🟡 MODERATE LED_GREEN.low() LED_YELLOW.high() LED_RED.low() BUZZER.low() else: # 🟢 SAFE LED_GREEN.high() LED_YELLOW.low() LED_RED.low() BUZZER.low() # ── HELPER: Update the LCD screen ────────────── def update_display(count): lcd.clear() lcd.putstr(f"People: {count}/{MAX_CAPACITY}") lcd.move_to(0, 1) if count >= MAX_CAPACITY: lcd.putstr("!! OVERCROWDED !!") elif count >= WARN_CAPACITY: lcd.putstr(" Filling Up... ") else: lcd.putstr(" All Safe! ") # ── MAIN LOOP ────────────────────────────────── lcd.putstr("Crowd Monitor v1") utime.sleep(2) crowd_count = 0 update_display(crowd_count) print("🤖 Crowd Monitor ONLINE!") while True: dist_a = get_distance(TRIG_A, ECHO_A) dist_b = get_distance(TRIG_B, ECHO_B) # ── ENTRY DETECTION: A triggers first, then B if dist_a < DETECT_DIST and dist_b >= DETECT_DIST: utime.sleep_ms(300) dist_b2 = get_distance(TRIG_B, ECHO_B) if dist_b2 < DETECT_DIST: # Confirmed entry! crowd_count += 1 print(f"ENTRY → Total: {crowd_count}") update_display(crowd_count) update_leds(crowd_count) utime.sleep(COOLDOWN) # ── EXIT DETECTION: B triggers first, then A elif dist_b < DETECT_DIST and dist_a >= DETECT_DIST: utime.sleep_ms(300) dist_a2 = get_distance(TRIG_A, ECHO_A) if dist_a2 < DETECT_DIST: # Confirmed exit! crowd_count = max(0, crowd_count - 1) print(f"EXIT ← Total: {crowd_count}") update_display(crowd_count) update_leds(crowd_count) utime.sleep(COOLDOWN) utime.sleep_ms(50) # Small pause between readings

How to Upload the Code

In Thonny: open the file → click Run → Run current script (F5). To make it run automatically every time the Pico powers on, save it as main.py directly on the Pico (File → Save as → Raspberry Pi Pico).

🧪 Step 6 — Test Your Robot!

Testing & Debugging

Let's make sure everything works! Do these tests one by one:

✅ Test 1

Sensor Distance Check

Open Thonny's shell and run print(get_distance(TRIG_A, ECHO_A)). Put your hand 30cm in front of Sensor A — you should see ~30 printed!

✅ Test 2

LED Test

Temporarily set crowd_count = 7 and call update_leds(7). The yellow LED should turn on. Try 0 for green, 12 for red + buzzer.

🔵 Test 3

Entry Count

Walk slowly past Sensor A first, then Sensor B. Watch the Thonny shell — it should print "ENTRY → Total: 1" and the LCD should update!

🔵 Test 4

Overcrowd Alert

Keep walking past the entry sensors until the count hits 10. The red LED should flash and the buzzer should beep to warn you it's too crowded!

🐛

Common Problems & Fixes

Sensor reading 999? Check the VCC and GND wires are properly seated.
LCD shows nothing? Scan for the I2C address: run i2c.scan() in Thonny shell — if you see a different number than 0x27, update LCD_ADDR.
Count jumps by 2? Increase the COOLDOWN value to 2.0 seconds.

🚀 Level Up!

Cool Ways to Upgrade Your Project

Once your basic project is working, try these awesome additions!

📱

Wi-Fi Dashboard

Use the Pico W's built-in Wi-Fi to send crowd data to a web dashboard in real time!

📊

Data Logger

Save count data to a CSV file to see busy and quiet times — just like real analytics!

🔊

Voice Announcements

Add a speaker module to say "Caution: area is getting crowded" out loud!

📷

Camera Vision

Add a Pi Camera module and use OpenCV to count people with actual computer vision AI!

🔢

Multi-Zone

Add more sensor pairs for multiple doorways and track each room separately!

📲

SMS Alerts

Connect to Twilio API to send a text message to a safety officer when overcrowding happens!

❓ FAQ

Questions Kids Always Ask

Q: Can I use a regular Raspberry Pi 4 instead of a Pico?

Yes! If you use a Raspberry Pi 4, you'd write regular Python instead of MicroPython, and the GPIO pin numbers stay the same. A Pi 4 is more powerful but also more expensive and needs more setup.

Q: How accurate is the people counter?

With two ultrasonic sensors and the bi-directional logic, accuracy is around 85–90% in a controlled doorway. False counts can happen if two people walk through at the same time — which is why real systems often use cameras too!

Q: Is this really "AI"?

Great question! Our project uses rule-based AI — the simplest type. Real AI crowd monitors also use machine learning and neural networks trained on thousands of images. Our project teaches you the same decision-making logic, just in a simpler form.

Q: Can I use this for my school science fair?

Absolutely! Make sure you document your hypothesis, experiment, results, and conclusion. You could compare the sensor-counting accuracy against counting by hand, and show your data as a graph. It'd make an amazing project!

Q: What if the HC-SR04 doesn't work at 3.3V?

Some HC-SR04 modules work better at 5V. If using 5V, you'll need a voltage divider (two resistors) on the ECHO line to step it down to 3.3V for the Pico. A 1kΩ and 2kΩ resistor pair works great!

🎉 You Did It!

You just built a working AI safety system — the same kind used in airports, stadiums, and smart cities around the world! You've learned about ultrasonic sensing, bi-directional counting logic, decision trees, I2C communication, and MicroPython. That's seriously impressive engineering. What will you build next? 🚀

🏷 Tags: robotics for kids · AI projects · Raspberry Pi Pico · MicroPython · STEM projects · crowd monitoring · ultrasonic sensor · Python beginner · MakeMindz

MakeMindz — Making Robotics & AI Fun for Young Builders 🤖

© 2025 MakeMindz. Build something amazing today!

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