ESP32-C6 ADC Knob Dims an LED (PWM): Wiring, Code and Simulator

To build this ESP32-C6 ADC Knob Dims an LED (PWM) project you need an ESP32-C6 DevKitC-1 and a potentiometer, a 220 Ω resistor and a yellow LED. The ESP32-C6 ADC reads a potentiometer on IO1 and LEDC PWM on IO2 sets an LED’s brightness to match. Make the 6 connections in the wiring table, upload the MicroPython code, and turn the knob while it runs. Connect the logic analyzer to IO2 to see the PWM duty change.

Open this circuit in the free ESP32-C6 DevKitC-1 simulator

Parts list

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

Wiring

#FromTo
1ESP32-C6 DevKitC-1 3V3Potentiometer VCC
2ESP32-C6 DevKitC-1 GNDPotentiometer GND
3ESP32-C6 DevKitC-1 IO1Potentiometer SIG
4ESP32-C6 DevKitC-1 IO2220 Ω resistor leg 1
5220 Ω resistor leg 2yellow LED anode (A, long leg)
6ESP32-C6 DevKitC-1 GNDyellow 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-C6 DevKitC-1. No install or account is needed.
  2. Add the parts. Add a potentiometer, a 220 Ω resistor and a yellow LED from the parts palette.
  3. Wire 1. Connect ESP32-C6 DevKitC-1 3V3 to Potentiometer VCC.
  4. Wire 2. Connect ESP32-C6 DevKitC-1 GND to Potentiometer GND.
  5. Wire 3. Connect ESP32-C6 DevKitC-1 IO1 to Potentiometer SIG.
  6. Wire 4. Connect ESP32-C6 DevKitC-1 IO2 to 220 Ω resistor leg 1.
  7. Wire 5. Connect 220 Ω resistor leg 2 to yellow LED anode (A, long leg).
  8. Wire 6. Connect ESP32-C6 DevKitC-1 GND to yellow LED cathode (C, short leg).
  9. Paste the MicroPython code. Paste the MicroPython code below into the code editor.
  10. Run it. Press Run. Turn the knob while it runs. Connect the logic analyzer to IO2 to see the PWM duty change.

MicroPython code

# ESP32-C6: a knob dims an LED.
# The ADC reads the potentiometer on IO1; LEDC PWM on IO2 sets the LED's
# brightness to match, and the serial monitor shows the reading.
from machine import ADC, Pin, PWM
import time

adc = ADC(Pin(1), atten=ADC.ATTN_11DB)
pwm = PWM(Pin(2), freq=1000, duty_u16=0)

while True:
    raw = adc.read_u16()
    pwm.duty_u16(raw)
    print("knob %3d%%  ->  LED duty %5d" % (raw * 100 // 65535, raw))
    time.sleep_ms(200)

What to try

Turn the knob while it runs. Connect the logic analyzer to IO2 to see the PWM duty change.

Frequently asked questions

How do I wire the ADC Knob Dims an LED (PWM) project on an ESP32-C6 DevKitC-1?

Make 6 connections: ESP32-C6 DevKitC-1 3V3 to Potentiometer VCC; ESP32-C6 DevKitC-1 GND to Potentiometer GND; ESP32-C6 DevKitC-1 IO1 to Potentiometer SIG; ESP32-C6 DevKitC-1 IO2 to 220 Ω resistor leg 1; 220 Ω resistor leg 2 to yellow LED anode (A, long leg); ESP32-C6 DevKitC-1 GND to yellow LED cathode (C, short leg).

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

An ESP32-C6 DevKitC-1 and a potentiometer, a 220 Ω resistor and a yellow LED.

Can I simulate this ESP32-C6 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-C6 is emulated instruction by instruction on its RISC-V core, running its own ROM and the official MicroPython firmware.

What does the code do?

The ESP32-C6 ADC reads a potentiometer on IO1 and LEDC PWM on IO2 sets an LED’s brightness to match.

More ESP32-C6 DevKitC-1 projects