Adaptive AI Traffic Density Controller (ASTDC) With Raspberry Pi and YOLO

by Summiya Yousaf in Circuits > Raspberry Pi

17 Views, 0 Favorites, 0 Comments

Adaptive AI Traffic Density Controller (ASTDC) With Raspberry Pi and YOLO

IMG_6927.jpeg

Static programmed timers provide a significant structural issue at urban intersections. They cause "Phantom Jams" in which travelers sit idle at red lights while empty intersecting lanes hold longer green signals by cycling blindly based on historical averages rather than current demand. This inefficiency leads to delays for emergency responders and millions of tons of unnecessary carbon dioxide emissions worldwide. The AI Smart Traffic Density Controller (ASTDC) is an open source, edge automated solution for this problem. The system uses real time vehicle density to dynamically change green light phases by integrating physical ultrasonic backup sensors with an optimized YOLO computer vision model running on a Raspberry Pi. Standard infrastructure is transformed into an intelligent, flexible traffic node by storing all intersection event recordings in a containerized Docker database.

Supplies

IMG_6933.jpeg
IMG_6921.jpeg
IMG_6940.jpeg
IMG_6922.jpeg
IMG_6912.jpeg

Processing Core: Raspberry Pi 5

Vision Input: USB camera

Backup Matrix: HC-SR04 Ultrasonic Distance Sensors

Local Interface: I2C LCD1602 Character Display Screen

Actuators: Traffic Light LED Modules

System Toggle: Momentary Push Button

Interconnects: Solderless Breadboard & copper jumper wire array

Laboratory Tools: Laser cutter, basic soldering iron, hot glue

Testing models: Diverse set of toy cars, buses, and motorcycles

Bill of Materials (BOM) and Project Components

To create this smart intersection, you'll need a Raspberry Pi 5 core, a USB webcam, an SD card reader, jumper wires, four HC-SR04 ultrasonic sensors, four traffic light LED module, an LCD and a button. The physical layout is constructed using wooden sheets and road stickers, and it is populated with a collection of toy vehicles to replicate real world traffic. Assembling this brings the total estimated cost of project supplies to roughly 400euro. For complete details about cost , materials used and suppliers you can view it here BOMSummiyaYousaf.xlsx.

Data Annotation

To Annotate and prepare your model, upload your toy vehicle(Car, Bus, Motorcycle, or Pedestrian) photos to Roboflow and label them.

AI Training

Export the dataset in YOLO26 format. Then, paste the generated download snippet into a Jupyter Notebook and run it to start training on your custom toys. Once the process is finished, copy the output weights file from your notebook environment into your Raspberry Pi's folder.

Mechanical Assembly and Hardware Wiring

Using a breadboard, attach your physical infrastructure components to the GPIO pins of the Raspberry Pi. Then mount all your electronics into the laser cut wooden housing.

Python Code

Write codes such that it looks at the live webcam feed to count vehicles in each lane while simultaneously checking the sensors.

Launching the Automated Control System

IMG_6929.jpeg

Start your system within Docker, then run the main control script (headless.py) to handle traffic light changes based on the vehicles they see.

Dashboard

Screenshot 2026-06-18 134735.png

Open a new terminal window and run your dashboard script (dashboard.py) to enable your PC's control screen.

Live Validation

IMG_6909.jpeg

Place your toy vehicles in front of the camera and watch the traffic lights change automatically in real time.