Lesson 2
18 min
Discover the development board, the GPIOs, the 3.3 V voltage and the pins to avoid.
Definition
The pinout is the diagram that shows the role of each pin on an electronic board: which ones are power, which ones are ground, and what functions each GPIO (General Purpose Input Output) can fulfill. Knowing how to read the pinout is essential before connecting any component.
The ESP32 chip on its own is tiny and hard to use. It is therefore bought mounted on a development board ("DevKit") that adds everything needed to get started. On a typical board, you will find:

The EN button (short for enable) restarts the chip: it is the equivalent of an Arduino's reset button, and your program starts again from the beginning. The BOOT button is connected to pinGPIO0. If you hold it down during the restart, the chip enters upload mode and waits for a new program.
The programmable pins are called GPIOs ("General Purpose Input Output"), numbered for example GPIO4 or GPIO23. In code, you simply use their number. Unlike the Arduino Uno, the ESP32's pins are multifunction: the same pin can serve as a digital input, a PWM output, an analog input or a communication bus, depending on the configuration you choose.
On a 38-pin board, the numbering printed on the board corresponds directly to the GPIO number. So you writepinMode(23, OUTPUT)to use the pin labeled "23" (or "D23" depending on the board). There is no special prefix like the A of the Uno's analog inputs.

Warning: the pins do not tolerate 5 V
The ESP32's GPIOs operate at 3.3 V. Applying 5 V to them can permanently damage them, or even destroy the chip. If you want to connect a sensor that outputs 5 V to an input, you must lower the voltage (voltage divider, logic level converter). And no ESP32 pin is designed to be connected to mains power.
As for current, a pin must not supply much: stay under 10 to 12 mA per pin, which is enough to light an LED but not to power a motor or a relay directly.
An LED connected to a 3.3 V pin receives less voltage than on a 5 V Arduino. It therefore shines a bit less brightly with the same resistor. For a common red or green LED, a 220-ohm resistor is still a good choice: the current will be low but sufficient, and you stay well within the pin's limits.
If a sensor sends a 5 V signal to the ESP32, you can lower it with two resistors in series, called a voltage divider. With a 1 kΩ resistor on the signal side and a 2 kΩ one to GND, the middle point delivers about two thirds of the input voltage, i.e. 3.3 V for 5 V. For fast or bidirectional signals (an I2C bus, for example), it is better to use a small logic level converter module.

The board's regulator can only supply limited current on the3V3 pin, and the ESP32 already uses a good part of it when Wi-Fi is active. So don't connect power-hungry components to this pin: a motor, an LED strip or a servo motor should be powered separately, with a common ground.
Not all GPIOs are equal. A few quirks to remember about the classic ESP32:
To get started without trouble
The following pins are the "safest": GPIO4, 13, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27, 32 and 33. For analog reading at the same time as Wi-Fi, prefer GPIO32 to 39.
Some pins have a default function that you should respect, because they are already used by the hardware or by libraries.
A0 to A5). On the ESP32, you simply use the GPIO number.Many boards have a small LED connected to GPIO2. This is not universal: some boards don't have one, and others put it on a different pin. Check your board's documentation before counting on it for your first tests.
Since GPIO numbers say nothing about their use, get into the habit of giving them a name in your program with const int. If you need to move a component to another pin, you only change one line, instead of searching through all the code.
// Only one line to change if you switch pins
const int ledPin = 23;
const int buttonPin = 4;
const int sensorPin = 34; // input only: perfect for a sensor
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
int light = analogRead(sensorPin); // value from 0 to 4095
if (digitalRead(buttonPin) == LOW) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
Serial.println(light);
delay(200);
}In this example, the sensor is connected to GPIO34, a pin that can only read: it is a suitable choice. The button is on GPIO4 with the internal pull-up resistorINPUT_PULLUP, and the LED onGPIO23.
Exercise
Exercise: choosing your pins
Going further
Vin × R2 / (R1 + R2)), then check your result with the typical values of 1 kΩ and 2 kΩ.