Introduction
A potentiometer is a variable resistor used to change voltage manually.
In this tutorial, we will interface a potentiometer with ESP32 and display analog values on the Serial Monitor.
Required Components
| Component | Quantity |
|---|---|
| ESP32 Board | 1 |
| Potentiometer (10K) | 1 |
| Breadboard | 1 |
| Jumper Wires | 3 |
Potentiometer Basics
A potentiometer has 3 terminals:
- VCC → Connected to 3.3V
- GND → Connected to Ground
- Middle Pin → Analog Output
Rotating the knob changes the output voltage.
ESP32 Potentiometer Connection
| Potentiometer Pin | ESP32 Connection |
|---|---|
| VCC | 3.3V |
| GND | GND |
| Middle Pin | GPIO 34 |

Arduino IDE Setup
Step 1:
Connect ESP32 board using USB cable.
Step 2:
Open Arduino IDE.
Step 3:
Select Board:
Tools > Board > ESP32 Dev Module
Step 4:
Select correct COM Port.
ESP32 Potentiometer Program
Upload the following code to ESP32.
int potPin = 34;
int potValue = 0;
void setup() {
Serial.begin(115200);
}
void loop() {
potValue = analogRead(potPin);
Serial.println(potValue);
delay(500);
}
Program Explanation
| Code | Purpose |
|---|---|
| analogRead() | Reads analog voltage value |
| Serial.begin(115200) | Starts serial communication |
| Serial.println() | Displays value on Serial Monitor |
| delay(500) | Wait for 500 milliseconds |
Open Serial Monitor
After uploading the code:
Go to:
Tools > Serial Monitor
Set Baud Rate to:
115200
Rotate the potentiometer knob and observe changing values.
Output
ESP32 ADC gives values from:
- 0 → Minimum Voltage
- 4095 → Maximum Voltage
Rotating the potentiometer changes the analog value continuously.
Important Notes
- ESP32 ADC resolution is 12-bit.
- GPIO 34 is input-only pin.
- Use 3.3V supply for ESP32.
- Do not apply more than 3.3V to analog pin.
