An intelligent IoT-based urban traffic monitoring and congestion prediction system that leverages computer vision, edge computing, and real-time data analytics to provide comprehensive traffic insights for smart cities.
UrbanPulse is a complete IoT ecosystem designed to monitor urban traffic conditions in real-time. The system captures images from ESP32-CAM devices, processes them using machine learning models for vehicle detection and congestion analysis, and provides real-time traffic updates through a mobile application.
The project consists of four main components working together:
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β β β β β β
β IoT Devices βββββΆβ Edge Gateway βββββΆβ Cloud Backend βββββΆβ Mobile App β
β (ESP32-CAM) β β (BLE Client) β β (ML + API) β β (React Native)β
β β β β β β β β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
- Platform: ESP32-CAM with AI-Thinker module
- Technology: Arduino C++, PlatformIO
- Features:
- High-quality image capture
- Bluetooth Low Energy (BLE) communication
- Authentication system for secure access
- Power management and camera reset functionality
- Technology: Python with asyncio and BLE
- Features:
- BLE communication with ESP32 devices
- Image preprocessing and optimization
- Local caching and batch processing
- Multi-device management support
- Technology: Flask, ONNX Runtime, OpenCV
- Features:
- YOLOv5 vehicle detection model
- Real-time congestion analysis
- Accident detection algorithms
- Google Cloud Storage integration
- PostgreSQL database connectivity
- Technology: Node.js, Express, PostgreSQL
- Features:
- RESTful API for traffic data
- Real-time status updates
- News and alerts management
- Google Cloud SQL integration
- Technology: React Native, Expo
- Features:
- Real-time traffic status visualization
- Interactive charts and statistics
- Traffic news and alerts
- Multi-city support
- Responsive design with custom themes
- Node.js (v18+)
- Python (3.8+)
- PlatformIO CLI
- Google Cloud SDK
- Expo CLI
- PostgreSQL
-
Hardware Requirements:
- ESP32-CAM AI-Thinker module
- MicroSD card (optional)
- Power supply (5V)
-
Installation:
cd Device pio run -t upload
-
Install dependencies:
cd Edge pip install -r requirements.txt -
Configure environment:
cp .env.example .env # Edit .env with your configuration -
Run the gateway:
python main.py
-
Setup:
cd Cloud/cloud-run-service pip install -r requirements.txt -
Deploy to Google Cloud Run:
gcloud run deploy urbanpulse-ml \ --source . \ --platform managed \ --region europe-southwest1
-
Setup:
cd Cloud/UrbanPulse-backend npm install -
Deploy:
gcloud run deploy urbanpulse-api \ --source . \ --platform managed \ --region europe-southwest1
-
Install dependencies:
cd UrbanPulse npm install -
Start development server:
npm start
-
Run on device:
npm run android # For Android npm run ios # For iOS
The system uses a custom-trained YOLOv5 model for vehicle detection with the following capabilities:
- Vehicle Detection: Cars, trucks, motorcycles
- Congestion Analysis: Real-time traffic density calculation
- Accident Detection: Unusual vehicle patterns and collisions
- Traffic Flow: Movement analysis and predictions
- Classes: Vehicle types (cars, trucks, motorcycles)
- Input: 640x640 RGB images
- Format: ONNX for cross-platform compatibility
- Inference: Real-time processing on CPU/GPU
GET /traffic/status- Current traffic conditionsGET /traffic/news- Traffic news and alertsPOST /upload- Image upload and processing
GET /health- Service health check
# Cloud ML Service
BUCKET_NAME=your-gcs-bucket
MODEL_PATH=app/yolov5su.onnx
DB_HOST=your-cloud-sql-instance
DB_USER=your-db-user
DB_PASS=your-db-password
DB_NAME=urbanpulse
# Backend API
NODE_ENV=production
DB_HOST=your-cloud-sql-instance
DB_USER=your-db-user
DB_PASS=your-db-password
DB_NAME=urbanpulse
# Mobile App
REACT_APP_BACKEND_URL=https://your-api-domain.comCurrently deployed in:
- Sant Cugat del Vallès (Catalonia, Spain)
- Monitoring locations:
- AP-7 (Km 230, Km 200)
- Rotonda Pere I
- C/ Costa i Llobera
- β Live traffic status updates
- β Vehicle counting and classification
- β Congestion level analysis (Fluid/Dense/Stopped)
- β Accident detection and alerts
- β Historical traffic patterns
- β Peak hours analysis
- β Traffic flow predictions
- β Statistical reporting
- β Intuitive mobile interface
- β Real-time notifications
- β Interactive charts and graphs
- β Multi-language support
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- University: Universitat AutΓ²noma de Barcelona (UAB)
- Course: IoT Systems and Applications
- YOLOv5: Ultralytics for the base detection model
- Google Cloud: Infrastructure and ML services
- Expo: React Native development platform
Project Team: JG03dev Institution: Universitat AutΓ²noma de Barcelona (UAB)
