ESP32
What you’ll learn
- What makes the ESP32 different from an Arduino UNO
- How to program it in the Arduino IDE or MicroPython
- The 3.3 V rule
The ESP32
| Arduino UNO R3 | ESP32 (typical dev board) | |
|---|---|---|
| Processor | 8-bit, 16 MHz | 32-bit, up to 240 MHz, often dual-core |
| Memory | 2 KB RAM | Hundreds of KB of RAM |
| Wi-Fi / Bluetooth | No | Yes |
| Logic voltage | 5 V | 3.3 V |
| Price | ~$20 (clones less) | ~$5–10 |
Programming it
- Arduino IDE: install the esp32 boards package (Boards Manager), pick your board, and most Arduino code works.
- MicroPython: flash MicroPython firmware and write Python.
The 3.3 V rule
Robot uses
- A web page or phone app to drive the robot over Wi-Fi
- Bluetooth gamepad control
- Sending sensor data to a laptop for logging
Example: a tiny Wi-Fi web server
#include <WiFi.h>#include <WebServer.h>
WebServer server(80);
void setup() { Serial.begin(115200); WiFi.begin("your-network", "your-password"); while (WiFi.status() != WL_CONNECTED) delay(200); Serial.println(WiFi.localIP()); // open this address in a browser server.on("/", [] { server.send(200, "text/html", "<h1>Hello from the robot</h1>"); }); server.on("/go", [] { /* start motors */ server.send(200, "text/plain", "going"); }); server.begin();}
void loop() { server.handleClient(); }Example: a 5 V sensor on a 3.3 V pin
HC-SR04 ECHO → 1 kΩ → ESP32 pin, and from the ESP32 pin → 2 kΩ → GND. This divider brings 5 V down to about 3.3 V.
Try it in a virtual ESP32
Press Start simulator and replace sketch.ino with this, then press ▶ and watch the Serial Monitor.
void setup() { Serial.begin(115200); Serial.println("Hello from the ESP32!");}
void loop() { Serial.print("Uptime (s): "); Serial.println(millis() / 1000); delay(1000);}Runs on Wokwi, free, no account needed.
CompareEasy
List three advantages and one danger of the ESP32 compared with an UNO. Advantages: Wi-Fi/Bluetooth, much faster, more memory (also cheaper). Danger: 3.3 V pins can be damaged by 5 V signals.
Faster printsMedium
Print the uptime every 250 ms in milliseconds.
Print millis() directly and use delay(250).
Divider for ECHOHard
Design a voltage divider to bring a 5 V ECHO signal to at most 3.3 V. 1 kΩ on top, 2 kΩ to GND: 5 × 2/3 ≈ 3.33 V. (Or 10 kΩ / 20 kΩ.)
Quick check
Finished this lesson?