Skip to content

yashg2006/SmartCity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

17 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ›๏ธ UrbanPulse โ€” Smart City Infrastructure Portal

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


๐Ÿš€ Getting Started

Follow these step-by-step instructions to get the complete UrbanPulse Smart City system running on your local machine.

๐Ÿ“‹ Prerequisites

Ensure you have the following installed:

  1. Node.js (v18 or higher) โ€” Download
  2. Python 3.9+ โ€” Download
  3. MongoDB Community Server โ€” Download
  4. Arduino IDE 2.x โ€” Download
  5. YOLOv8 Weights โ€” Ensure best.pt is in ml_server/weights/ (or your configured model path)

๐Ÿ› ๏ธ Step 1: ML Server Setup (Python)

The ML server handles vision analysis and risk fusion.

  1. Open a terminal in the ml_server directory:
    cd ml_server
  2. Create and activate a virtual environment:
    python -m venv venv
    # On Windows:
    .\venv\Scripts\activate
    # On Mac/Linux:
    source venv/bin/activate
  3. Install dependencies:
    pip install -r requirements.txt
  4. Start the ML server:
    python main.py
    The ML server will run on http://localhost:8000.

๐Ÿ’ป Step 2: Backend Setup (Node.js)

The backend manages sensor data, database storage, and real-time updates.

  1. Open a terminal in the backend directory:
    cd backend
  2. Install dependencies:
    npm install
  3. Ensure your MongoDB service is running locally (mongodb://localhost:27017).
  4. Start the backend:
    npm start
    # Or for development:
    node server.js
    The backend will run on http://localhost:3000.

๐ŸŽจ Step 3: Frontend Setup (React + Vite)

The dashboard provides a real-time visualization of all smart city systems.

  1. Open a terminal in the frontend directory:
    cd frontend
  2. Install dependencies:
    npm install
  3. Start the development server:
    npm run dev
    The dashboard will typically run on http://localhost:5173.

๐Ÿ“Ÿ Step 4: ESP32 Hardware Firmware

The ESP32 collects data from DHT11, Sound, PIR, and Ultrasonic sensors.

  1. Open esp32_smartcity/esp32_smartcity.ino in the Arduino IDE.
  2. Install Required Libraries:
    • WiFiS3 (for Arduino R4 WiFi)
    • ArduinoHttpClient
    • ArduinoJson
    • DHT sensor library
    • LiquidCrystal I2C
    • TinyGPS++
  3. Configure Network:
    • Update ssid and pass with your WiFi credentials.
    • Update serverAddress with your laptop's local IP address.
  4. Connect your ESP32 and click Upload.

๐Ÿ Verification Order

To ensure everything works correctly, start services in this order:

  1. MongoDB (Database)
  2. ML Server (Python)
  3. Backend (Node.js)
  4. Frontend (React)
  5. ESP32 (Hardware)

๐ŸŒŸ Features

๐ŸฆŸ Mosquito Swarm Detection & AI-Fusion Risk Scoring [NEW]

  • 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 Drainage Monitoring

  • 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

๐Ÿ—‘๏ธ Garbage Detection & Citizen Reporting

  • 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)

๐Ÿ—๏ธ Tech Stack

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

๐Ÿ“‚ Project Structure

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

๐Ÿ“ก ESP32 / Arduino Integration

1. Pushing Sensor Data

Your ESP32 should POST sensor data to the backend: POST http://<SERVER_IP>:3000/api/sensors/data

Payload Format

{
  "nodeId": "MOSQUITO-NODE-01",
  "zone": "Sector 4A",
  "temp": 28.5,
  "humid": 65.0,
  "sound": 450,
  "motion": true
}

2. Polling for AI Risk Reports

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

Response Format

{
  "mlResult": "CRITICAL SWARM",
  "riskScore": 92
}

๐Ÿ”‘ Key API Endpoints

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

๐Ÿง  Smart City Logic

๐ŸฆŸ Mosquito Breeding Risk (Fusion)

  • 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 Drainage System

  • Water Sensor (WET) + Low drainDistance โ†’ HIGH FLOW โšก

๐Ÿ—‘๏ธ Garbage Bin System

  • FillPercent > 85% โ†’ CRITICAL OVERFLOW ๐Ÿ”ด

๐Ÿ“„ License

This project is built for the Smart City Hackathon โ€” Digital India Initiative.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors