Sunday, 31 May 2026

AI Smart Traffic Violation Detection System Using Computer Vision

AI Smart Traffic Violation Detection System Using Computer Vision AI Agent + ESP32 + Computer Vision + n8n Automation + Telegram Voice Alerts + Google Sheets + ThingSpeak Cloud Dashboard
AI Smart Traffic Violation Detection System Using Computer Vision AI Agent + ESP32 + Computer Vision + n8n Automation + Telegram Voice Alerts + Google Sheets + ThingSpeak Cloud Dashboard 1. Project Overview This project is an AI-powered Intelligent Traffic Monitoring System that automatically detects traffic violations using Computer Vision and sends real-time alerts through Telegram, Google Sheets, and IoT Cloud Dashboards. The system uses: ESP32 for IoT communication Camera for vehicle monitoring AI Computer Vision Model n8n Workflow Automation Telegram Voice Notifications Google Sheets Cloud Database ThingSpeak IoT Dashboard AI Analytics Agent Real-Time Monitoring Web Dashboard 2. Project Objectives The system automatically detects: ✅ Helmet Violations ✅ Triple Riding ✅ Wrong Side Driving ✅ Red Light Jumping ✅ Over Speeding ✅ Vehicle Counting ✅ Traffic Density Monitoring ✅ Accident Detection ✅ Emergency Vehicle Detection 3. System Architecture Traffic Camera │ ▼ Computer Vision AI Model │ ▼ Violation Detection Engine │ ▼ ESP32 IoT Gateway │ ▼ n8n Automation Server ├─────────────┐ ▼ ▼ ThingSpeak Google Sheets Dashboard Database │ ▼ Telegram Voice Alerts │ ▼ Traffic Control Authority 4. Hardware Components List Component Quantity ESP32 Dev Board 1 ESP32-CAM Module 1 OV2640 Camera 1 Traffic Signal LEDs 3 Buzzer 1 RFID Module (Optional) 1 Ultrasonic Sensor 1 Power Supply 5V 1 Jumper Wires As Required Breadboard 1 Router/WiFi Network 1 Laptop/PC 1 5. Software Requirements Programming Arduino IDE Python 3.11+ OpenCV YOLOv8 TensorFlow Flask Cloud Platforms Google Sheets ThingSpeak Telegram Bot n8n 6. Working Principle Step 1 Camera continuously captures road traffic. Step 2 Computer Vision model analyzes: Vehicle Bike Truck Bus Person Helmet Step 3 AI identifies traffic violations. Example: Bike detected Helmet = No Result: Helmet Violation Step 4 Violation data sent to ESP32. { "vehicle":"Bike", "violation":"Helmet Missing", "time":"10:30AM" } Step 5 ESP32 uploads data to: ThingSpeak Google Sheets n8n Step 6 n8n triggers Telegram Bot. Telegram sends: Traffic Alert Helmet Violation Detected Vehicle: Bike Location: Junction-1 Time: 10:30 AM Step 7 Text converted to voice message. Telegram Voice Alert: Attention. Helmet violation detected at Junction One. Please take action. 7. Circuit Diagram Connections ESP32-CAM OV2640 Camera │ ▼ ESP32-CAM Buzzer Buzzer + → GPIO13 Buzzer - → GND Traffic LEDs Red LED → GPIO14 Yellow LED → GPIO15 Green LED → GPIO2 All GND → Common GND 8. Flowchart START │ ▼ Capture Video Frame │ ▼ Run AI Detection │ ▼ Violation Found? │ ┌─No─┐ │ │ ▼ │ Next Frame │ └────┘ Yes │ ▼ Generate Event │ ▼ Send To ESP32 │ ▼ n8n Automation │ ▼ Google Sheets │ ▼ ThingSpeak │ ▼ Telegram Alert │ ▼ Voice Notification │ ▼ END 9. ESP32 Source Code #include #include const char* ssid = "YOUR_WIFI"; const char* password = "YOUR_PASSWORD"; String thingspeakKey="YOUR_API_KEY"; void setup() { Serial.begin(115200); WiFi.begin(ssid,password); while(WiFi.status()!=WL_CONNECTED) { delay(500); } } void loop() { float violations = random(0,10); HTTPClient http; String url = "http://api.thingspeak.com/update?api_key=" + thingspeakKey + "&field1=" + String(violations); http.begin(url); int code=http.GET(); http.end(); delay(15000); } 10. Python Computer Vision Code Install: pip install ultralytics opencv-python Code: from ultralytics import YOLO import cv2 model = YOLO("yolov8n.pt") cap = cv2.VideoCapture(0) while True: ret, frame = cap.read() results = model(frame) annotated = results[0].plot() cv2.imshow("Traffic Monitoring", annotated) if cv2.waitKey(1)==27: break 11. Google Sheets Integration Create Sheet: Traffic Violations Database Columns: Timestamp Vehicle Violation Location Use: Google Sheets Node inside n8n. Each violation creates a new row automatically. 12. ThingSpeak Dashboard Setup Create Channel Fields: Field 1: Violation Count Field 2: Traffic Density Field 3: Accident Alerts Field 4: Helmet Violations Field 5: Wrong Side Driving Dashboard shows: Real-Time Graphs Daily Reports Monthly Analytics 13. Telegram Bot Setup Create Bot Using: BotFather on Telegram Commands: /newbot Receive: BOT TOKEN Obtain Chat ID Send: /start to bot. Use chat ID in n8n. 14. n8n Workflow Design Workflow: Webhook Trigger │ ▼ IF Violation? │ ▼ Google Sheets Node │ ▼ ThingSpeak Update │ ▼ Telegram Message │ ▼ Text-To-Speech │ ▼ Telegram Voice 15. Sample n8n Workflow JSON Structure { "nodes":[ { "name":"Webhook" }, { "name":"Google Sheets" }, { "name":"Telegram" } ] } 16. AI Agent Analytics Module The AI Agent performs: Traffic Analysis Vehicle Count Peak Hours Traffic Density Violation Trends Predictive Analysis Expected Violations Tomorrow: 120 Next Week: 850 Smart Recommendations Increase Police Patrol Optimize Traffic Signals Deploy Additional Cameras 17. AI Power Consumption Prediction Logic Parameters: Camera Runtime ESP32 Runtime Network Usage Cloud Upload Frequency Prediction Formula: P=V×I Energy Consumption: E=P×t Example: Voltage = 5V Current = 0.5A Power = 2.5W 24 Hours Usage Energy = 60Wh 18. Telegram Voice Notification Automation Voice Generation Flow: Violation Detected │ ▼ n8n │ ▼ Google TTS │ ▼ MP3 Generation │ ▼ Telegram Voice Message Sample Voice: Attention Traffic Control. Helmet violation detected at Main Junction. Vehicle Number AP09AB1234. Immediate action required. 19. AI Web Dashboard Features Live Dashboard Displays: Vehicle Count Active Violations Traffic Density AI Predictions Camera Status ESP32 Status Charts Hourly Violations Daily Traffic Monthly Analytics Peak Congestion Analysis 20. Future Enhancements Phase 2 Automatic Number Plate Recognition (ANPR) Face Recognition Smart Signal Optimization Emergency Vehicle Priority Phase 3 Edge AI on ESP32-S3 AI Chatbot Assistant Mobile Application Digital Challan Generation Phase 4 Smart City Integration Multi-Camera Monitoring Centralized Command Center AI Traffic Forecasting Final Outcome This project delivers a complete Industry 4.0 AI Traffic Management Platform featuring: ✅ Computer Vision Traffic Violation Detection ✅ ESP32 IoT Monitoring & Connectivity ✅ AI Agent Analytics & Prediction ✅ n8n Workflow Automation ✅ Google Sheets Cloud Database ✅ ThingSpeak Real-Time Dashboard ✅ Telegram Text & Voice Alerts ✅ Cloud-Based Monitoring Dashboard ✅ Traffic Density & Vehicle Analytics ✅ Future-Ready Smart City Deployment Architecture The result is a scalable AI-powered smart traffic enforcement and monitoring system capable of real-time violation detection, automated reporting, cloud analytics, and intelligent decision support.

No comments:

Post a Comment

AI-Based Real-Time Air Pollution Monitoring and Prediction

AI-Based Real-Time Air Pollution Monitoring and Prediction System ESP32 + AI Agent + IoT Cloud + n8n Automation + Telegram Voice Alerts + Go...