Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Smart Emergency Route Monitor

A real-time web application that connects to Arduino ultrasonic sensors to detect obstacles and automatically switch emergency routes on a map.

Features

  • Real-time serial port communication with Arduino (COM6, 9600 baud)
  • Automatic route switching based on obstacle detection
  • Live distance monitoring
  • Interactive OpenStreetMap integration with animated routes (using Leaflet.js)
  • Visual and audio alerts for blocked routes
  • Data logging to Supabase database
  • Responsive dashboard with connection status
  • No API keys required for maps

Prerequisites

  • Node.js (v18 or higher)
  • Arduino device connected to COM6
  • Supabase account (already configured)

Arduino Setup

Your Arduino should send:

  • "BLOCK_DETECTED" - When obstacle is detected
  • "CLEAR_ROUTE" - When route is clear

Example Arduino code:

void setup() {
  Serial.begin(9600);
}

void loop() {
  int distance = measureDistance(); // Your sensor logic

  if (distance < 20) {
    Serial.println("BLOCK_DETECTED");
    Serial.println(distance);
  } else {
    Serial.println("CLEAR_ROUTE");
    Serial.println(distance);
  }

  delay(1000);
}

Installation

  1. Install dependencies:
npm install
  1. Configure environment variables in .env:
VITE_SUPABASE_URL=your_supabase_url
VITE_SUPABASE_ANON_KEY=your_supabase_key

Running the Application

  1. Start the backend server (in one terminal):
npm run server
  1. Start the frontend (in another terminal):
npm run dev
  1. Open your browser and navigate to http://localhost:5173

How It Works

  1. Backend Server (server.js):

    • Connects to Arduino via COM6 at 9600 baud
    • Listens for "BLOCK_DETECTED" and "CLEAR_ROUTE" messages
    • Emits real-time events via Socket.io
    • Logs status changes to Supabase
  2. Frontend Dashboard:

    • Displays live connection status
    • Shows current route status (CLEAR/BLOCKED)
    • Displays distance readings from sensor
    • Updates map with appropriate route
  3. Map System:

    • OpenStreetMap with Leaflet.js
    • Route A: Normal shortest route (green)
    • Route B: Alternate route (red)
    • Automatically switches based on obstacle detection
    • Animated ambulance marker
    • Centered on Chennai, India (13.0827, 80.2707)

System Architecture

Arduino (COM6)
    ↓
Node.js Backend (Express + Socket.io)
    ↓
React Frontend (Vite + Tailwind)
    ↓
OpenStreetMap (Leaflet.js) + Supabase Database

API Endpoints

  • GET /api/status - Returns current system status

Socket Events

  • connection_status - Serial port connection status
  • route_status - Route status updates (CLEAR/BLOCKED)
  • distance_update - Distance sensor readings

Database Schema

The application logs all route status changes to Supabase:

route_status_logs table:

  • id (uuid)
  • status (text: 'CLEAR' or 'BLOCKED')
  • distance (integer)
  • timestamp (timestamptz)
  • created_at (timestamptz)

Troubleshooting

Serial port not connecting:

  • Verify Arduino is connected to COM6
  • Check Arduino is using 9600 baud rate
  • Ensure no other applications are using the serial port

Map not showing:

  • Check browser console for errors
  • Ensure internet connection (for OpenStreetMap tiles)
  • Verify Leaflet CSS is loading properly

No data logging:

  • Verify Supabase credentials in .env
  • Check database migration was applied
  • Review server console for errors

Technology Stack

  • Frontend: React, TypeScript, Vite, Tailwind CSS
  • Backend: Node.js, Express, Socket.io
  • Hardware: Arduino, SerialPort
  • Database: Supabase (PostgreSQL)
  • Maps: OpenStreetMap with Leaflet.js
  • Icons: Lucide React

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages