The ESP32 is the natural next step after the Arduino: much faster, with Wi-Fi and Bluetooth, and a similar price. It's the basis of most smart home and IoT projects. But there are a few important differences you need to know before you start, and most beginners' problems come from exactly these differences.
ESP32 or Arduino Uno?
| Arduino Uno | ESP32 DevKit | |
|---|---|---|
| Speed | 16 MHz | up to 240 MHz, dual core |
| RAM | 2 KB | about 520 KB |
| Wi-Fi and Bluetooth | none | both built in |
| Pin voltage | 5 V | 3.3 V |
| ADC | 10 bits | 12 bits (but less linear) |
| Comfortable pin current | about 20 mA | about 20 mA |
So if the project needs internet, speed or memory, the ESP32 is the better fit. If it's a simple project with 5 V modules and you're learning, the Uno is easier with fewer pitfalls. The detailed comparison is in the what is a microcontroller article.
Board types you'll meet
- ESP32 DevKit (30 or 38 pins): the most common and cheapest, and the one this article covers.
- ESP32-C3: smaller and cheaper, single core, fewer pins. Good for simple sensors.
- ESP32-S3: more powerful, with native USB and no converter chip, suited to displays and cameras.
- ESP32-CAM: has a camera and an SD card slot, but no USB, so you upload code with a USB-to-serial adapter or a carrier board underneath.
Note that the pin layout differs between one DevKit and another even when they look the same. Go by the labels on your own board, not a picture from the internet.
1. Installing the board in the Arduino IDE
- File → Preferences, and in "Additional boards manager URLs" add the Espressif ESP32 boards URL (it's in their official documentation).
- Boards Manager → search for esp32 and install it.
- Choose the board, most commonly ESP32 Dev Module, and choose the port.
If the port doesn't appear, you probably need the CP210x or CH340 driver, depending on the chip on your board (its name is printed on the small chip next to the USB socket). If the driver is installed and the port still doesn't show, try another cable: many cables are charge-only and have no data wires.
First code: Blink
const int LED = 2; // the on-board LED on many DevKit boards
void setup() {
pinMode(LED, OUTPUT);
}
void loop() {
digitalWrite(LED, HIGH); delay(500);
digitalWrite(LED, LOW); delay(500);
}
If the LED doesn't light, either your board has its LED on a different pin, or it has no user LED at all. Connect an LED with a 220 Ω resistor to another pin and try that. The calculation is in the LED resistor article.
2. The most important difference: 3.3 V
The ESP32 runs at 3.3 V, and its pins aren't designed to tolerate 5 V. If you connect a module that outputs 5 V (such as the HC-SR04 sensor), bring the signal down with a voltage divider or a level shifter.
The reverse applies too: many modules made for 5 V (such as some LCD displays and relays) may not reliably read 3.3 V as HIGH. Check the datasheet, or use a module that runs on 3.3 V.
3. Pins to watch out for
- GPIO 6 to 11: connected to the flash memory inside the module. Don't use them.
- GPIO 34, 35, 36 and 39: input only, with no internal pull-up.
- GPIO 0, 2, 12 and 15: "strapping" pins that affect how the chip boots. If you attach something that pulls them to a particular level, the board may not boot or may not accept an upload. The most common case: something pulls GPIO 12 HIGH at power-up, and the board won't start at all.
- ADC2 doesn't work while Wi-Fi is on. Use ADC1 pins (32 to 39) for ADC readings.
- GPIO 1 and 3 are the serial line that talks to the computer. If you use them, uploading and the Serial Monitor get confused.
Safe pins to start with: 4, 5, 13, 14, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27, 32, 33. Keep 21 and 22 for I2C, since they're the default in most libraries.
4. A Wi-Fi connection that reconnects by itself
This code connects, tries again if the network drops later, and doesn't hang forever if the router isn't there:
#include <WiFi.h>
const char* SSID = "your_network";
const char* PASS = "your_password";
void connectWiFi() {
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, PASS);
unsigned long t0 = millis();
while (WiFi.status() != WL_CONNECTED && millis() - t0 < 15000) {
delay(500);
Serial.print(".");
}
Serial.println(WiFi.status() == WL_CONNECTED ? WiFi.localIP().toString() : "Connection failed");
}
void setup() {
Serial.begin(115200);
connectWiFi();
}
void loop() {
if (WiFi.status() != WL_CONNECTED) connectWiFi();
// the rest of the project goes here
delay(1000);
}
Open the Serial Monitor at 115200 and you'll see the board's IP address. If you see garbage characters, the Monitor speed isn't 115200. See the Serial Monitor article.
Notes: the ordinary ESP32 works on 2.4 GHz only, so if your router only broadcasts a 5 GHz network, the board won't see it. And remember the network name and password are case-sensitive.
5. The BOOT button
On some boards, uploading fails with a message like "Failed to connect". The fix: press the BOOT button and keep holding it as soon as "Connecting…" appears, then release it once the upload starts. If the problem happens a lot, a 10 µF capacitor between the EN pin and ground makes the board enter upload mode by itself in most cases.
The other button, EN (or RST), resets the board, which restarts the code from the beginning.
6. Power
When Wi-Fi transmits, it draws high current peaks (they can reach hundreds of milliamps). If the supply is weak, the board resets by itself, which is the well-known "brownout" problem: you'll see a message in the serial output containing "Brownout detector was triggered".
- Use a good USB cable, or a 5 V source that can deliver at least 500 mA.
- A capacitor of 100–470 µF close to the supply helps a lot.
- If you power it externally, connect 5 V to the 5V/VIN pin (which goes through the on-board regulator), or a steady 3.3 V to the 3V3 pin. Never put 5 V on the 3V3 pin.
- If it runs on a battery, use deep sleep. Details are in the ESP32 deep sleep article.
Note that the DevKit board itself (with its regulator, USB chip and LED) draws a few milliamps even while the chip sleeps, so it isn't ideal for projects that need to last months on a battery.
Not working? Check these in order
| Problem | Usual cause |
|---|---|
| Port doesn't appear | Charge-only cable, or missing driver |
| Failed to connect | Hold BOOT during upload, or something on GPIO 0, 2 or 12 |
| Garbage in the serial output | Monitor speed isn't 115200 |
| Resets when Wi-Fi starts | Weak supply (brownout) |
| Analog reading is zero with Wi-Fi on | The sensor is on an ADC2 pin |
| The board is very hot | A short, or 5 V on the 3V3 pin |
FAQ
Can I use ordinary Arduino libraries? Most of them, yes, especially sensor and display libraries. Libraries that access the hardware directly (such as some older timer and PWM libraries) may not work. Older versions of the board package used ledcWrite instead of analogWrite, and newer versions support both.
Can I run Bluetooth and Wi-Fi together? Yes, but they share the same radio and memory, so performance drops a little. For simple projects you won't notice.
Next step
Try reading a temperature and humidity sensor and showing the reading on a web page served by the board itself. It's one of the most popular first projects, and after that you can send the readings anywhere with MQTT.