ESP32-C3 Button Interrupt + Blink: Wiring, Code and Simulator

To build this ESP32-C3 Button Interrupt + Blink project you need an ESP32-C3 DevKitM-1 and a 220 Ω resistor, a red LED and a push button. A real ESP32-C3, emulated instruction by instruction: an LED blinks on IO2, a button on IO4 pauses it and counts presses with an interrupt. Make the 5 connections in the wiring table, upload the MicroPython code, and hold the button: the LED stops. Each press runs the IRQ handler; watch the count in the serial monitor.

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

Parts list

QtyPartWhat it does
1ESP32-C3 DevKitM-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-C3 DevKitM-1 IO2220 Ω resistor leg 1
2220 Ω resistor leg 2red LED anode (A, long leg)
3ESP32-C3 DevKitM-1 GNDred LED cathode (C, short leg)
4ESP32-C3 DevKitM-1 IO4push button 1.l
5ESP32-C3 DevKitM-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-C3 DevKitM-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-C3 DevKitM-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-C3 DevKitM-1 GND to red LED cathode (C, short leg).
  6. Wire 4. Connect ESP32-C3 DevKitM-1 IO4 to push button 1.l.
  7. Wire 5. Connect ESP32-C3 DevKitM-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. Hold the button: the LED stops. Each press runs the IRQ handler; watch the count in the serial monitor.

MicroPython code

# ESP32-C3 (real chip emulation): blink an LED, and pause it with a button.
# LED on IO2 through a resistor; the button joins IO4 to GND, and the pin's
# internal pull-up holds it HIGH until you press.
from machine import Pin
import time

led = Pin(2, Pin.OUT)
button = Pin(4, Pin.IN, Pin.PULL_UP)
presses = 0

def on_press(pin):
    global presses
    presses += 1

button.irq(trigger=Pin.IRQ_FALLING, handler=on_press)

while True:
    if button.value() == 0:
        led.off()
    else:
        led.value(not led.value())
    print("presses:", presses)
    time.sleep_ms(400)

What to try

Hold the button: the LED stops. Each press runs the IRQ handler; watch the count in the serial monitor.

Frequently asked questions

How do I wire the Button Interrupt + Blink project on an ESP32-C3 DevKitM-1?

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

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

An ESP32-C3 DevKitM-1 and a 220 Ω resistor, a red LED and a push button.

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?

A real ESP32-C3, emulated instruction by instruction: an LED blinks on IO2, a button on IO4 pauses it and counts presses with an interrupt.

More ESP32-C3 DevKitM-1 projects