A 3D digital twin of a small hospital layout (ICU / OT / Ward / Emergency) built with React + Three.js that connects to real hardware using ESP (Blynk Cloud).
The current hardware scope is one LED and one ultrasonic distance sensor, integrated bidirectionally with the Emergency ward in the 3D twin.
- 3D hospital twin (React Three Fiber + Drei)
- Room lighting (Emergency) linked to hardware bidirectionally
- Toggle in 3D → updates Blynk
V4→ ESP turns LED ON/OFF - Toggle LED widget in Blynk / physical state → 3D Emergency room updates
- Toggle in 3D → updates Blynk
- Ultrasonic patient presence (Emergency bed)
- If distance < 5 cm → PATIENT PRESENT
- If distance ≥ 5 cm → NO PATIENT
- Presence is visualized in the 3D label and the ultrasonic beam
- Live sensor dashboard in the UI (large stat cards)
- Temperature, Humidity, Gas (MQ), Distance
- Camera controls
- Left-drag: pan
- Right-drag: orbit
- Scroll: zoom
- WASD: move on the ground plane
- Frontend: Vite + React
- 3D:
three,@react-three/fiber,@react-three/drei - IoT Cloud: Blynk Cloud (HTTP API)
- Hardware: ESP (Blynk + DHT11 + MQ analog + Ultrasonic + LED)
frontend/— Vite + React app (3D twin + Blynk integration)
cd frontend
npm installCreate frontend/.env (or copy from frontend/.env.example) and set:
VITE_BLYNK_AUTH_TOKEN=YOUR_BLYNK_AUTH_TOKEN
VITE_BLYNK_BASE_URL=https://blr1.blynk.cloudIf your Blynk region differs, change
VITE_BLYNK_BASE_URLto your region host (example:https://fra1.blynk.cloud).
cd frontend
npm run devOpen the URL shown in your terminal (typically http://localhost:5173).
Important: if you edit
.env, restartnpm run dev.
The frontend reads these virtual pins from Blynk:
| Virtual Pin | Meaning |
|---|---|
V0 |
Temperature (°C) |
V1 |
Humidity (%) |
V2 |
Gas sensor (MQ raw) |
V3 |
Ultrasonic distance (cm) |
V4 |
LED control (0/1) |
Bidirectional control implemented:
- Write: 3D Emergency light → updates Blynk
V4 - Read: Blynk
V4→ updates 3D Emergency light
Patient presence logic:
- Uses
V3distance - Present if
0 < V3 < 5cm
Your sketch should:
- Push sensor values to:
V0temp,V1humidity,V2gas,V3distance
- Read LED command from:
V4and set the physical LED pin accordingly
If you're using an ESP8266 (as in your code), includes like ESP8266WiFi.h and BlynkSimpleEsp8266.h are correct.
- Do not commit your Blynk Auth Token or Wi‑Fi credentials.
- Keep them in
frontend/.env(gitignored) and in your local Arduino/PlatformIO settings. - If you ever shared a token publicly, regenerate it in Blynk.
- No live values showing
- Ensure
frontend/.envexists and hasVITE_BLYNK_AUTH_TOKEN - Restart the dev server
- Confirm
VITE_BLYNK_BASE_URLmatches your Blynk region (e.g.,blr1)
- Ensure
- LED toggles but sensor reads fail
- Verify the region base URL
- Check that the device is online and
V0..V3are being written from ESP
- Emergency room includes an ultrasonic ceiling sensor and beam.
- The Emergency label shows:
- ACTIVE/STANDBY (room light state)
- PATIENT PRESENT/NO PATIENT (from distance threshold)