The ESP32 is a cheap board with Wi-Fi and Bluetooth built in, and the Arduino IDE is the easiest way to program it. This guide takes you from a new board to a working sketch, then covers the handful of things that catch out almost everyone. It assumes a board with the original ESP32 chip, such as an ESP32-DevKitC or a similar 30 or 38-pin board, and the steps are the same for the S3, C3 and C6 apart from choosing the board.
1. Install the Arduino IDE
Download the free Arduino IDE 2 from arduino.cc and install it. It runs on Windows, macOS and Linux.
2. Add the ESP32 boards
The Arduino IDE doesn't know about ESP32 boards until you add Espressif's package.
- Open File → Preferences (on a Mac, Arduino IDE → Settings).
- In Additional boards manager URLs, paste this address and click OK:
https://espressif.github.io/arduino-esp32/package_esp32_index.json - Open the Boards Manager (the board icon on the left), search for esp32, and install esp32 by Espressif Systems. It's a large download. Don't confuse it with "Arduino ESP32 Boards", which is only for Arduino's own Nano ESP32.
3. Connect the board
Plug the board in with a USB cable that carries data. Many cables that come with gadgets only charge, and they're the most common reason a board isn't found.
The board has a USB-to-serial chip next to its USB socket, usually a Silicon Labs CP2102 or a WCH CH340. Windows 10 and 11 normally install the driver by themselves. If no new port appears, install the driver for your board's chip from Silicon Labs' or WCH's website, then unplug and replug the board.
4. Choose the board and port
- Open Tools → Board → esp32 and choose ESP32 Dev Module. That suits most boards with an ESP32-WROOM-32 module. If your board is listed by name, choose that instead.
- Open Tools → Port and choose the board's port: a COM port on Windows, or something like
/dev/cu.usbserial…or/dev/cu.SLAB_USBtoUARTon a Mac and/dev/ttyUSB0on Linux. If you're not sure which, unplug the board and see which one disappears.
5. Your first sketch: blink
Many ESP32 boards have an LED on GPIO 2, but not all of them, so this sketch uses an LED you add yourself. Wire GPIO 23 through a 220 Ω resistor to an LED's long leg, and the short leg to GND. With 3.3 V from the pin, that's about 6 mA for a red LED.
// First ESP32 sketch: blink an LED on GPIO 23 and print to the Serial Monitor.
const int LED_PIN = 23;
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
Serial.println("Hello from the ESP32");
}
void loop() {
digitalWrite(LED_PIN, HIGH);
Serial.println("LED on");
delay(500);
digitalWrite(LED_PIN, LOW);
Serial.println("LED off");
delay(500);
}
Click Upload (the arrow). The IDE compiles the sketch, which takes longer than on an Uno, then shows "Connecting..." and writes it to the board. Open the Serial Monitor (the magnifying glass at the top right) and set it to 115200 baud to see the messages.
6. Try the Wi-Fi: scan for networks
This sketch lists every Wi-Fi network the ESP32 can hear, with its signal strength. It's a quick way to check the radio works, and to see how strong your signal is where the board will live.
// List the Wi-Fi networks the ESP32 can hear, every 10 seconds.
#include <WiFi.h>
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA); // station mode: the ESP32 joins networks rather than making one
}
void loop() {
int n = WiFi.scanNetworks();
Serial.printf("Found %d networks\n", n);
for (int i = 0; i < n; i++) {
// RSSI is the signal strength in dBm: -50 is excellent, -70 fine, below -80 unreliable
Serial.printf("%2d %-32s %4d dBm channel %d\n", i + 1, WiFi.SSID(i).c_str(), (int)WiFi.RSSI(i), (int)WiFi.channel(i));
}
WiFi.scanDelete(); // free the memory the results used
delay(10000);
}
We tested both sketches on a simulated ESP32, checking the blink timing and the scan output.
The original ESP32 only uses 2.4 GHz Wi-Fi, so 5 GHz networks won't appear. Signal strength is in dBm and always negative: −50 dBm is excellent, −70 dBm is fine, and below about −80 dBm the connection gets unreliable.
Fixing upload errors
- "Failed to connect to ESP32" or it sits on "Connecting....____": the board didn't enter its programming mode. Upload again, and when "Connecting..." appears, hold the BOOT button until the percentage starts counting. Most boards do this by themselves, but some need help.
- No port to choose: try a different cable first, then install the USB chip's driver.
- "Port is busy" or "Access denied": close the Serial Monitor or any other program using the port.
- The board keeps restarting once Wi-Fi starts ("Brownout detector was triggered"): the power supply can't keep up with the Wi-Fi's bursts of current. Try another cable or USB port. Espressif recommends a supply that can give at least 500 mA.
- Gibberish in the Serial Monitor: the baud rate doesn't match
Serial.begin(). Set both to 115200.
Things that are different from an Arduino Uno
- 3.3 V logic. Never put 5 V on a GPIO pin. Sensors made for 5 V boards may need a level shifter or a voltage divider.
- Not every pin is free. On the original ESP32, GPIO 6 to 11 belong to the flash memory, GPIO 34 to 39 are inputs only, and GPIO 0, 2, 5, 12 and 15 affect how the chip starts. Our ESP32 pinout lists the safe ones.
- ADC2 stops working when Wi-Fi is on. Use ADC1 pins (GPIO 32 to 39) for analogue sensors.
- The ADC isn't very precise. It reads 0 to 4095, but it isn't perfectly straight near the ends of its range. That's fine for a soil sensor or a knob, but not for measuring voltages accurately.
- Versions of the ESP32 package. Espressif's Arduino package has moved to version 3, and version 4 is on the way. Some functions changed between versions, especially the ones for PWM. The projects on this site use
analogWrite(),tone()andtouchRead(), which work the same in both. If a sketch from elsewhere won't compile, check which version it was written for.
Next steps
Try one of our ESP32 projects: a weather station with its own web page, a touch lamp or a plant watering reminder. Or skip the coding and turn the board into a Home Assistant sensor with our ESPHome project.
Sources
The main references behind this guide. Numbers we worked out ourselves, such as the code outputs, come from running the code.