This project shows how to control an LED using a push button connected to an ESP8266 microcontroller.
It’s a simple digital input/output example using MicroPython in the Thonny IDE.
| Component | Description |
|---|---|
| Board | ESP8266 |
| IDE | Thonny IDE |
| Language | MicroPython |
| USB Driver | Silicon Labs CP210x USB to UART Bridge |
| LED Pin | GPIO2 |
| Push Button Pin | GPIO0 |
- ESP8266 (NodeMCU or compatible)
- 1 LED + 220Ω resistor
- 1 Push Button
- Micro USB cable
- Thonny IDE
- CP210x USB Driver
- MicroPython firmware flashed on ESP8266
| ESP8266 Pin | Component | Description |
|---|---|---|
| GPIO2 | LED | Active Low |
| GPIO0 | Push Button | Input (active low) |
| GND | LED (-) and Button GND | Common Ground |
💡 Tip: Use a pull-up resistor (or internal pull-up) on GPIO0 if your button behaves erratically.
import machine # GPIO2 = LED # GPIO0 = Pushbutton led = machine.Pin(2, machine.Pin.OUT) button = machine.Pin(0, machine.Pin.IN) while True: if button.value() == 0: # Button pressed led.value(0) # LED ON else: # Button released led.value(1) # LED OFF