In this tutorial, you’ll learn how to use the ESP32 ADC to read analog voltage with the Arduino IDE. We’ll use analogRead() to get the raw 12-bit reading and analogReadMilliVolts() to get a calibrated voltage in mV. You’ll learn which ESP32 ADC pins to use (and which to avoid with Wi-Fi), the real input voltage range for each attenuation setting, how to calibrate and filter the readings, and how fast the ESP32 ADC really is.
Then, we’ll build a few ESP32 ADC example projects: reading a potentiometer, an LED dimmer, a calibrated voltmeter, a noise-reduction filter, multi-channel continuous (DMA) sampling, an ADC speed test, and measuring 12v with a voltage divider. We’ll also fix the most common ESP32 analogRead problems (always 0, always 4095, noisy readings, and code that stopped compiling after the Arduino core 3.x update). Without further ado, let’s get right into it!
ESP32 ADC analogRead Example
To read an analog voltage with the ESP32 ADC in Arduino, connect your signal (0 to 3.1v) to an ADC1 pin such as GPIO35, then call analogRead(35) for the raw value (0 – 4095) or analogReadMilliVolts(35) for the calibrated voltage in mV. No pinMode() is needed. Here is the shortest complete sketch:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
// ESP32 ADC Quick Answer (Arduino-ESP32 core 3.x) // Potentiometer wiper -> GPIO35 (ADC1_CH7) void setup() { Serial.begin(115200); } void loop() { int raw = analogRead(35); // 0 to 4095 (12-bit) int mV = analogReadMilliVolts(35); // calibrated voltage in mV Serial.printf("Raw: %d Voltage: %d mV\n", raw, mV); delay(100); } |
Open the serial monitor at 115200 baud and turn the potentiometer. The rest of this tutorial explains the ESP32 ADC pins, the voltage range and attenuation, calibration, the wiring, and the full LAB examples.
Note: All examples in this tutorial are tested with: ESP32 DevKit V1 (ESP32-WROOM-32), Arduino-ESP32 core 3.3.12, Arduino IDE 2.x. Every listing in this tutorial compiles with core 3.x. If you’re on the old core 2.x, see the core 3.x changes section.
ESP32 ADC Pins (ADC1 & ADC2 Channels)
The ESP32 has two 12-bit SAR ADCs with 18 analog input channels in total: ADC1 has 8 channels on GPIO32 – GPIO39, and ADC2 has 10 channels on GPIO0, 2, 4, 12 – 15, and 25 – 27. The 30-pin ESP32 DevKit V1 board exposes 15 of them (GPIO37 and GPIO38 aren’t broken out, and GPIO0 is the BOOT button).
| ADC Unit | Channel | GPIO | Notes |
|---|---|---|---|
| ADC1 | CH0 | GPIO36 (VP) | Input-only |
| ADC1 | CH3 | GPIO39 (VN) | Input-only |
| ADC1 | CH4 | GPIO32 | |
| ADC1 | CH5 | GPIO33 | |
| ADC1 | CH6 | GPIO34 | Input-only |
| ADC1 | CH7 | GPIO35 | Input-only (used in this tutorial) |
| ADC1 | CH1, CH2 | GPIO37, GPIO38 | Not on most DevKit boards |
| ADC2 | CH0 | GPIO4 | Not usable while Wi-Fi is on |
| ADC2 | CH1 | GPIO0 | Strapping pin (BOOT button) |
| ADC2 | CH2 | GPIO2 | Strapping pin, onboard LED on many boards |
| ADC2 | CH3 – CH6 | GPIO15, 13, 12, 14 | GPIO12 & GPIO15 are strapping pins |
| ADC2 | CH7 – CH9 | GPIO27, 25, 26 | Not usable while Wi-Fi is on |
ESP32 ADC2 & Wi-Fi: Which Pins Work With Wi-Fi?
Use the ADC1 pins (GPIO32 – GPIO39) whenever your project uses Wi-Fi. The Wi-Fi driver uses ADC2, so while Wi-Fi is running, an analogRead() on an ADC2 pin can’t get the ADC, and the Arduino core returns 0 without any error in your sketch.
Note: GPIO34, 35, 36, and 39 are input-only pins with no internal pull-up or pull-down resistors. That makes them perfect for analog inputs, but you can’t use them as outputs. And never apply more than 3.3v to any ESP32 pin: use a voltage divider for higher voltages (LAB 7).
ESP32 ADC Resolution, Voltage Range & Attenuation
The ESP32 ADC is 12-bit by default, so analogRead() returns 0 – 4095. With the default 11dB attenuation ( ADC_11db), the usable input range is about 150mV to 3100mV on the original ESP32, not the full 0 – 3.3v. Inputs below ~150mV read 0, and inputs above ~3.1v read 4095.
| Parameter | ESP32 (Arduino Core 3.x Default) |
|---|---|
| ADC Type | 2x SAR ADC (successive approximation) |
| Resolution | 12-bit (0 – 4095), configurable 9 – 12 bits |
| Default Attenuation | 11dB (ADC_11db) |
| Usable Range @ 11dB | ~150mV – 3100mV |
| Max Pin Voltage | 3.3v (absolute) |
| Internal Reference (VREF) | 1100mV nominal, 1000 – 1200mV chip to chip |
| Calibration | eFuse-based, applied by analogReadMilliVolts() |
| Continuous (DMA) Sampling Rate | 20kHz – 2MHz (ADC1 only) |
ESP32 ADC Attenuation
The ESP32 ADC measures against an internal ~1.1v reference. To read higher voltages, the input passes through an attenuator first. The higher the attenuation, the higher the voltage you can measure, at the cost of some accuracy. Here are the measurable ranges from the Arduino-ESP32 ADC documentation:

