Skip to content

vedantpawar15/Hospital-Digital-Twin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Hospital-Digital-Twin

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.


Features

  • 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
  • Ultrasonic patient presence (Emergency bed)
    • If distance < 5 cmPATIENT PRESENT
    • If distance ≥ 5 cmNO 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

Tech Stack

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

Repo Structure

  • frontend/ — Vite + React app (3D twin + Blynk integration)

Quick Start (Frontend)

1) Install dependencies

cd frontend
npm install

2) Configure Blynk (required for live hardware sync)

Create 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.cloud

If your Blynk region differs, change VITE_BLYNK_BASE_URL to your region host (example: https://fra1.blynk.cloud).

3) Run dev server

cd frontend
npm run dev

Open the URL shown in your terminal (typically http://localhost:5173).

Important: if you edit .env, restart npm run dev.


Hardware → Blynk Virtual Pin Mapping

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 V3 distance
  • Present if 0 < V3 < 5 cm

ESP Sketch Notes

Your sketch should:

  • Push sensor values to:
    • V0 temp, V1 humidity, V2 gas, V3 distance
  • Read LED command from:
    • V4 and 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.


Security

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

Troubleshooting

  • No live values showing
    • Ensure frontend/.env exists and has VITE_BLYNK_AUTH_TOKEN
    • Restart the dev server
    • Confirm VITE_BLYNK_BASE_URL matches your Blynk region (e.g., blr1)
  • LED toggles but sensor reads fail
    • Verify the region base URL
    • Check that the device is online and V0..V3 are being written from ESP

Demo Behavior

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

About

This project implements a real-time IoT-based digital twin of a hospital emergency ward, where sensor data from a physical setup is mirrored in a 3D virtual model, and control actions from the digital twin are reflected back onto the physical system using bidirectional communication.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors