from machine import Pin, ADC
import time
# Define the ESP32 pin connected to the potentiometer
potentiometer_pin = 34 # You can change this to your desired pin
# Create an ADC object for the potentiometer pin
adc = ADC(Pin(potentiometer_pin))
while True :
# Read the analog value from the potentiometer (0 to 4095)
analog_value = adc.read()
# Print the analog value to the serial console
print("Analog value:", analog_value)
# Optionally, convert the analog value to voltage (0 to 3.3V)
voltage = analog_value * (3.3 / 4095)
print("Voltage:", voltage, "V")
time.sleep_ms(1000)