| Attenuation | ESP32 | ESP32-S3 | ESP32-S2 / C3 |
|---|---|---|---|
ADC_0db | 100 – 950mV | 0 – 950mV | 0 – 750mV |
ADC_2_5db | 100 – 1250mV | 0 – 1250mV | 0 – 1050mV |
ADC_6db | 150 – 1750mV | 0 – 1750mV | 0 – 1300mV |
ADC_11db (default) | 150 – 3100mV | 0 – 3100mV | 0 – 2500mV |
You can change the attenuation for all ADC pins or for one pin only:
|
1 2 |
analogSetAttenuation(ADC_6db); // All ADC pins analogSetPinAttenuation(35, ADC_2_5db); // GPIO35 only |
For most projects, you’ll leave it at the default 11dB, which gives you the widest range. Use a lower attenuation only when your signal is small (for example a sensor that outputs 0 – 1v), because the narrower range gives you better resolution per mV.
ESP32 ADC Resolution
Use analogReadResolution(bits) to change the resolution of the value returned by analogRead(). On the original ESP32, values from 9 to 12 bits change the hardware resolution. Any other value (1 – 16) is just shifted from the 12-bit result, so asking for 16 bits doesn’t give you a better ADC. For example, analogReadResolution(10) gives you 0 – 1023, just like an Arduino UNO.
How the ESP32 ADC Works
The ESP32 has two SAR (Successive Approximation Register) ADCs. A SAR ADC samples the input voltage on a small internal capacitor, then finds its digital value with a binary search: it tries the most significant bit first, compares an internal DAC voltage with the input, keeps or clears that bit, and moves to the next one. A 12-bit result takes 12 of these steps, as you can see in the animation below.

Each ADC unit is controlled by an RTC controller (used by analogRead() and in deep sleep) or a digital controller with DMA for high-speed continuous sampling (LAB 5). Here is the internal block diagram from Espressif’s documentation:

If it’s your first time learning about ADCs, check out this ADC tutorial for how ADCs work, ADC types, error sources, and sampling.
ESP32 ADC Arduino Functions (Core 3.x)
These are the ADC functions in the current Arduino-ESP32 core (3.x). The ones you’ll use 99% of the time are analogRead() and analogReadMilliVolts().
| Function | What It Does |
|---|---|
analogRead(pin) | Returns the raw ADC value (0 – 4095 at 12-bit). Not calibrated |
analogReadMilliVolts(pin) | Returns the calibrated input voltage in mV (uses the eFuse calibration data) |
analogReadResolution(bits) | Sets the resolution of analogRead() results (1 – 16, default 12) |
analogSetAttenuation(atten) | Sets the attenuation for all ADC pins: ADC_0db, ADC_2_5db, ADC_6db, ADC_11db (default) |
analogSetPinAttenuation(pin, atten) | Sets the attenuation for one pin |
analogSetWidth(bits) | ESP32 only: sets the hardware sample width (9 – 12 bits) |
analogContinuous(pins, count, conv, freq, cb) | Sets up continuous (DMA) sampling on ADC1 pins |
analogContinuousStart() / Stop() | Starts or stops continuous conversions |
analogContinuousRead(&buf, timeout) | Gets the averaged raw and mV results for each pin |
analogContinuousSetAtten() / SetWidth() | Attenuation and resolution for continuous mode |
analogContinuousDeinit() | Releases the continuous mode driver |
ESP32 ADC Changes in Arduino Core 3.x (Old vs New)
Arduino-ESP32 core 3.0 (May 2024, now 3.3.x) moved to ESP-IDF 5 and removed several ADC functions that older tutorials still use, including the first version of this one. If your old ADC code stopped compiling after a core update, here is what to change, based on the official 2.x to 3.0 migration guide and our compile tests:
| Old (Core 2.x) | New (Core 3.x) | Compile Error You’ll Get on 3.x |
|---|---|---|
analogSetClockDiv(div) | Removed. Use continuous mode to set a sampling rate | 'analogSetClockDiv' was not declared in this scope |
adcAttachPin(pin) | Removed. analogRead() attaches the pin itself | 'adcAttachPin' was not declared in this scope |
analogSetVRefPin(pin) | Removed. Calibration is automatic in analogReadMilliVolts() | 'analogSetVRefPin' was not declared in this scope |
adcStart(), adcBusy(), adcEnd() | Removed. analogRead() is a blocking read | 'adcEnd' was not declared in this scope |
analogSetCycles(), analogSetSamples() | Removed. Average in software (LAB 4) or use continuous mode | 'analogSetCycles' was not declared in this scope |
esp_adc_cal_characterize() + esp_adc_cal_raw_to_voltage() | analogReadMilliVolts(pin) | Warning: legacy adc calibration driver is deprecated |
ADC_ATTEN_DB_11 | ADC_11db (Arduino) or ADC_ATTEN_DB_12 (IDF) | Warning: 'ADC_ATTEN_DB_11' is deprecated |
ledcSetup() + ledcAttachPin() | ledcAttach(pin, freq, res) | 'ledcSetup' was not declared in this scope |
analogRead(), analogReadMilliVolts(), analogReadResolution(), analogSetAttenuation(), and analogSetPinAttenuation() work the same way on both cores, so a simple analogRead() sketch doesn’t need any change.
ESP32 ADC Example Wiring & Parts
All the LABs in this tutorial use the same setup: one 10kΩ potentiometer as the analog input on GPIO35, and one LED with a 330Ω resistor on GPIO5 for the LED dimmer LAB. Here is the wiring diagram for the ESP32 ADC example projects in this tutorial.

