from machine import ADC, Pin
import time
# Configure ADC pin (GPIO34 is commonly used for analog input)
pot = ADC(Pin(34))
# Set ADC range (0 - 3.3V)
pot.atten(ADC.ATTN_11DB)
# Set ADC width to 12-bit (0 to 4095)
pot.width(ADC.WIDTH_12BIT)
while True:
adc_value = pot.read() # Read analog value
# Convert ADC value to Voltage
voltage = (adc_value / 4095) * 3.3
print("ADC Value:", adc_value)
print("Voltage: {:.2f} V".format(voltage))
print("----------------------")
time.sleep(1)Loading
esp32-devkit-c-v4
esp32-devkit-c-v4