A real-time IoT-powered Smart City monitoring platform for Water Drainage Management, Garbage Detection, and AI-Powered Mosquito Swarm Detection, built with React + Express + MongoDB + AI (YOLOv8).
๐ฎ๐ณ Digital India Initiative โ Department of Urban Planning
Follow these step-by-step instructions to get the complete UrbanPulse Smart City system running on your local machine.
Ensure you have the following installed:
- Node.js (v18 or higher) โ Download
- Python 3.9+ โ Download
- MongoDB Community Server โ Download
- Arduino IDE 2.x โ Download
- YOLOv8 Weights โ Ensure
best.ptis inml_server/weights/(or your configured model path)
The ML server handles vision analysis and risk fusion.
- Open a terminal in the
ml_serverdirectory:cd ml_server - Create and activate a virtual environment:
python -m venv venv # On Windows: .\venv\Scripts\activate # On Mac/Linux: source venv/bin/activate
- Install dependencies:
pip install -r requirements.txt
- Start the ML server:
The ML server will run on http://localhost:8000.
python main.py
The backend manages sensor data, database storage, and real-time updates.
- Open a terminal in the
backenddirectory:cd backend - Install dependencies:
npm install
- Ensure your MongoDB service is running locally (
mongodb://localhost:27017). - Start the backend:
The backend will run on http://localhost:3000.
npm start # Or for development: node server.js
The dashboard provides a real-time visualization of all smart city systems.
- Open a terminal in the
frontenddirectory:cd frontend - Install dependencies:
npm install
- Start the development server:
The dashboard will typically run on http://localhost:5173.
npm run dev
The ESP32 collects data from DHT11, Sound, PIR, and Ultrasonic sensors.
- Open
esp32_smartcity/esp32_smartcity.inoin the Arduino IDE. - Install Required Libraries:
WiFiS3(for Arduino R4 WiFi)ArduinoHttpClientArduinoJsonDHT sensor libraryLiquidCrystal I2CTinyGPS++
- Configure Network:
- Update
ssidandpasswith your WiFi credentials. - Update
serverAddresswith your laptop's local IP address.
- Update
- Connect your ESP32 and click Upload.
To ensure everything works correctly, start services in this order:
- MongoDB (Database)
- ML Server (Python)
- Backend (Node.js)
- Frontend (React)
- ESP32 (Hardware)
- DHT11 Sensor โ monitors temperature and humidity (key factors for breeding)
- Sound Sensor โ detects high-frequency mosquito buzzing sounds
- PIR Motion Sensor โ detects biological activity in potential breeding hotspots
- AI-Fusion Risk Scoring โ combines real-time hardware sensor data with YOLOv8 ML model vision input to calculate a precise breeding risk score (0-100)
- Hardware Alerts โ Live risk results and sensor readings displayed on local ESP32 LCD
- Interactive Heatmap โ Visualize mosquito hotspots across the city sectors
- Water Sensor (inside pipeline) โ detects if water is actively flowing through the pipe
- Ultrasonic Sensor (top of pipe, facing down) โ measures distance to water surface to calculate water level
- Combined Flow Diagnosis โ determines flow speed (fast/normal/slow/no flow) by combining both sensor readings
- Pipeline SVG Visualization โ live cross-section diagram showing water level, sensor positions, and flow direction
- Ultrasonic Sensor on Bin Lid โ measures distance to garbage surface; short distance = bin filling up
- Overflow Alerts โ critical alert when bin fill exceeds 85%
- Citizen Image Reporting โ citizens can capture/upload photos of garbage and submit reports directly to the Municipal Corporation
- Report Tracking โ all citizen reports are stored with status (Pending โ Acknowledged โ Resolved)
| Layer | Technology |
|---|---|
| Frontend | React 18 + Vite |
| Backend | Node.js + Express |
| ML Server | Python + Flask + YOLOv8 + OpenCV |
| Database | MongoDB + Mongoose |
| Real-time | Socket.IO |
| Hardware | ESP32 (R4 WiFi) + Sound Sensor + PIR + DHT11 + HC-SR04 + LCD I2C |
Smart_City project/
โโโ backend/
โ โโโ server.js # Express + Socket.IO server
โ โโโ routes/
โ โ โโโ sensors.js # Main sensor data handler
โ โ โโโ mosquito.js # Mosquito risk reports & analytics
โโโ ml_server/
โ โโโ main.py # YOLOv8 analysis & risk fusion engine
โ โโโ requirements.txt # ML dependencies (ultralytics, flask)
โโโ frontend/
โ โโโ src/
โ โ โโโ components/
โ โ โ โโโ MosquitoDetection.jsx # ๐ฆ Mosquito risk dashboard
โ โ โ โโโ WaterDrainage.jsx # ๐ง Water drainage monitoring
โ โ โ โโโ GarbageDetection.jsx # ๐๏ธ Garbage detection + reporting
โ โ โ โโโ Dashboard.jsx # ๐ Overview dashboard
โโโ esp32_smartcity/
โ โโโ esp32_smartcity.ino # ESP32 Firmware for all sensors
โโโ README.md
Your ESP32 should POST sensor data to the backend:
POST http://<SERVER_IP>:3000/api/sensors/data
{
"nodeId": "MOSQUITO-NODE-01",
"zone": "Sector 4A",
"temp": 28.5,
"humid": 65.0,
"sound": 450,
"motion": true
}The ESP32 polls the server to display the hardware/AI fusion result on the LCD:
GET http://<SERVER_IP>:3000/api/mosquito/latest-report?zone=Sector%204A
{
"mlResult": "CRITICAL SWARM",
"riskScore": 92
}| Method | Endpoint | Description |
|---|---|---|
POST |
/api/sensors/data |
Receive multi-sensor data from hardware |
GET |
/api/mosquito/latest-report |
Fetch latest AI+Hardware fusion risk report |
GET |
/api/sensors/nodes |
Get latest reading per node |
POST |
/api/sensors/report |
Submit citizen garbage report |
POST |
/api/auth/login |
Authentication |
- High Temp/Humidity (DHT11) + Buzzing Sound (Analog) = Baseline Risk ๐
- Motion Detected (PIR) + AI Vision Match (YOLOv8) = Swarm Confirmed ๐ฅ
- Result: Visual Risk Indicator + Hardware Alert + Municipal Dispatch
Water Sensor (WET)+Low drainDistanceโ HIGH FLOW โก
FillPercent > 85%โ CRITICAL OVERFLOW ๐ด
This project is built for the Smart City Hackathon โ Digital India Initiative.