3V3 goes to one outer pin of the potentiometer (through the breadboard’s + rail). Power the pot from 3.3v only.
GND goes to the other outer pin of the potentiometer and to the LED’s cathode (short leg), through the breadboard’s − rail.
GPIO35 goes to the potentiometer’s middle pin (wiper). This is the ESP32 ADC input (ADC1_CH7) we read in the LABs.
GPIO5 goes to the 330Ω resistor, and the resistor goes to the LED’s anode (long leg). It’s the PWM output for the LED dimmer in LAB 2.
Note: Power the potentiometer from 3.3v, never from 5v (VIN). With 5v on the pot, the wiper can go above 3.3v and damage the ESP32’s ADC pin.
| QTY. | Component Name | Amazon.com | AliExpress |
| 1 | ESP32 DevKit V1 (DOIT) Board | Amazon | AliExpress |
| 1 | 10kΩ Potentiometer | Amazon | AliExpress |
| 1 | LEDs Kit | Amazon | AliExpress |
| 1 | Resistors Kit (330Ω, 30kΩ, 7.5kΩ) | Amazon | AliExpress |
| 1 | 100nF Ceramic Capacitors | Amazon | AliExpress |
| 1 | 0-25v Voltage Sensor Module (30k/7.5k Divider, LAB 7) | Amazon | AliExpress |
| 1 | ADS1115 16-Bit ADC Module (Optional) | Amazon | AliExpress |
| 1 | Breadboard & Jumper Wires | Amazon | AliExpress |
| 1 | Micro USB Cable | Amazon | AliExpress |
ESP32 analogRead Potentiometer Example (LAB 1)
In this first ESP32 ADC example, we’ll read the potentiometer on GPIO35 with both analogRead() and analogReadMilliVolts() and print them in a format the Arduino Serial Plotter understands, so you can watch both values change as you turn the knob.
Wiring: the potentiometer’s wiper goes to GPIO35 and its outer pins go to 3V3 and GND as shown in the wiring diagram above.
Here is The Application Code For This Example (ESP32_ADC_Read_Pot_LAB1.ino)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/* * LAB Name: ESP32 ADC Read Potentiometer (analogRead + analogReadMilliVolts) * Author: Khaled Magdy * For More Info Visit: www.DeepBlueMbedded.com * Tested With: Arduino-ESP32 Core 3.3.x */ #define AN_POT_PIN 35 // GPIO35 = ADC1_CH7 (input-only pin) int AN_Pot_Raw = 0; int AN_Pot_mV = 0; void setup() { Serial.begin(115200); analogReadResolution(12); // 12-bit: 0 to 4095 (default) analogSetAttenuation(ADC_11db); // Full input range up to ~3.1v (default) } void loop() { AN_Pot_Raw = analogRead(AN_POT_PIN); // Raw ADC reading (uncalibrated) AN_Pot_mV = analogReadMilliVolts(AN_POT_PIN); // Calibrated voltage in mV Serial.print("Raw:"); Serial.print(AN_Pot_Raw); Serial.print(",mV:"); Serial.println(AN_Pot_mV); delay(50); } |
ESP32 analogRead Example Code Explanation
First, we define the analog input pin. GPIO35 is an ADC1 pin (ADC1_CH7), so it keeps working when you add Wi-Fi later.
|
1 |
#define AN_POT_PIN 35 // GPIO35 = ADC1_CH7 (input-only pin) |
In the setup() function, we set the resolution and attenuation. Both lines only repeat the defaults (12-bit and 11dB), so you can delete them. I kept them so you know where to change these settings.
|
1 2 |
analogReadResolution(12); // 12-bit: 0 to 4095 (default) analogSetAttenuation(ADC_11db); // Full input range up to ~3.1v (default) |
In the loop() function, we read the raw value and the calibrated voltage, then print them as label:value pairs, which the Serial Plotter in Arduino IDE 2.x shows as two named curves.
|
1 2 |
AN_Pot_Raw = analogRead(AN_POT_PIN); // Raw ADC reading (uncalibrated) AN_Pot_mV = analogReadMilliVolts(AN_POT_PIN); // Calibrated voltage in mV |
ESP32 analogRead Example Result

