A real-time bridge connecting Arduino-based mining safety sensors to a cloud-hosted FastAPI backend via WebSocket.
Arduino UNO
│
│ USB Serial
▼
Laptop
│
│ Python Sensor Bridge
▼
Render FastAPI
│
│ WebSocket
▼
Web Dashboard
https://drive.google.com/drive/folders/1Thhx-196MS_y5KyWBvx8XwMBEpddcZnx
https://engineer-day-2026-backend.onrender.com/
The Sensor Bridge is responsible for:
- 📥 Reading real-time sensor data from the Arduino Serial/COM port
- 🧩 Parsing the incoming JSON payload
- ☁️ Transmitting processed data to the Render FastAPI WebSocket endpoint
- 🔁 Maintaining a continuous, robust loop between hardware and the cloud backend
The Arduino must transmit one valid JSON object per line:
{
"temp": 28.0,
"gas": 125,
"fire": 0,
"sos": 0,
"warning": 0,
"danger": 0,
"fan": 0
}| Field | Type | Description |
|---|---|---|
temp |
float | Ambient temperature (°C) |
gas |
int | Gas concentration level |
fire |
0/1 | Fire detection flag |
sos |
0/1 | Manual SOS trigger |
warning |
0/1 | Warning threshold flag |
danger |
0/1 | Danger threshold flag |
fan |
0/1 | Ventilation fan status |
1. Clone the repository and navigate to the project folder
git clone https://github.com/kvinitkarmkar/sensor-bridge
cd sensor-bridge2. Create and activate a virtual environment
python -m venv venv- Windows
venv\Scripts\activate
- macOS / Linux
source venv/bin/activate
3. Install dependencies
pip install -r requirements.txtCreate a .env file in the root directory:
ARDUINO_PORT=COM6
BAUD_RATE=9600
BACKEND_WS_URL=wss://engineer-day-2026-backend.onrender.com/ws
SERIAL_TIMEOUT=1Note: Replace
COM6with the port assigned to your Arduino UNO. On Linux/macOS, use something like/dev/ttyUSB0or/dev/ACM0.
python main.py============================================================
Underground Mines Safety System - Sensor Bridge
============================================================
[SERIAL] Connected to Arduino on COM6 @ 9600 baud
[WS] Connected to backend: wss://engineer-day-2026-backend.onrender.com/ws
[SYSTEM] Sensor bridge started.
[SYSTEM] Waiting for Arduino data...
[ARDUINO] Received: {'temp': 28.0, 'gas': 125, 'fire': 0, ...}
[WS] Sent: {"temp": 28.0, "gas": 125, "fire": 0, ...}
Sensor
↓
Arduino UNO
↓
USB Serial
↓
serial_reader.py
↓
main.py
↓
websocket_client.py
↓
Render FastAPI WebSocket
- Port Conflict: Do not run the Arduino IDE Serial Monitor while the Sensor Bridge is running — most operating systems allow only one application to access a COM port at a time.
- Security: Never commit your
.envfile to GitHub. Make sure it's listed in.gitignore.
- Hardware: Arduino UNO
- Bridge: Python (
pyserial,websockets/websocket-client) - Backend: FastAPI (deployed on Render)
- Transport: USB Serial → WebSocket