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
| Qty | Part | What it does |
|---|---|---|
| 1 | ESP32-C3 DevKitM-1 | the microcontroller board |
| 1 | 220 Ω resistor | Limits current. 220 Ω in series with an LED; 10 kΩ as a pull-up or pull-down. |
| 1 | red LED | Lights when A (anode, the bent leg) is high and C (cathode) is low. Use a resistor. |
| 1 | push button | Connects 1 to 2 while held. Pair with INPUT_PULLUP and wire the other side to GND. |
Wiring
| # | From | To |
|---|---|---|
| 1 | ESP32-C3 DevKitM-1 IO2 | 220 Ω resistor leg 1 |
| 2 | 220 Ω resistor leg 2 | red LED anode (A, long leg) |
| 3 | ESP32-C3 DevKitM-1 GND | red LED cathode (C, short leg) |
| 4 | ESP32-C3 DevKitM-1 IO4 | push button 1.l |
| 5 | ESP32-C3 DevKitM-1 GND | push button 2.l |
Step by step
- 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.
- Add the parts. Add a 220 Ω resistor, a red LED and a push button from the parts palette.
- Wire 1. Connect ESP32-C3 DevKitM-1 IO2 to 220 Ω resistor leg 1.
- Wire 2. Connect 220 Ω resistor leg 2 to red LED anode (A, long leg).
- Wire 3. Connect ESP32-C3 DevKitM-1 GND to red LED cathode (C, short leg).
- Wire 4. Connect ESP32-C3 DevKitM-1 IO4 to push button 1.l.
- Wire 5. Connect ESP32-C3 DevKitM-1 GND to push button 2.l.
- Paste the MicroPython code. Paste the MicroPython code below into the code editor.
- 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.