Notice that the raw curve flattens at 0 near the low end and at 4095 near the top, while the mV curve stops at about 142mV and 3171mV on my board. That’s the ESP32 ADC’s usable range at 11dB attenuation, and the calibrated mV value never reads below the bottom of that range.
ESP32 Potentiometer LED Dimmer With ADC (LAB 2)
In this example, we’ll read the potentiometer with the ESP32 ADC and use the result to set the brightness of an LED with PWM. The PWM resolution is set to 12 bits so the ADC result (0 – 4095) can be written directly as the PWM duty cycle, with no scaling.
- Attach the LED pin (GPIO5) to a PWM channel at 1kHz and 12-bit resolution
- Read the ADC input channel (potentiometer on GPIO35)
- Write the ADC result to the LED’s PWM duty cycle
Wiring: the potentiometer stays on GPIO35, and the LED goes to GPIO5 through the 330Ω resistor, with its cathode to GND.
Here is The Application Code For This Example (ESP32_ADC_POT_LED_Dimmer_LAB2.ino)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
/* * LAB Name: ESP32 ADC + Potentiometer LED Dimmer * Author: Khaled Magdy * For More Info Visit: www.DeepBlueMbedded.com * Tested With: Arduino-ESP32 Core 3.3.x */ #define LED_GPIO 5 #define PWM_FREQ 1000 #define PWM_RES 12 // 12-bit PWM to match the 12-bit ADC result #define AN_POT_PIN 35 int AN_Pot_Result = 0; void setup() { ledcAttach(LED_GPIO, PWM_FREQ, PWM_RES); // Core 3.x: pin-based LEDC (no channel) } void loop() { AN_Pot_Result = analogRead(AN_POT_PIN); ledcWrite(LED_GPIO, AN_Pot_Result); // Core 3.x: write by pin delay(1); } |
ESP32 ADC LED Dimmer Code Explanation
In core 3.x, the LEDC (PWM) driver is pin-based. One call to ledcAttach() sets the pin, the frequency, and the resolution, and picks a free channel for you. Then ledcWrite() takes the pin number, not a channel number.
|
1 2 |
ledcAttach(LED_GPIO, PWM_FREQ, PWM_RES); // Core 3.x: pin-based LEDC (no channel) ledcWrite(LED_GPIO, AN_Pot_Result); // Core 3.x: write by pin |
If you’re coming from the old version of this LAB (core 2.x), that’s the only change: ledcSetup() and ledcAttachPin() were removed in core 3.0. You can learn more about the PWM side in the ESP32 PWM Tutorial.
ESP32 ADC LED Dimmer Demo Video
This is the real hardware testing result for this example project on my ESP32 DevKit board. The LED brightness follows the potentiometer from fully off to fully on.
ESP32 ADC Read Voltage & Calibration (LAB 3)
To read an accurate voltage with the ESP32 ADC, use analogReadMilliVolts() instead of converting analogRead() with the usual raw * 3.3 / 4095 formula. The ESP32’s internal reference varies from 1000mV to 1200mV between chips, and its response is not linear near the ends, so the simple formula can be off by more than 100mV. analogReadMilliVolts() corrects for this with calibration data that Espressif burns into each chip’s eFuse at the factory.
In this LAB, we’ll print three values side by side: the raw reading, the naive formula, and the calibrated voltage. Then we’ll compare them with a multimeter.
Wiring: the same potentiometer on GPIO35. To check the readings, put your multimeter between GPIO35 and GND.
Here is The Application Code For This Example (ESP32_ADC_Read_Voltage_mV_LAB3.ino)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
/* * LAB Name: ESP32 ADC Calibrated Voltage Reading (Raw Formula vs analogReadMilliVolts) * Author: Khaled Magdy * For More Info Visit: www.DeepBlueMbedded.com * Tested With: Arduino-ESP32 Core 3.3.x */ #define AN_POT_PIN 35 void setup() { Serial.begin(115200); } void loop() { int Raw = analogRead(AN_POT_PIN); float V_Naive = Raw * 3.3 / 4095.0; // Naive formula (NOT accurate on ESP32) float V_Cal = analogReadMilliVolts(AN_POT_PIN) / 1000.0; // eFuse-calibrated reading Serial.print("Raw: "); Serial.print(Raw); Serial.print(" | Naive: "); Serial.print(V_Naive, 3); Serial.print(" v | Calibrated: "); Serial.print(V_Cal, 3); Serial.println(" v"); delay(250); } |
ESP32 ADC Calibration Code Explanation
The naive conversion assumes the ADC maps 0 – 3.3v linearly to 0 – 4095, which isn’t true for the ESP32:
|
1 |
float V_Naive = Raw * 3.3 / 4095.0; // Naive formula (NOT accurate on ESP32) |
The calibrated reading does all the work in one call. The first time you call it for an ADC unit, the core creates an ESP-IDF calibration scheme (line fitting on the ESP32 and ESP32-S2, curve fitting on the S3, C3, and C6) from the eFuse data and reuses it after that. So you don’t need to calibrate anything yourself or call it again in every reading. For the details, see Espressif’s ADC calibration driver documentation.
|
1 |
float V_Cal = analogReadMilliVolts(AN_POT_PIN) / 1000.0; // eFuse-calibrated reading |
ESP32 ADC Calibration Test Result (vs Multimeter)
I set the potentiometer to four voltages, measured each one with my bench multimeter (HP 34401A) between GPIO35 and GND, and compared it with the two ESP32 readings:

| Multimeter | Raw | Naive Formula | analogReadMilliVolts() |
|---|---|---|---|
| 0.207v | 88 | 0.071v | 0.219v |
| 1.000v | 1044 | 0.841v | 1.018v |
| 2.001v | 2243 | 1.807v | 2.029v |
| 3.000v | 3683 | 2.967v | 2.998v |


The calibrated reading stays within about 30mV of the multimeter across the range. The naive formula reads 136mV to 194mV low in the middle of the range, and it only gets close near 3v. Keep in mind that calibration can’t fix the dead bands: anything below about 140mV still reads around 140mV, and anything above ~3.1v reads the maximum. When I first tested this in 2021 with the legacy esp_adc_cal functions, a 2.00v input read 1.85v uncalibrated and 1.99v calibrated, with dead bands of about 0.14v at both ends.
ESP32 ADC Noise Reduction & Filtering (LAB 4)
The ESP32 ADC is noisy: even with the potentiometer standing still, readings jump by tens of counts. You can reduce this in hardware with a 100nF capacitor from the ADC pin to GND, and in software with multi-sampling and averaging. Espressif recommends both in its ADC documentation.
Be careful with the capacitor, though. It filters the high-frequency components of your signal as well as the noise. For a near-DC signal like a temperature sensor or a battery voltage, it’s fine. For anything that changes fast, I’d rather use an active buffer. In most of my designs, I put a voltage follower (op-amp buffer) and a small RC filter in front of the ADC input. The buffer also stops the channels from disturbing each other when the ADC’s sampling capacitor switches from one channel to the next.

