ESP32-C3 ADC Potentiometer Meter: Wiring, Code and Simulator

To build this ESP32-C3 ADC Potentiometer Meter project you need an ESP32-C3 DevKitM-1 and a potentiometer, three 220 Ω resistors, a green LED, a yellow LED and a red LED. The ESP32-C3 ADC reads a potentiometer on IO1 (raw and eFuse-calibrated millivolts) and lights a three-LED level meter. Make the 12 connections in the wiring table, upload the MicroPython code, and turn the knob while it runs: read_u16() is the raw reading, read_uv() the calibrated voltage in microvolts.

Open this circuit in the free ESP32-C3 DevKitM-1 simulator

Parts list

QtyPartWhat it does
1ESP32-C3 DevKitM-1the microcontroller board
1PotentiometerVCC to 5V, GND to GND, SIG to an analog pin. Drag the knob; analogRead gives 0–1023.
3220 Ω resistorLimits current. 220 Ω in series with an LED; 10 kΩ as a pull-up or pull-down.
1green LEDLights when A (anode, the bent leg) is high and C (cathode) is low. Use a resistor.
1yellow LEDLights when A (anode, the bent leg) is high and C (cathode) is low. Use a resistor.
1red LEDLights when A (anode, the bent leg) is high and C (cathode) is low. Use a resistor.

Wiring

#FromTo
1ESP32-C3 DevKitM-1 3V3Potentiometer VCC
2ESP32-C3 DevKitM-1 GNDPotentiometer GND
3ESP32-C3 DevKitM-1 IO1Potentiometer SIG
4ESP32-C3 DevKitM-1 IO2220 Ω resistor (r1) leg 1
5220 Ω resistor (r1) leg 2green LED anode (A, long leg)
6ESP32-C3 DevKitM-1 GNDgreen LED cathode (C, short leg)
7ESP32-C3 DevKitM-1 IO3220 Ω resistor (r2) leg 1
8220 Ω resistor (r2) leg 2yellow LED anode (A, long leg)
9ESP32-C3 DevKitM-1 GNDyellow LED cathode (C, short leg)
10ESP32-C3 DevKitM-1 IO5220 Ω resistor (r3) leg 1
11220 Ω resistor (r3) leg 2red LED anode (A, long leg)
12ESP32-C3 DevKitM-1 GNDred LED cathode (C, short leg)

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the ESP32-C3 DevKitM-1. No install or account is needed.
  2. Add the parts. Add a potentiometer, three 220 Ω resistors, a green LED, a yellow LED and a red LED from the parts palette.
  3. Wire 1. Connect ESP32-C3 DevKitM-1 3V3 to Potentiometer VCC.
  4. Wire 2. Connect ESP32-C3 DevKitM-1 GND to Potentiometer GND.
  5. Wire 3. Connect ESP32-C3 DevKitM-1 IO1 to Potentiometer SIG.
  6. Wire 4. Connect ESP32-C3 DevKitM-1 IO2 to 220 Ω resistor (r1) leg 1.
  7. Wire 5. Connect 220 Ω resistor (r1) leg 2 to green LED anode (A, long leg).
  8. Wire 6. Connect ESP32-C3 DevKitM-1 GND to green LED cathode (C, short leg).
  9. Wire 7. Connect ESP32-C3 DevKitM-1 IO3 to 220 Ω resistor (r2) leg 1.
  10. Wire 8. Connect 220 Ω resistor (r2) leg 2 to yellow LED anode (A, long leg).
  11. Wire 9. Connect ESP32-C3 DevKitM-1 GND to yellow LED cathode (C, short leg).
  12. Wire 10. Connect ESP32-C3 DevKitM-1 IO5 to 220 Ω resistor (r3) leg 1.
  13. Wire 11. Connect 220 Ω resistor (r3) leg 2 to red LED anode (A, long leg).
  14. Wire 12. Connect ESP32-C3 DevKitM-1 GND to red LED cathode (C, short leg).
  15. Paste the MicroPython code. Paste the MicroPython code below into the code editor.
  16. Run it. Press Run. Turn the knob while it runs: read_u16() is the raw reading, read_uv() the calibrated voltage in microvolts.

MicroPython code

# ESP32-C3 (real chip emulation): read a potentiometer with the ADC.
# ADC1 is on IO0-IO4; this knob is on IO1. With 11 dB attenuation the input
# range is about 0-3.1 V. The LEDs on IO2, IO3 and IO5 show a 3-step level meter.
from machine import Pin, ADC
import time

knob = ADC(Pin(1), atten=ADC.ATTN_11DB)
leds = [Pin(n, Pin.OUT) for n in (2, 3, 5)]

while True:
    raw = knob.read_u16()          # 0..65535
    mv = knob.read_uv() // 1000    # calibrated millivolts, from the chip's eFuse calibration
    level = raw * 4 // 65536       # 0..3
    for i, led in enumerate(leds):
        led.value(i < level)
    print("raw", raw, "mV", mv, "level", level)
    time.sleep_ms(300)

What to try

Turn the knob while it runs: read_u16() is the raw reading, read_uv() the calibrated voltage in microvolts.

Frequently asked questions

How do I wire the ADC Potentiometer Meter project on an ESP32-C3 DevKitM-1?

Make 12 connections: ESP32-C3 DevKitM-1 3V3 to Potentiometer VCC; ESP32-C3 DevKitM-1 GND to Potentiometer GND; ESP32-C3 DevKitM-1 IO1 to Potentiometer SIG; ESP32-C3 DevKitM-1 IO2 to 220 Ω resistor (r1) leg 1; 220 Ω resistor (r1) leg 2 to green LED anode (A, long leg); ESP32-C3 DevKitM-1 GND to green LED cathode (C, short leg); ESP32-C3 DevKitM-1 IO3 to 220 Ω resistor (r2) leg 1; 220 Ω resistor (r2) leg 2 to yellow LED anode (A, long leg); ESP32-C3 DevKitM-1 GND to yellow LED cathode (C, short leg); ESP32-C3 DevKitM-1 IO5 to 220 Ω resistor (r3) leg 1; 220 Ω resistor (r3) leg 2 to red LED anode (A, long leg); ESP32-C3 DevKitM-1 GND to red LED cathode (C, short leg).

What parts do I need for this ESP32-C3 project?

An ESP32-C3 DevKitM-1 and a potentiometer, three 220 Ω resistors, a green LED, a yellow LED and a red LED.

Can I simulate this ESP32-C3 project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and MicroPython code in your browser for free, with no install and no hardware. The ESP32-C3 is emulated instruction by instruction on a RISC-V core running the official MicroPython firmware.

What does the code do?

The ESP32-C3 ADC reads a potentiometer on IO1 (raw and eFuse-calibrated millivolts) and lights a three-LED level meter.

More ESP32-C3 DevKitM-1 projects