Reading a Potentiometer with ADC
Learn how to read an analog voltage on the ESP32-S3 and convert it into a real-world number using the built-in ADC.
The Hardware Setup
A potentiometer is a variable resistor with three legs: two outer legs connect to power and ground, and the middle "wiper" leg outputs a voltage somewhere between the two, depending on the knob position. We'll read that wiper voltage on an ADC-capable GPIO.
Stick to ADC1 pins (GPIO 1–10 on most ESP32-S3 boards) for this project — ADC2 shares hardware with Wi-Fi and can give unreliable readings while the radio is active.
The Arduino Source Code
The ESP32-S3's ADC supports up to 12-bit resolution, giving readings from 0 to 4095. This code reads the raw value and converts it into an actual voltage (0–3.3V) for the Serial Monitor.
// ESP32-S3 Potentiometer + ADC Tutorial - CircuitHub.pro
#include <Arduino.h>
const int POT_PIN = 1; // ADC1_CH0
void setup() {
Serial.begin(115200);
analogReadResolution(12); // Use the full 0-4095 range
}
void loop() {
int raw = analogRead(POT_PIN);
float voltage = (raw / 4095.0) * 3.3;
Serial.print("Raw ADC: ");
Serial.print(raw);
Serial.print(" Voltage: ");
Serial.print(voltage, 2);
Serial.println("V");
delay(200);
}
Required Components
Simple, cheap parts — a great one to keep in your basic toolkit:
🚀 Take It Further
Combine this with the PWM LED Fade tutorial: instead of an automatic fade loop, map the potentiometer's 0–4095 reading directly to the LED's 0–255 duty cycle with map(raw, 0, 4095, 0, 255) and control the brightness manually with the knob.