In this LAB, we’ll do the software part: a moving average filter that averages the last 15 readings.
Wiring: the same potentiometer on GPIO35. For the hardware filter, add a 100nF capacitor between GPIO35 and GND.
Here is The Application Code For This Example (ESP32_ADC_Moving_Average_LAB4.ino)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
/* * LAB Name: ESP32 ADC Multi-Sampling & Moving Average Filter * Author: Khaled Magdy * For More Info Visit: www.DeepBlueMbedded.com * Tested With: Arduino-ESP32 Core 3.3.x */ #define AN_POT_PIN 35 #define FILTER_LEN 15 uint32_t AN_Pot_Buffer[FILTER_LEN] = {0}; int AN_Pot_i = 0; int AN_Pot_Raw = 0; int AN_Pot_Filtered = 0; uint32_t readADC_Avg(int ADC_Raw) { int i = 0; uint32_t Sum = 0; AN_Pot_Buffer[AN_Pot_i++] = ADC_Raw; if(AN_Pot_i == FILTER_LEN) { AN_Pot_i = 0; } for(i=0; i<FILTER_LEN; i++) { Sum += AN_Pot_Buffer[i]; } return (Sum/FILTER_LEN); } void setup() { Serial.begin(115200); } void loop() { AN_Pot_Raw = analogRead(AN_POT_PIN); AN_Pot_Filtered = readADC_Avg(AN_Pot_Raw); Serial.print("Raw:"); Serial.print(AN_Pot_Raw); // Raw Reading Serial.print(",Filtered:"); Serial.println(AN_Pot_Filtered); // Filtered Output delay(10); } |
ESP32 ADC Moving Average Filter Code Explanation
The readADC_Avg() function stores each new reading in a circular buffer of FILTER_LEN samples and returns the average of the whole buffer. You can change the filter length to whatever you want, but the larger it gets, the slower the filter responds to real changes (more phase lag), while the output gets smoother.
|
1 2 3 4 5 |
AN_Pot_Buffer[AN_Pot_i++] = ADC_Raw; if(AN_Pot_i == FILTER_LEN) { AN_Pot_i = 0; } |
ESP32 ADC Filter Demo Video
This is the real hardware testing result for this example on my ESP32 board. The blue curve is the raw ADC reading and the red curve is the filtered output.
ESP32 ADC Continuous Mode (DMA) Multi-Channel Example (LAB 5)
The ESP32 ADC continuous mode samples one or more ADC1 pins in the background with DMA, at a sampling rate you choose (20kHz to 2MHz on the ESP32), and calls your function when a batch of conversions is ready. Use it when you need a fixed sampling rate or several channels without blocking the CPU, which analogRead() can’t do.
In this LAB, we’ll sample GPIO34 and GPIO35 at 20kHz, average every 20 conversions per pin, and print both channels.
Wiring: the potentiometer stays on GPIO35, and a jumper wire connects GPIO34 to GND so the second channel has a known input. You can put any other 0 – 3.1v signal on GPIO34 instead.
Here is The Application Code For This Example (ESP32_ADC_Continuous_Multi_Channel_LAB5.ino)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
/* * LAB Name: ESP32 ADC Continuous Mode (DMA) - Multi-Channel Sampling * Author: Khaled Magdy * For More Info Visit: www.DeepBlueMbedded.com * Tested With: Arduino-ESP32 Core 3.3.x */ #define CONVERSIONS_PER_PIN 20 // Each result = average of 20 conversions #define SAMPLING_FREQ_HZ 20000 // Total ADC conversion rate (Hz) uint8_t ADC_Pins[] = {34, 35}; // ADC1 pins only (ADC2 is not supported in continuous mode) uint8_t ADC_Pins_Count = sizeof(ADC_Pins) / sizeof(uint8_t); volatile bool ADC_Done = false; adc_continuous_result_t *ADC_Result = NULL; void ARDUINO_ISR_ATTR ADC_Complete_ISR() { ADC_Done = true; } void setup() { Serial.begin(115200); analogContinuousSetWidth(12); analogContinuousSetAtten(ADC_11db); analogContinuous(ADC_Pins, ADC_Pins_Count, CONVERSIONS_PER_PIN, SAMPLING_FREQ_HZ, &ADC_Complete_ISR); analogContinuousStart(); } void loop() { if (ADC_Done) { ADC_Done = false; if (analogContinuousRead(&ADC_Result, 0)) { for (int i = 0; i < ADC_Pins_Count; i++) { Serial.printf("GPIO%u: %4d (%4d mV) ", ADC_Result[i].pin, ADC_Result[i].avg_read_raw, ADC_Result[i].avg_read_mvolts); } Serial.println(); } delay(100); } } |
ESP32 ADC Continuous Mode Code Explanation
We configure the continuous driver with the pin list, how many conversions to average per pin, the total sampling frequency, and the callback function. The callback runs in an interrupt, so it only sets a flag.
|
1 |
analogContinuous(ADC_Pins, ADC_Pins_Count, CONVERSIONS_PER_PIN, SAMPLING_FREQ_HZ, &ADC_Complete_ISR); |
In the loop(), when the flag is set, analogContinuousRead() gives us an array with one result per pin, holding both the averaged raw value and the averaged calibrated voltage in mV.
Note: Continuous mode works on ADC1 pins only, and an ADC unit can’t run continuous mode and analogRead() at the same time. Don’t call analogRead() on an ADC1 pin while continuous mode is running. The minimum sampling frequency is 20kHz on the ESP32 (611Hz on the S2, S3, C3, and C6).
ESP32 ADC Continuous Mode Result
GPIO34 (tied to GND) stays at 0 (142mV, the bottom of the range), while GPIO35 follows the potentiometer as I turn it. Both channels are sampled in the background, and each line is the average of 20 conversions per pin.

