Microduck Robot●microduck-robot.com

ESP32 servo simulator

A classic ESP32 runs real Arduino firmware right in your browser: four servos, two LEDs, a buzzer, a button, a potentiometer, an HC-SR04 distance sensor, a 128×64 OLED screen and a serial monitor you can type into. Pick an example, change its numbers, or upload the .bin you compiled in the Arduino IDE.

  1. Pick an example
  2. Power on the ESP32
  3. Play with the button and the knob
ESP32 WROOM-32 EN BOOT PWR IO2 4516181921222527323334 Hold GPIO27 GPIO34 · 2048 GPIO4 + GPIO25 100 cmHC-SR04 · 5/16 OLED · 32/33 SG90Servo 1 – SG90Servo 2 – SG90Servo 3 – SG90Servo 4 – ESP32 WROOM-32 EN BOOT PWR IO2 4516181921222527323334 Hold GPIO27 GPIO34 · 2048 GPIO4 + GPIO25 100 cmHC-SR04 · 5/16 OLED · 32/33 SG90Servo 1 – SG90Servo 2 – SG90Servo 3 – SG90Servo 4 –

🏁 Challenges

Serial monitor (115200 baud)


          

Inputs

Hold it down. Pressed, the pin reads LOW.
analogRead(34) returns this value, 0 to 4095.
Beyond 400 cm the sensor gets no echo.
Signal details (PWM)
GPIOFrequencyPulseAngle

Angle assumes a servo that turns 0–180° for 500–2500 µs, the ESP32Servo default.

Run your own firmware

In the Arduino IDE choose the board "ESP32 Dev Module", then Sketch > Export Compiled Binary. Upload the *.ino.merged.bin (complete image) or the *.ino.bin (program only). Your file stays in your browser.
or drop it here

Example code

Change the numbers in the yellow boxes, then press "Run with my numbers". The page writes them into the compiled program, so you see the effect without compiling.

// sweep4: four servos sweep smoothly back and forth, each offset along the cycle.// Servos on GPIO18, 19, 21, 22 (ESP32Servo, 500-2500 us = 0-180 degrees).#include <ESP32Servo.h>#include "MDParams.h" enum { SWEEP_PERIOD_MS, SWEEP_MIN_DEG, SWEEP_MAX_DEG, PHASE_STEP_PCT };MD_PARAMS(4,  {"SWEEP_PERIOD_MS", , 500, 20000},   // one full back-and-forth sweep  {"SWEEP_MIN_DEG", , 0, 180},  {"SWEEP_MAX_DEG", , 0, 180},  {"PHASE_STEP_PCT", , 0, 100});    // how far along the cycle each next servo is const int SERVO_PINS[4] = {18, 19, 21, 22};Servo servos[4];int angles[4]; void setup() {  Serial.begin(115200);  for (int i = 0; i < 4; i++) {    servos[i].setPeriodHertz(50);              // standard 50 Hz servo signal    servos[i].attach(SERVO_PINS[i], 500, 2500);  }  Serial.println("sweep4 ready");} void loop() {  static unsigned long lastPrint = 0;  unsigned long now = millis();  float lo = PARAM(SWEEP_MIN_DEG), hi = PARAM(SWEEP_MAX_DEG);  for (int i = 0; i < 4; i++) {    float phase = fmod((float)now / PARAM(SWEEP_PERIOD_MS) + i * PARAM(PHASE_STEP_PCT) / 100.0, 1.0);    // cosine ease: slow at both ends, fastest in the middle    angles[i] = (int)(lo + (hi - lo) * (1 - cos(2 * PI * phase)) / 2);    servos[i].write(angles[i]);  }  if (now - lastPrint >= 1000) {                // report once per second    lastPrint = now;    Serial.printf("angles: %d %d %d %d\n", angles[0], angles[1], angles[2], angles[3]);  }  delay(20);                                    // one update per servo frame}

How the simulator works

The ESP32 is emulated instruction by instruction in WebAssembly inside your browser: its dual-core processor, boot ROM, flash, LEDC PWM, GPIO, ADC and serial port. It runs the same binary you would flash onto a real board, so what you see is what your code does.

Servo positions come from the PWM the firmware sets on the LEDC peripheral: frequency and pulse width, read from the simulated registers. The angle shown is the target the pulse asks for, not a measured load, speed or torque.

Nothing is uploaded. Examples and your own .bin run in a background worker in this tab, in real time, and stop when you leave the page.

Questions

Can I simulate my own ESP32 code here?

Yes. Change the numbers in the yellow boxes of an example and run it, or compile your own sketch in the Arduino IDE for "ESP32 Dev Module", choose Sketch > Export Compiled Binary and upload the .bin. Writing new code and compiling it in the page is not available yet.

Which pins and parts are simulated?

Four servos on GPIO18, 19, 21 and 22, the blue on-board LED on GPIO2, an external LED on GPIO4, a buzzer on GPIO25, a button on GPIO27, a potentiometer on GPIO34, an HC-SR04 distance sensor (TRIG GPIO5, ECHO GPIO16), a 128×64 SSD1306 OLED on I2C (GPIO32 and 33), and the serial monitor at 115200 baud in both directions. Wi-Fi and Bluetooth are not simulated.

Which ESP32 boards does it support?

The classic ESP32 (ESP32-D0WD, as on the ESP32 DevKitC and "ESP32 Dev Module") with 4 MB flash. Files built for the ESP32-S2, S3, C3 or other chips are refused.

How accurate is the servo signal?

In our tests the simulated pulse widths matched what the firmware set to within 1 µs at 50 Hz, for four channels at once, and changes on one channel did not affect the others. Real servos add their own dead band and speed limit.

Emulator: esp32sim (MIT) with our PWM and ADC patch; ESP32 ROM from Espressif (Apache-2.0). Examples built with Arduino-ESP32 3.3.8 and ESP32Servo. Licences and versions are listed in the notices file. Third-party notices

Simulators and tools → Bus servo command tool → Wiring guide →

Contact us