Circuit 3D

ESP32

An ESP32 is a low-cost microcontroller with Wi-Fi and Bluetooth built in: two cores at up to 240 MHz, 520 KB of RAM, and pins that run at 3.3 V. It has 260 times an Arduino Uno’s RAM and 15 times its clock speed, and programs from the same Arduino IDE.

Vpin ≤ 3.3 V

the one rule for its pins: none takes 5 V, so a 5 V signal needs a divider or a level shifter first.

Its older sibling, the ESP8266, has Wi-Fi only, and sits on NodeMCU boards.

What is an ESP32?

An ESP32 is a microcontroller from Espressif with Wi-Fi and Bluetooth built in, two processor cores at up to 240 MHz and 520 KB of RAM, sold on small dev boards that plug into a breadboard.

Like an Arduino, it reads sensors and drives outputs, but it can also join a Wi-Fi network, serve a web page or talk to a phone. That makes it the usual chip for connected gadgets, from weather stations to smart switches.

What is the ESP32 pinout?

The common 30-pin ESP32 DevKit V1 has 15 pins down each side: power, ground and reset, and GPIO pins that double as analog inputs, touch sensors, DAC outputs, serial ports, I2C and SPI.

Figure 1 marks each group. Two warnings matter most: every signal pin takes 3.3 V at most, and the strapping pins, 2, 5, 12 and 15, decide how the chip boots, so wire them carefully. The board’s blue LED sits on GPIO 2.

ESP32 EN VP VN D34 D35 D32 D33 D25 D26 D27 D14 D12 D13 GND VIN D23 D22 TX0 RX0 D21 D19 D18 D5 TX2 RX2 D4 D2 D15 GND 3V3

ADC, VP, VN, D34, D35, D32, D33: analog inputs on ADC1, 12 bits, which keep working while Wi-Fi is on; the ADC2 pins stop reading when Wi-Fi runs.

Figure 1. The common 30-pin ESP32 DevKit V1, antenna up and USB down, with its board labels; D numbers are GPIO numbers. Every signal pin is 3.3 V only.

What is the difference between an ESP32 and an Arduino?

An ESP32 has Wi-Fi, Bluetooth, 15 times the clock speed and 260 times the RAM of an Arduino Uno, but its pins work at 3.3 V instead of 5 V and are easier to damage.

Figure 2 compares them. Start on an Uno if you want the most forgiving board for first circuits, or see Raspberry Pi vs Arduino for a full computer, and move to an ESP32 when a project needs a network, more speed or more memory. Both program from the Arduino IDE.

Arduino Uno 2 KB ESP8266 80 KB ESP32 520 KB

RAM: the ESP32 has 260 times the Uno’s ram. It also adds Wi-Fi and Bluetooth, but its pins run at 3.3 V where the Uno’s run at 5 V.

Figure 2. An Arduino Uno, an ESP8266 and an ESP32 compared on a scale where each step is ten times the last. Typical boards; the ESP8266 can also run at 160 MHz.

What is the difference between the ESP8266 and the ESP32?

The ESP8266 is the ESP32’s older, simpler sibling: one core at 80 or 160 MHz, Wi-Fi but no Bluetooth, fewer pins and a single analog input, which still makes it a cheap way onto Wi-Fi.

The ESP32 adds a second core, Bluetooth, many analog inputs, touch pins and more memory, for little more money. For a new project, the ESP32 is usually the better choice.

What is NodeMCU?

NodeMCU is a development board built around the ESP8266, with a USB socket, a USB-to-serial chip and a 3.3 V regulator, so it plugs into a computer and a breadboard; the name first belonged to firmware written for it.

Its pins are labeled D0 to D8, which are not the chip’s GPIO numbers, so check a pinout before you wire it. ESP32 boards are sometimes sold under the same name.

How do you program an ESP32?

To program an ESP32, add Espressif’s ESP32 board package to the Arduino IDE, pick your board, and upload over USB, where most Arduino code and libraries work as they are.

MicroPython runs on it too, for Python instead of C++, and Espressif’s own ESP-IDF unlocks everything the chip can do. If an upload stalls, hold the BOOT button as it starts.

What are good first ESP32 projects?

Good first ESP32 projects are an LED you switch from a phone over Wi-Fi, a temperature logger that serves its readings as a web page, and a Bluetooth link to a phone app.

Each builds on the basics: an LED needs its resistor, at 3.3 V a smaller one than at 5 V, and a sensor such as a temperature sensor or a thermistor wires to an analog pin. Pair it with other wireless modules for RFID or GPS.

How do you power an ESP32 safely?

Power an ESP32 board from 5 V, through USB or its VIN pin, so its regulator makes the 3.3 V the chip needs, and allow for current peaks of about 240 mA when Wi-Fi transmits.

A USB phone charger works, from 120 V or 230 V mains, as does a power bank. Don’t feed VIN 12 V, as Example 2 shows, and never put more than 3.3 V on a signal pin; a divider brings a 5 V signal down.

How do you protect an ESP32’s pins and regulator?

Divide any higher signal down to 3.3 V with two resistors, and multiply the voltage the regulator drops by its current for the heat it must shed.

Example 1: reading a higher voltage safely

A sensor puts out up to 5 V. With 10 kΩ to ground, which top resistor keeps an ESP32 pin at or below 3.3 V?

Given
a 5 V signal, a 10 kΩ resistor to ground, and an ESP32 pin that must stay at or below 3.3 V
Find
the top resistor, and the voltage the pin sees
Solution
Rtop ≥ 10 kΩ × (5 ÷ 3.3 − 1) ≈ 5.15 kΩ, so take 5.6 kΩVpin = 5 × 10 ÷ (5.6 + 10) ≈ 3.21 V
Answer
5.6 kΩ on top, giving 3.21 V

Example 2: why not power it from 12 V

An ESP32 board’s regulator drops VIN to 3.3 V. Fed 5 V, how much heat must it shed at the chip’s Wi-Fi peaks?

Given
an ESP32 dev board fed 5 V on VIN, its 3.3 V linear regulator passing the chip’s 240 mA Wi-Fi peaks
Find
the heat the regulator must shed
Solution
P = (5 V − 3.3 V) × 0.24 A = 0.408 W
Answer
0.408 W, which a small regulator handles

Summary

Key equations

  • Vpin = V × Rlow ÷ (Rtop + Rlow) a divider to 3.3 V
  • P = (Vin − 3.3 V) × I its regulator’s heat

Key terms

GPIO
A pin the program controls.
Dev board
The chip with USB and a regulator.
Strapping pin
One read at power-up to set booting.
NodeMCU
An ESP8266 dev board.

Practice problems

  1. What voltage do an ESP32’s pins work at?

  2. Which ESP32 pins are input only?

  3. Which has Bluetooth, the ESP32 or the ESP8266?

  4. Which are an ESP32’s default I2C pins in the Arduino IDE?

  5. An ESP32 board’s 3.3 V regulator passes 240 mA from 5 V. How much heat does it shed?

FAQ

Can an ESP32 run on 5 V?

Its board can: power it with 5 V from USB or the VIN pin, and its regulator makes 3.3 V. Its signal pins still take only 3.3 V.

Is an ESP32 better than an Arduino?

For Wi-Fi, Bluetooth, speed and memory, yes. An Arduino Uno is simpler and its 5 V pins are more forgiving, which suits a first circuit.

Why won’t my ESP32 boot with something wired to GPIO 12?

GPIO 12 sets the flash memory’s voltage at power-up, and pulled high it can stop the board starting. Keep strapping pins 2, 5, 12 and 15 free while it boots.

Does the ESP32 have analog inputs?

Yes, 12-bit ones on many pins. Use the ADC1 pins, 32 to 39, when Wi-Fi is on, since the ADC2 pins stop reading while Wi-Fi runs.

Can an ESP32 use Bluetooth and Wi-Fi at once?

Yes, they share one radio and take turns, which works for most projects, though each runs a little slower than on its own.