Skip to content

This project demonstrates how to use **external interrupts** on the **ESP8266** to toggle an LED using a **push button**. Instead of continuously checking button state, the program reacts instantly when the button is pressed — making it more efficient and responsive.

Notifications You must be signed in to change notification settings

asathiskumar98-byte/ESP8266-Push-Button-LED-Toggle-using-Interrupt-MicroPython-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

🚦 ESP8266 Push Button LED Toggle using Interrupt (MicroPython)

This project demonstrates how to use external interrupts on the ESP8266 to toggle an LED using a push button.
Instead of continuously checking button state, the program reacts instantly when the button is pressed — making it more efficient and responsive.


🧠 Project Overview

Component Description
Board ESP8266
IDE Thonny IDE
Language MicroPython
USB Driver Silicon Labs CP210x USB to UART Bridge
LED Pin GPIO2
Button Pin GPIO0 (Active LOW)

⚙️ Requirements

  • ESP8266 (NodeMCU or compatible)
  • 1 LED + 220Ω resistor
  • 1 Push Button
  • Micro USB cable
  • Thonny IDE
  • CP210x USB Driver
  • MicroPython firmware installed on ESP8266

🧩 Circuit Connections

ESP8266 Pin Component Description
GPIO2 LED Output (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 to prevent floating input issues.


💻 Code

import machine

# GPIO2 = one LED connected
# GPIO0 = pushbutton

led = machine.Pin(2, machine.Pin.OUT)
button = machine.Pin(0, machine.Pin.IN)

def button_function(pin):
    led.value(not led.value())  # Toggle LED state

button.irq(trigger=machine.Pin.IRQ_FALLING, handler=button_function)

About

This project demonstrates how to use **external interrupts** on the **ESP8266** to toggle an LED using a **push button**. Instead of continuously checking button state, the program reacts instantly when the button is pressed — making it more efficient and responsive.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages