Understanding the Analog Inputs - ESP32
- automatelabonline
- Feb 22
- 2 min read
The Analog Inputs of the ESP32
The analog inputs of the ESP32 allow for reading voltages between 0V and 3.3V. This type of reading is extremely useful for reading analog signals, such as potentiometers and photoresistors, for example.
The ESP32 has 15 pins that can be configured as analog inputs. The figure below shows the pinout of the ESP32. The analog inputs are marked with the label ADC .

Undestanding the ESP32 ADC
The ADC (Analog-to-Digital Converter) of the ESP32 has a 12-bit resolution. This means it is capable of measuring 2¹² = 4096 different voltage levels. This resolution is adjustable by code, allowing it to be configured to values between 9 bits (0 to 511) and 12 bits (0 to 4095).
The pins can read voltages between 0V and 3.3V. When configured to the maximum resolution, the minimum measurement range of the reading is

Functions for the Analog Inputs
Unlike the Arduino Uno, the digital inputs of the ESP32 are not specific and can also function as outputs. Therefore, it is necessary to use the pinMode() function to configure the pin as an input. The reading of the pin is done in the same way as with the Arduino, using the function
analogRead(PIN);
Where PIN refers to the pin number that will be read.
If you wish to change the resolution of the analog pin readings, it can be done using the function
analogReadResolution(N_BITS);
N_BITS represents the number of bits that the reading will have. This value can be configured between 9 and 12, and it will change the resolution of all the analog inputs on the board.
Project - Reading a Potentiometer with ESP32
To practice the concepts learned about analog inputs, let's implement a project to read the voltage of a potentiometer with the ESP32. The following figure shows the project connection. The pins at the ends of the potentiometer are connected to 3V3 and GND. The middle pin is connected to one of the pins that can read analog voltages, in this case, pin D4.

Below is the code for this project.
#define PIN_POTENTIOMETER 4 // defines the pin
void setup() {
pinMode(PIN_POTENTIOMETER, INPUT); // set the pin as input
Serial.begin(9600);
}
void loop() {
Serial.println(analogRead(PIN_POTENTIOMETER)); // read the port and print at Serial
delay(100);
}
Conclusions
The analog inputs of the ESP32 boards offer excellent flexibility for various projects involving the reading of analog signals, such as temperature sensors, light sensors, and many other devices. With a 12-bit resolution and the ability to perform fast and precise readings, the analog inputs of the ESP32 stand out among other boards, making them ideal for high-precision applications.
Moreover, the combination of the analog inputs with the powerful connectivity and processing features of the ESP32 enables the development of more sophisticated solutions, which require not only the capture of sensory data but also its transmission or real-time processing.
In short, the analog inputs of the ESP32 are an essential tool for the creation of real-time monitoring and control systems, allowing the implementation of innovative projects with high precision and efficiency.