A potentiometer (often called a pot) is a variable resistor that allows you to adjust resistance manually by rotating its knob. It is commonly used for volume control, brightness adjustment, and sensor calibration.
When connected to an ESP32, a potentiometer works as a voltage divider, giving an analog output that the ESP32 can read. In this tutorial, we’ll connect a potentiometer to GPIO 34 of ESP32 DOIT DevKit v1 and read its values in the Serial Monitor.
// Potentiometer with ESP32 DOIT DevKit v1
// Pot connected to GPIO 34
int potPin = 34; // Potentiometer connected to ADC pin
int potValue = 0; // Variable to store Pot value
void setup() {
Serial.begin(115200); // Start Serial Monitor
}
void loop() {
potValue = analogRead(potPin); // Read Pot value (0-4095)
Serial.print("Potentiometer Value: ");
Serial.println(potValue);
delay(500); // Small delay for stability
}
Define Variables
int potPin = 34;
int potValue = 0;
potValue
will hold the sensor readings.Setup Serial Monitor
Serial.begin(115200);
Starts serial communication to display potentiometer values.
Loop Function
potValue = analogRead(potPin);
Serial.println(potValue);
Problem | Cause | Solution |
---|---|---|
Values always 0 | Wrong wiring | Connect middle pin to GPIO 34 |
Values unstable | Loose connections | Use good breadboard/jumpers |
Reads only max value | Wrong supply | Connect pot to 3.3V, not 5V |
Serial not showing | Wrong baud rate | Set 115200 in Serial Monitor |
ESP32 gives 0–4095 (12-bit resolution) for analog inputs.
No, ESP32 works at 3.3V logic. Use 3.3V to avoid damage.
Yes ✅, read pot value and map it to LED PWM duty cycle.
ESP32 has multiple ADC pins, so you can connect several potentiometers.
No, ESP32 reads voltage (0–3.3V) as ADC values, not resistance directly.