- LED Blink with Button
- Motion Detection Alarm System
- Simple RGB LED Controller
- Blinking LED with WebSocket Control
- Control LED Brightness using PWM
- Web Page with HTML and CSS on ESP32
- Control Multiple LEDs
- ESP32 with Bluetooth Serial Communication
- EEPROM with ESP32
- ESP32 Push Button Input: Reading Digital States
- Interfacing DHT11 Sensor
- Interfacing Ultrasonic Sensor
- Interfacing Flame Sensor
- Interfacing Sound Sensor
- Interfacing Potentiometer
- Interfacing IR Sensor
- Interfacing Servo Motor
- Interfacing Cam Wireless
- Interfacing DC Motor
- Interfacing Shock Sensor
- Interfacing Color Recognition Sensor
- Interfacing RFID Module
- TTGO LoRa32 SX1276 OLED
- Interfacing Keypad
- Interfacing Solenoid Lock
- Interfacing 16x2 LCD
- Interfacing Soil Moisture
- Interfacing MQ-7 Gas Sensor
- Interfacing Light Sleep Mode
- Interfacing Smart Light Control
- Interfacing (IoT) Weather Station
- Interfacing Web Server for Temperature Data Display
- Interfacing Home Automation System with Relay Control
- Interfacing IoT Smart Garden
- Face Recognition-Based Door Unlock System
- Interfacing Wi-Fi Jammer Detector
- Interfacing Health Band with Pulse
- Interfacing Sound Level Logger for Classrooms
- Night Vision Surveillance Camera
- Solar Panel Monitoring System
- Smart Farming Robot for Crop Surveillance
- Smart Water Quality Monitoring System
- Industrial IoT Gateway for Real-Time Monitoring
- Agriculture System with Automated Drone Control
ESP32 with Potentiometer (HW-040)

Introduction to Potentiometer
A potentiometer is a three-terminal resistor with a sliding contact (wiper) that acts as a voltage divider. When connected to the ESP32's analog input pin, it provides variable analog values that can be read and processed. These values can be used to control brightness, volume, or motor speed. In this experiment, we will read analog values from a potentiometer using the ESP32.
Components Required
We will need a potentiometer (HW-040), an ESP32 development board, and a few jumper wires. The middle terminal (wiper) of the potentiometer will be connected to an analog input pin on the ESP32.
- Connect potentiometer VCC to ESP32 3.3V.
- Connect potentiometer GND to ESP32 GND.
- Connect potentiometer OUT (middle pin) to ESP32 GPIO 34 (or any analog input pin).
- Open the Arduino IDE on your computer.
- Go to Tools > Board > Boards Manager.
- Search for 'ESP32' and install the ESP32 package.
- Select 'ESP32 Dev Module' from the Board menu.
- Connect ESP32 to your computer via USB cable.
- Go to Tools > Port and select the correct COM port.
- Go to Sketch > Include Library > Manage Libraries.
- Search for 'Adafruit Unified Sensor' and install it (if required).
- Paste the provided Arduino code into a new sketch.
- Click Upload (right arrow icon) to upload code to ESP32.
- Wait for the code to compile and upload.
- Open Serial Monitor (Ctrl + Shift + M) and set baud rate to 115200.
- Observe analog values and voltage readings on Serial Monitor.
Formula: Voltage = (analogRead(POT_PIN) * 3.3) / 4095

Components List
- 1 × ESP32 Development Board
- 1 × Potentiometer (HW-040)
- 1 × Breadboard
- 1 × Set of Jumper Wires
- 1 × USB Cable for ESP32
- 1 × Computer with Arduino IDE installed
Pin Configuration
- VCC: Connect to ESP32 3.3V
- GND: Connect to ESP32 GND
- OUT (middle terminal): Connect to ESP32 GPIO 34 (analog input)
Make sure to connect the middle terminal (wiper) of the potentiometer to an analog input pin of the ESP32. GPIO 34 is a good option as it is input-only and supports ADC.

Wiring and Connections
- VCC -> 3.3V
- GND -> GND
- OUT -> GPIO 34

Code for ESP32 and Potentiometer
1#define POT_PIN 34
2
3void setup() {
4 Serial.begin(115200);
5}
6
7void loop() {
8 int potValue = analogRead(POT_PIN);
9 float voltage = (potValue * 3.3) / 4095.0;
10
11 Serial.print("Raw Value: ");
12 Serial.print(potValue);
13 Serial.print(" | Voltage: ");
14 Serial.print(voltage);
15 Serial.println(" V");
16 delay(500);
17}
Code Explanation
- #define POT_PIN 34: Defines the GPIO pin connected to the potentiometer's output.
- analogRead(POT_PIN): Reads the analog value from the potentiometer (range: 0-4095).
- float voltage = (potValue * 3.3) / 4095.0;: Converts the raw ADC value into actual voltage (0 to 3.3V).
- Serial.print(...): Displays the raw and voltage values on the Serial Monitor.
Applications
- Volume and brightness controls
- Analog sensor calibration
- User-controlled input for DIY projects
- Servo angle adjustment based on potentiometer rotation