How Fast Is the ESP32 ADC? (Sampling Rate Test, LAB 6)
On my ESP32 DevKit with core 3.3.12, one analogRead() call takes about 43.5µs (23 kSPS), and analogReadMilliVolts() takes about 44.4µs. For faster or evenly spaced samples, use continuous mode, which runs from 20kHz up to 2MHz on the ESP32.
Readers often ask how fast the ESP32 ADC can go, and the datasheet doesn’t give a simple answer for analogRead(). So let’s measure it. This sketch times 10,000 calls of each function with micros(). In core 3.x, analogRead() is a blocking read that returns only after the conversion is done, so this timing is the real time per sample.
Wiring: the same potentiometer on GPIO35. The speed doesn’t depend on the input voltage.
Here is The Application Code For This Example (ESP32_ADC_Speed_Test_LAB6.ino)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
/* * LAB Name: ESP32 ADC Speed Test (How Fast Is analogRead?) * Author: Khaled Magdy * For More Info Visit: www.DeepBlueMbedded.com * Tested With: Arduino-ESP32 Core 3.3.x */ #define AN_PIN 35 #define NUM_SAMPLES 10000 void setup() { Serial.begin(115200); delay(1000); analogRead(AN_PIN); // First call initializes the ADC unit & channel analogReadMilliVolts(AN_PIN); // First call creates the calibration handle } void loop() { uint32_t t0, t1; volatile int x; t0 = micros(); for (int i = 0; i < NUM_SAMPLES; i++) { x = analogRead(AN_PIN); } t1 = micros(); Serial.printf("analogRead(): %.2f us/sample -> %.1f kSPS\n", (t1 - t0) / (float)NUM_SAMPLES, NUM_SAMPLES * 1000.0 / (t1 - t0)); t0 = micros(); for (int i = 0; i < NUM_SAMPLES; i++) { x = analogReadMilliVolts(AN_PIN); } t1 = micros(); Serial.printf("analogReadMilliVolts(): %.2f us/sample -> %.1f kSPS\n\n", (t1 - t0) / (float)NUM_SAMPLES, NUM_SAMPLES * 1000.0 / (t1 - t0)); (void)x; // the reads are only timed, not used delay(2000); } |

If you need precise timing between samples with analogRead(), call it from a timer interrupt or a timed task. See the ESP32 Timers & Timer Interrupt Tutorial.
Measure 12v (or a Battery) With ESP32 ADC & Voltage Divider (LAB 7)
To measure a voltage higher than 3.3v with the ESP32 ADC, scale it down with a voltage divider and multiply the reading back in your code. With R1 = 30kΩ and R2 = 7.5kΩ (the values on the common “0 – 25v voltage sensor” modules), the divider ratio is 5, so 12v at the input becomes 2.4v at the ESP32 pin.
The formula for the input voltage is:
VIN = VPIN × (R1 + R2) / R2
For example, if analogReadMilliVolts() reads 2400mV: VIN = 2.4 × (30k + 7.5k) / 7.5k = 12.0v. Keep the maximum input below 15.5v with these resistors so the ADC pin stays under 3.1v.

