Inspiration

What it does

How we built it

Challenges we ran into

Accomplishments that we're proud of

What we learned

⚡ ESP32 LabTwin — 2D Electronics Digital Twin & Circuit Simulator

Live Interactive Web App: https://esp32-wireless-simulator.netlify.app


💡 Inspiration

Every hardware engineer and student has faced the frustration of frying expensive components, debugging cryptic brownout resets, or spending weeks waiting for replacement parts. While software engineers enjoy instant CI/CD sandboxes and cloud environments, embedded systems engineers are still stuck in a slow, physical trial-and-error cycle.

Existing circuit simulators are either purely schematic-based (ignoring real microcontroller firmware execution) or focus only on simple single-board code emulation without true multi-physics, RF propagation, or thermal stress modeling.

We set out to build ESP32 LabTwin: a comprehensive, browser-based Digital Twin workbench where engineers can wire authentic components, write real Arduino C++ firmware across multiple ESP32 microcontrollers, simulate wireless RF mesh communication, and witness authentic multi-domain physics—from LED burnout to 6-DOF aircraft aerodynamic flight dynamics—before touching physical hardware.


🚀 What It Does

ESP32 LabTwin combines five engineering domains into a unified, high-performance web platform:

1. Visual Schematic & Breadboard Workbench

  • Interactive 2D drag-and-drop circuit canvas with orthogonal and Bezier smart wire routing.
  • Animated current-flow particles whose speed and direction are physically proportional to the calculated branch current.
  • Dynamic voltage-gradient wire coloring (GND Blue, 3.3V Yellow, 5V Orange, Battery Red).

2. Multi-Physics Circuit Simulation Engine

  • Solves Kirchhoff's Current and Voltage Laws in real-time using Modified Nodal Analysis (MNA): $$ \mathbf{G} \mathbf{v} = \mathbf{i} $$
  • Non-linear Shockley diode and LED forward-voltage drop with dynamic internal resistance.
  • Thermal dissipation & burnout physics: Computes junction temperature: $$ T_j = T_{amb} + P \cdot R_{\theta JA} $$ Triggering automatic thermal shutdown at $150^\circ\text{C}$ for linear regulators (AMS1117, LM7805).
  • Real-time educational fault detection: short circuits, brownout reset thresholds (2.43V), reverse polarity, floating input pins, and missing grounds.

3. In-Browser ESP32 C++ Firmware Runtime

  • Sandboxed execution of authentic Arduino-ESP32 code: pinMode, digitalWrite, digitalRead, analogRead (with non-linear 12-bit ADC transfer curves), ledc 16-channel PWM, Wire I2C register maps, and Serial UART.
  • Dual-MCU support allowing independent transmitter and receiver firmware running simultaneously.

4. Virtual 2.4GHz & Sub-GHz RF Wireless Network

  • Simulates ESP-NOW, NRF24L01, HC-05 Bluetooth, and SX1276 LoRa.
  • Uses the Log-Distance Path Loss Model to calculate dynamic RSSI and packet loss probability: $$ PL(d) = PL(d_0) + 10 \cdot n \cdot \log_{10}\left(\frac{d}{d_0}\right) + X_\sigma $$
  • Integrated RF Spectrum Analyzer & Packet Sniffer for real-time packet inspection.

5. 6-DOF Aerodynamic Physics & Sensor Fusion

  • Full aircraft flight dynamics calculating Lift, Drag, Thrust, Angle of Attack ($\alpha$), and Stall breakdown: $$ L = \frac{1}{2} \rho v^2 S C_L(\alpha), \quad D = \frac{1}{2} \rho v^2 S C_D(\alpha) $$
  • Virtual MPU-6050 IMU mounted to the airframe outputs real-time accelerometer and gyroscope registers with realistic sensor noise and drift, enabling closed-loop PID flight stabilization.

6. Full Virtual Lab Instruments

  • Digital Multimeter (DMM): DCV, ACV, Current, Resistance, Continuity buzzer.
  • 4-Channel Digital Oscilloscope: 100 kSa/s with automated $V_{pp}$, $V_{rms}$, and frequency measurements.
  • 8-Channel Logic Analyzer: Built-in I2C and UART protocol decoders.
  • Serial Monitor: Bi-directional interactive console.

🛠️ How We Built It

  • Frontend & UI: Built with React 18, TypeScript, Tailwind CSS, and HTML5 Canvas / SVG for crisp, 60 FPS rendering of wires, animated particles, and instrumentation.
  • Circuit Matrix Engine: Developed an in-browser Modified Nodal Analysis (MNA) solver in TypeScript that constructs dynamic conductance matrices, handles voltage sources, and iteratively solves non-linear branch currents.
  • C++ Firmware Sandbox: Created a custom AST and tokenized C++ interpreter supporting Arduino core libraries, FreeRTOS multi-tasking stubs, and hardware peripheral registers.
  • Aero & RF Physics Engines: Implemented rigid-body 6-DOF equations of motion (Euler angles, body-rate angular momentum) and logarithmic RF wave attenuation formulas.
  • Testing & Reliability: Built a test suite with 84 unit and integration tests in Vitest covering electrical edge cases, wireless packet loss, security sandboxing, and physics robustness.

🚧 Challenges We Ran Into

  1. Non-Linear Circuit Convergence in JavaScript: Solving non-linear components (like LEDs and voltage regulators) alongside high-frequency PWM signals without lagging the UI required optimizing our iterative MNA solver to converge in under 1ms per frame.
  2. Deterministic Multi-MCU Timing: Coordinating two independent virtual ESP32 chips exchanging ESP-NOW packets while keeping the circuit solver, sensor I2C reads, and 6-DOF physics loop synchronized in a single-threaded browser runtime.
  3. Safe In-Browser C++ Execution: Sandboxing user-written C++ code to prevent infinite loops, buffer overruns, and security escapes while preserving authentic Arduino syntax.

🏆 Accomplishments We're Proud Of

  • True Closed-Loop Feedback: A user can write PID firmware on one ESP32, send pitch commands over virtual ESP-NOW to a second ESP32 on a virtual plane, read virtual MPU6050 I2C registers, and see the plane actively stabilize in real time!
  • 12 Ready-to-Run Digital Twin Projects: Preloaded labs ranging from simple LED resistors and ultrasonic distance meters to 4-DOF robotic arms and RC flight simulators.
  • 84 / 84 Passing Unit Tests: Ensuring robust electrical, physical, and wireless correctness.

📚 What We Learned

  • The mathematical intricacies of Modified Nodal Analysis (MNA) and matrix formulation for mixed passive/active electronic networks.
  • How to model real-world semiconductor limitations in code—such as internal battery resistance ($R_i$), voltage regulator thermal headroom, and ADC non-linearities.
  • Aerodynamic stability derivatives and how sensor noise directly influences PID control loop tuning.

🔮 What's Next for ESP32 LabTwin

  • WebAssembly (Wasm) Clang Toolchain: Compiling native ESP-IDF C++ directly to Wasm for 100% standard library parity.
  • Multiplayer Collaborative Lab: Allowing student-teacher pairs to wire circuits and debug code in real time over WebSockets.
  • 1-Click Hardware Export: Automatically generating Gerber PCB files, KiCad schematics, and BOM purchase carts for physical manufacturing.

What's next for ESP32 LabTwin: 2D Digital Twin & Circuit Simulator

Built With

Share this project:

Updates

Submission history