HomeElectronics NewsSolar Raspberry Pi Counts Traffic With AI All Day

Solar Raspberry Pi Counts Traffic With AI All Day

A solar-powered Raspberry Pi 5 system uses AI-based vehicle detection to count cars, buses, trucks and motorcycles while consuming just 5.6 W and operating without mains power.

AI vehicle-detection frame showing a red car and blue car with bounding boxes, tracking IDs and vehicle counts moving toward points A and B
The Raspberry Pi 5 system uses YOLOv8 Nano to detect, track and count vehicles by direction in real time. (Image: Marios Christoforou)

A Raspberry Pi, a basic webcam and a solar-powered battery system can count cars, buses, trucks and motorcycles on a road without a mains connection. The system was developed by Marios Christoforou, a computer engineering student at the University of Cyprus, as his final-year project. Traffic counts can help authorities plan signals, flyovers and public transport routes, but collecting this data manually or installing dedicated monitoring equipment can require significant effort and infrastructure. Christoforou’s system combines local AI processing with solar power to automate the task.

The finished system uses a pole-mounted camera to identify four vehicle types, determine their direction of travel, assign tracking IDs and upload aggregated counts to a remote MySQL database. The camera feed is processed locally, so images do not need to be sent to the cloud. According to the author, the system achieved 96.6 per cent detection and classification accuracy on a standardised pre-recorded video and processes about 10 frames per second.

AI vehicle-detection frame showing a red car and blue car with bounding boxes, tracking IDs and vehicle counts moving toward points A and B
Full frame captured by the camera. (Image: Marios Christoforou)

The hardware can be reproduced in India using a Raspberry Pi 5 4GB, a 720p USB webcam, 32GB microSD card, 100W solar panel, 12V 600Wh (about 50Ah) lead-acid battery, solar charge controller, 12V-to-5V USB-C step-down converter and weatherproof enclosure with a pole mount. Based on indicative India-market prices, the complete setup could cost about ₹24,000–30,000 or more, depending on the seller, component brand and availability. The Raspberry Pi 5 4GB alone can cost around ₹13,400 from some Indian retailers, making the earlier ₹17,000–25,000 estimate too low.

The webcam sends its video to the Raspberry Pi 5, where the Ultralytics YOLOv8 Nano model analyses each frame and identifies cars, trucks, buses and motorcycles. Since the same vehicle appears in multiple frames, detection alone cannot provide a reliable count. The software uses a Kalman filter to predict where each vehicle should appear in the next frame and matches those predictions with new detections using greedy Intersection over Union (IoU) matching. This allows the system to maintain a tracking ID as a vehicle moves through the camera view.

Direction detection uses two reference points, POINT_A and POINT_B, normally positioned on opposite sides of the frame. After a vehicle has been tracked for a defined number of frames, its position is projected onto the line between the two points to determine its direction. Once counted, the vehicle is flagged to prevent duplicate counting. On-screen tracking states use different colours, with unclassified vehicles shown in teal, left-moving vehicles in red and right-moving vehicles in green.

Every few minutes, the Raspberry Pi sends a UTC timestamp and the two direction totals to a remote MySQL database before resetting its local counters. At startup, the software checks whether both the camera and database are reachable. The system therefore sends count data rather than the camera footage itself.

Building the system starts with flashing 64-bit Raspberry Pi OS to a microSD card using Raspberry Pi Imager, enabling SSH and configuring the Pi for headless operation. Python and the Ultralytics package are then installed, followed by the YOLOv8 Nano weights and model fusion to reduce processing overhead. The scene parameters are configured using POINT_A and POINT_B for direction detection and CROP_RECT to exclude areas such as parked vehicles and footpaths.

For solar operation, the author disabled unused interfaces and peripherals including Bluetooth, PCIe, audio and HDMI, underclocked the CPU to 2,000 MHz and GPU to 400 MHz, operated the Pi headlessly and reduced the processing resolution. The power system connects the solar panel to the charge controller, the controller to the battery and the battery to the Raspberry Pi through the 12V-to-5V converter. The camera is mounted beside the road with the lane in view, while the solar panel is positioned to receive sunlight.

Satellite view of a university campus road junction marked with a pin showing where the traffic-monitoring camera was deployed
Satelite image of the proposed location for installing the device. (Image:Marios Christoforou)

The optimisation produced a reported 35 per cent performance improvement and 37 per cent reduction in power consumption. Average power draw fell to 5.6 W, equivalent to about 134 Wh per day. The 600 Wh battery was designed to provide at least three winter days of operation without solar input under the project’s stated worst-case assumptions. The system can also operate at night when sufficient street lighting is available.

The accuracy result comes from a standardised pre-recorded video rather than a long-term live deployment, so it should not be treated as a field-accuracy figure. The model is also limited to four vehicle classes. Bicycles, pedestrians and objects outside these classes are ignored. The author has not published the complete source code for the traffic-monitoring system, so it should not be treated as an open-source software project unless the author confirms a future release and licence. The underlying Ultralytics YOLOv8 software is available under the AGPL-3.0 licence.

For Indian roads, further model training would be useful because vehicles such as autorickshaws, e-rickshaws, tractors and handcarts are not included in the current four classes. The India Driving Dataset from IIIT Hyderabad could be one potential source of local road imagery, subject to its licence and permitted use. The hardware is relatively accessible in India, while a LiFePO4 battery could provide a lighter alternative to the lead-acid battery, provided the charging and power system is designed accordingly.

Overall, the project is better suited to an intermediate maker familiar with Linux, Python and basic electronics. A beginner may need additional help with the remote MySQL database. Since only aggregated counts are uploaded, the design limits the visual data leaving the monitoring unit, although the camera still observes the road locally. For student teams, resident-welfare associations and smart-city projects, it demonstrates how a solar-powered edge-AI system can automate traffic counting without continuous manual observation.

For more information, click here.

Loading form…
Ananthu Ashok
Ananthu Ashok
Ananthu Ashok is a tech journalist and has a deep interest in embedded systems, open source, IoT, robotics and emerging tech.

SHARE YOUR THOUGHTS & COMMENTS

EFY Prime

Unique DIY Projects

Electronics News

Truly Innovative Electronics

Latest DIY Videos

Electronics Components

Electronics Jobs

Calculators For Electronics