12V+ goes to the top of R1 (30kΩ). This is the voltage you’re measuring, so it never touches an ESP32 pin directly.
GPIO34 goes to the divider’s middle point, between R1 (30kΩ) and R2 (7.5kΩ). GPIO34 is an ADC1 pin, so this works with Wi-Fi on.
GND goes to the bottom of R2, the negative terminal of the 12v source, and the ESP32’s GND.
Here is The Application Code For This Example (ESP32_ADC_Voltage_Divider_LAB7.ino)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
/* * LAB Name: ESP32 ADC Read Higher Voltage With a Voltage Divider (e.g. 12v) * Author: Khaled Magdy * For More Info Visit: www.DeepBlueMbedded.com * Tested With: Arduino-ESP32 Core 3.3.x */ #define AN_VIN_PIN 34 #define R1 30000.0 // Top resistor (Vin -> ADC pin), 30kΩ #define R2 7500.0 // Bottom resistor (ADC pin -> GND), 7.5kΩ #define NUM_AVG 16 void setup() { Serial.begin(115200); } void loop() { uint32_t Sum_mV = 0; for (int i = 0; i < NUM_AVG; i++) { Sum_mV += analogReadMilliVolts(AN_VIN_PIN); } float V_Pin = (Sum_mV / (float)NUM_AVG) / 1000.0; // Voltage at the ADC pin float V_In = V_Pin * (R1 + R2) / R2; // Undo the divider ratio (x5) Serial.print("V_pin = "); Serial.print(V_Pin, 3); Serial.print(" v | V_in = "); Serial.print(V_In, 2); Serial.println(" v"); delay(500); } |
Note: The source being measured and the ESP32 must share the same GND. Use 1% resistors, and for the best accuracy measure your two resistors with a multimeter and put the real values in R1 and R2. The divider’s high impedance can make readings noisy, so the code averages 16 samples (a 100nF capacitor from GPIO34 to GND also helps).
ESP32 ADC Accuracy: When to Use an External ADC (ADS1115)
The ESP32 ADC is fine for potentiometers, light sensors, battery monitoring, and most hobby measurements, especially with analogReadMilliVolts() and some averaging. But it’s not linear near both ends of its range, it’s noisy, and its effective resolution is closer to 9 – 10 bits than 12. For precise measurements, use an external ADC such as the ADS1115 over I2C.
| Parameter | ESP32 Internal ADC | ADS1115 (External, I2C) |
|---|---|---|
| Resolution | 12-bit (≈9 – 10 effective bits) | 16-bit |
| Input Range | ~0.15 – 3.1v (at 11dB) | ±0.256v to ±6.144v (programmable gain) |
| Linearity | Poor near 0v and near 3.1v | Very good across the range |
| Differential Inputs | No | Yes (2 differential or 4 single-ended) |
| Max Sampling Rate | Up to 2MHz (continuous mode) | 860 SPS |
| Works With Wi-Fi | ADC1 only | Yes, any pin (I2C) |
| Best For | Pots, sensors, battery level, fast sampling | Precise voltage, current, and bridge sensors |
My personal opinion: I wouldn’t design a critical measurement system (where human health, safety, or money is involved) around the ESP32’s internal ADC. Use the ESP32 for what it does best (Wi-Fi, BLE, and the application) and offload precise measurements to a dedicated ADC chip or a small microcontroller with a well-documented ADC. It totally depends on the application, though, and at the end of the day, it’s your call.
ESP32 ADC Troubleshooting (analogRead Not Working)
ESP32 analogRead Always Returns 0
The most common cause is an ADC2 pin (GPIO0, 2, 4, 12 – 15, 25 – 27) while Wi-Fi is on: the read fails silently and returns 0. Move the input to an ADC1 pin (GPIO32 – 39). Also check the input isn’t below ~150mV (the dead band), that you used the GPIO number and not the board label, and that the pin is really an ADC pin.
ESP32 analogRead Always Returns 4095
The input is above the top of the range: about 3.1v at 11dB (or lower if you changed the attenuation). Check the wiring (a floating or 3.3v-shorted pin reads 4095), check that the pot isn’t powered from 5v, and use a voltage divider for higher voltages (LAB 7).
ESP32 ADC Readings Are Noisy or Jumping
Add a 100nF capacitor from the ADC pin to GND, average several samples (LAB 4), keep analog wires short and away from the antenna, and power the board from a clean supply. Wi-Fi transmissions add noise too, so sample between transmissions if you can.
‘ledcSetup’ was not declared in this scope
Your sketch uses the core 2.x LEDC API, removed in Arduino-ESP32 core 3.0. Replace ledcSetup(ch, freq, res) + ledcAttachPin(pin, ch) with ledcAttach(pin, freq, res), and write with ledcWrite(pin, duty). See LAB 2.
‘analogSetClockDiv’ was not declared in this scope
This function (and adcAttachPin, analogSetVRefPin, adcStart/adcBusy/adcEnd, analogSetCycles, analogSetSamples) was removed in core 3.0. Delete the line. For a set sampling rate, use continuous mode (LAB 5). See the core 3.x changes table.
esp_adc_cal: legacy adc calibration driver is deprecated
The old esp_adc_cal functions still compile on core 3.x with this warning, but you don’t need them. Replace the whole calibration code with analogReadMilliVolts(pin), which applies the same eFuse calibration (LAB 3).
ESP32-S2 analogRead Returns More Than 4095
Early ESP32-S2 chips (revision v0.0) default to 13-bit readings (0 – 8191) because of an ADC erratum. Call analogReadResolution(12) in setup() to get 0 – 4095.
ESP32 vs ESP32-S3 vs ESP32-C3 ADC
All ESP32 chips use the same Arduino ADC functions, but the number of channels, the pins, the range, and the ADC2 rules differ. On the ESP32-C3, ADC2 can’t be used with analogRead() at all, and the ESP32-C6 has only one ADC.
| Chip | ADC Units | Channels | Range @ 11dB | ADC2 Notes | Continuous Rate |
|---|---|---|---|---|---|
| ESP32 | 2 | 18 (ADC1: 8, ADC2: 10) | 150 – 3100mV | Blocked while Wi-Fi is on | 20kHz – 2MHz |
| ESP32-S2 | 2 | 20 | 0 – 2500mV | Shared with Wi-Fi | 611Hz – 83kHz |
| ESP32-S3 | 2 | 20 (GPIO1 – 20) | 0 – 3100mV | Shared with Wi-Fi | 611Hz – 83kHz |
| ESP32-C3 | 2 | 6 (ADC1: 5, ADC2: 1) | 0 – 2500mV | Not supported in analogRead() | 611Hz – 83kHz |
The LAB sketches in this tutorial use GPIO34 and GPIO35, which are ADC1 pins on the original ESP32 only. On the ESP32-S3, use an ADC1 pin from GPIO1 – GPIO10 (for example GPIO1 and GPIO2), and on the ESP32-C3, use GPIO0 – GPIO4. Everything else in the code stays the same, and the sketches compile for both boards on core 3.3.12.
Wrap Up
To conclude this tutorial, we’ve seen how to use the ESP32 ADC in Arduino core 3.x: reading raw values with analogRead(), reading calibrated voltage with analogReadMilliVolts(), choosing the right ADC1 pins, setting the attenuation, filtering noise, sampling in continuous mode, and measuring higher voltages with a divider. You can build on these examples to read sensors like the LM35 temperature sensor.
If you’ve got any questions or suggestions, drop me a comment below and I’ll be glad to help! And check out the ESP32 Programming Tutorials series for more ESP32 tutorials.
Download ESP32 ADC Project Files
Download all attachment files for this Article/Tutorial (project files, schematics, code, etc.) using the link below. Everything is tested and verified to work on real hardware, as you’ve seen in the demo videos & screenshots. Please consider supporting my work if it helped you.
ESP32 ADC FAQ
Yes. The ESP32 has 18 analog input channels on two 12-bit ADCs: ADC1 on GPIO32 – GPIO39 and ADC2 on GPIO0, 2, 4, 12 – 15 and 25 – 27. The 30-pin DevKit V1 exposes 15 of them. Use the ADC1 pins when your project uses Wi-Fi.
With the default 11dB attenuation, the ESP32 ADC reads up to about 3.1v (3100mV), and the absolute maximum on any pin is 3.3v. To measure higher voltages like 5v or 12v, use a voltage divider and multiply the reading back in code.
No. ESP32 pins are not 5v tolerant, and 5v can damage the pin or the chip. Scale a 5v signal down with a voltage divider (for example 10kΩ from the 5v signal to the pin and 15kΩ from the pin to GND gives 3.0v, inside the 3.1v range).
analogRead() returns the raw, uncalibrated ADC value (0 – 4095 at 12-bit). analogReadMilliVolts() returns the input voltage in mV, corrected with the calibration data stored in the chip’s eFuse, which is much more accurate than converting the raw value with a simple formula.
The ESP32 ADC input is a switched sampling capacitor, not a fixed resistance, so the source impedance matters. Keep the source impedance low (under about 10kΩ), or add a 100nF capacitor at the pin or an op-amp buffer when you read from a high-impedance source like a large voltage divider.
I have a code for counting samples of ADC.I’m attaching the code here.
Code:
#include
#include
#include
const uint16_t samples = 10000;
uint8_t clockDiv =255;
void setup() {
Serial.begin(115200);
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(ADC1_CHANNEL_3, ADC_ATTEN_DB_11);
adc_set_clk_div(clockDiv); //doesn’t work
}
void loop() {
const uint16_t samples = 10000;
auto t1 = std::chrono::system_clock::now();
for (uint32_t i=0; i
adc_buf[i]=adc1_get_raw(ADC1_CHANNEL_3);
}
auto t2 = std::chrono::system_clock::now();
std::chrono::duration diff = t2 – t1;
auto ms = std::chrono::duration_cast(diff).count();
//For seeing output if needed
//for (int j=0; j
// Serial.print(adc_buf[j]);Serial.print(” “);
// }
Serial.println();
Serial.printf(“Samples: %u\n”, samples);
Serial.printf(“Duration: %llums\n”, ms);
Serial.printf(“KSPS: %0.4f”, static_cast(samples) / ms);
Serial.println();
}
The problem is that no clock divider is changing the sampling rate .. My device showing about 20ksps.
Although if I change CPU frequency from the ArduinoIDE settings the code showing sampling rate as low as 1ksps .But why does the adc_set_clk_div(clockDiv) not working.Could you kindly look over this problem ?
Hi Samit!
Well, i’ve looked into this while writing this tutorial.
Your procedure for measuring the adc sampling rate is logically correct.
However, the adc read function is a non-blocking routine. Which means, reading the timer before and after that function will not give you the adc conversion time.
There was a function in the adc driver that was a blocking routine which waits until conversion completion then returns. But they’ve removed it for some reason back in 2019 or something.
I know it can be strange a little bit, but the adc function we have is working asynchronously in a non-blocking way.
This shows you that changing the clock div won’t change anything at all. While changing cpu frequency will change the speed it goes from time capture before and after adc read. This is logical too!
Hope this helps.
Kind regards,
Khaled M.
Thanks a lot for your explanation. Yeah it’s look kinda weird . However then could you suggest any other way of measuring the ADC sampling frequency as I need to know and be able to change it’s ADC sampling frequency for my project. Thanks in advance.
I think switching to espressif IDF can help you get more control over the ADC operation. But with a little bit more complex workflow. I’ll be doing this in the future here on my website.
For now, you can search online if you want to take this route!
Also as mentioned ADC-DMA can be used for faster sampling ,could you kindly demonstarate with example how to store ADC values in DMA and read it. Hoping to see more about DMAs. And yes, you have created an excellent website,your contents are so well explained and brought all together in a
so much organized way.Looking forward to seeing lots of videos and projects from here .
Khaled – thanks for this good post. As to the non-blocking ADC read…does using the (I think) lower-level function sequence in Arduino IDE allow for correct time measurement?
startMicro = micros();
adcStart(ADXLpin);
while(adcBusy(ADXLpin)) {;}
ADXLval = adcEnd(ADXLpin);
endMicro = micros();
While researching this topic, I found out that they’ve removed it from the APIs a few years ago. Try to change the ADC’s clock divider and see if it’s getting faster or slower.
If it’s giving you the same conversion time, then the API is not working in the latest Arduino Framework.
Hello Khaled, thanks for the tutorial… I have spent some precious time on trying to correct it… Now i can trust in the values, at least between 140mV ~ 3120mv, as you mentioned there are dead-bands in both spectrum ends, but i am not expecting reading values near to the ends (i guess…).
But, i have some questions:
first, regarding ADC, do i have to implement the ADC calibration functions on every code? The calibrated values is not stored on register for future use? If i always have to implement, do i have to call the funcitions every time i do an analog read, or it can be just in the initialization? Or run time to time? Have you tested not call the function and noticed some deviation with time (that needs to do a recalibration)?
and now regarding the DAC (pwm function). I noticed that you are using some funcionts to configure the PWM output (such configuration as frequency and resolution), i guess this functions which you are using is not provided by espressif, right? And i have checked on the espressif documention and could not find anything that mention i can change the PWM output characteristics (they say that the resolution is 255 and that is it!) so, could you help on this?
Thanks a lot.
Hii anyone please help me, in testing ADCs. After lots of struggle I found good content so you are only my hope please share your contact number.
Hola Khaled! excelente contenido, hace mucho que busco información del ADC del esp32, muchos dicen que no es de fiar, pero tu has tirado por tierra esto con este articulo, y me has dado una luz de esperanzo en la implementación para mi tesis, medición de variables eléctricas de CA, es viable realizarlo con este micro? Tanto la tensión como la corriente, seria ideal ir por canales distintos, como se implementaría el filtro por hardware del cual hablas?, es viable poder medir algunos armónicos, tanto en tensión como de corriente? Armónicos de 3,5,7,9 en alguna de las formas de onda? Sigue así y ojalá puedas profundizar éste tema del ADC.