ESP32-C6 RGB LED, Blink and Button Interrupt: Wiring, Code and Simulator

To build this ESP32-C6 RGB LED, Blink and Button Interrupt project you need an ESP32-C6 DevKitC-1 and a 220 Ω resistor, a red LED and a push button. A real ESP32-C6 (RISC-V), emulated instruction by instruction: the on-board RGB LED cycles colours over RMT, an LED blinks on IO2, and an interrupt counts button presses on IO4. Make the 5 connections in the wiring table, upload the MicroPython code, and press the button and watch the count in the serial monitor. Change the colours list to your own.

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

Parts list

QtyPartWhat it does
1ESP32-C6 DevKitC-1the microcontroller board
1220 Ω resistorLimits current. 220 Ω in series with an LED; 10 kΩ as a pull-up or pull-down.
1red LEDLights when A (anode, the bent leg) is high and C (cathode) is low. Use a resistor.
1push buttonConnects 1 to 2 while held. Pair with INPUT_PULLUP and wire the other side to GND.

Wiring

#FromTo
1ESP32-C6 DevKitC-1 IO2220 Ω resistor leg 1
2220 Ω resistor leg 2red LED anode (A, long leg)
3ESP32-C6 DevKitC-1 GNDred LED cathode (C, short leg)
4ESP32-C6 DevKitC-1 IO4push button 1.l
5ESP32-C6 DevKitC-1 GNDpush button 2.l

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 220 Ω resistor, a red LED and a push button from the parts palette.
  3. Wire 1. Connect ESP32-C6 DevKitC-1 IO2 to 220 Ω resistor leg 1.
  4. Wire 2. Connect 220 Ω resistor leg 2 to red LED anode (A, long leg).
  5. Wire 3. Connect ESP32-C6 DevKitC-1 GND to red LED cathode (C, short leg).
  6. Wire 4. Connect ESP32-C6 DevKitC-1 IO4 to push button 1.l.
  7. Wire 5. Connect ESP32-C6 DevKitC-1 GND to push button 2.l.
  8. Paste the MicroPython code. Paste the MicroPython code below into the code editor.
  9. Run it. Press Run. Press the button and watch the count in the serial monitor. Change the colours list to your own.

MicroPython code

# ESP32-C6: the on-board RGB LED, an LED and a button.
# A real ESP32-C6 (RISC-V), emulated instruction by instruction on its own ROM.
# The RGB LED on IO8 cycles colours (a WS2812 driven by the RMT peripheral),
# the LED on IO2 blinks, and the button on IO4 counts presses with an interrupt.
from machine import Pin
import neopixel, time

led = Pin(2, Pin.OUT)
rgb = neopixel.NeoPixel(Pin(8), 1)
presses = 0

def pressed(pin):
    global presses
    presses += 1
    print("button presses:", presses)

btn = Pin(4, Pin.IN, Pin.PULL_UP)
btn.irq(trigger=Pin.IRQ_FALLING, handler=pressed)

colours = [(40, 0, 0), (0, 40, 0), (0, 0, 40), (30, 20, 0), (0, 25, 30), (25, 0, 30)]
i = 0
while True:
    rgb[0] = colours[i % len(colours)]
    rgb.write()
    led.value(i % 2)
    i += 1
    time.sleep_ms(400)

What to try

Press the button and watch the count in the serial monitor. Change the colours list to your own.

Frequently asked questions

How do I wire the RGB LED, Blink and Button Interrupt project on an ESP32-C6 DevKitC-1?

Make 5 connections: ESP32-C6 DevKitC-1 IO2 to 220 Ω resistor leg 1; 220 Ω resistor leg 2 to red LED anode (A, long leg); ESP32-C6 DevKitC-1 GND to red LED cathode (C, short leg); ESP32-C6 DevKitC-1 IO4 to push button 1.l; ESP32-C6 DevKitC-1 GND to push button 2.l.

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

An ESP32-C6 DevKitC-1 and a 220 Ω resistor, a red LED and a push button.

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?

A real ESP32-C6 (RISC-V), emulated instruction by instruction: the on-board RGB LED cycles colours over RMT, an LED blinks on IO2, and an interrupt counts button presses on IO4.

More ESP32-C6 DevKitC-1 projects