Skip to main content

Build. Learn.
Innovate.

LED Control and Blinking Patterns

Written By:

Published on:

Project Overview

In this project, students learn how to control one or more LEDs using an ESP32 microcontroller and MicroPython. They’ll experiment with turning LEDs on and off, controlling multiple LEDs in patterns, and adjusting blinking speeds. This introduces key concepts in hardware control, timing, and logic.

Educational Goals

  • Learn how digital outputs control physical components
  • Understand GPIO pin configuration on ESP32
  • Write functions to control time-based actions
  • Build awareness of sequential logic through LED patterns
  • Enhance problem-solving skills through hands-on testing

Detailed Parts List

  • 1x ESP32 Dev Board (36-pin)
  • 3x LEDs (any color)
  • 3x 220Ω Resistors
  • Jumper wires
  • Breadboard
  • USB Cable (for power and programming)

Circuit Diagram Description

  • Each LED is connected to a GPIO pin through a 220Ω resistor to ground.

ESP32 GPIO23 —-> [220Ω] —-> |>| —-> GND
ESP32 GPIO22 —-> [220Ω] —-> |>| —-> GND
ESP32 GPIO21 —-> [220Ω] —-> |>| —-> GND

Software Functionality

  • Control single and multiple LEDs
  • Implement different blinking patterns
  • Adjust timing intervals
  • Group LEDs for sequential or alternating effects

Web Interface Features (Optional Extension)

  • Simple webpage with buttons to trigger LED patterns
  • Toggle buttons for manual LED control
  • Dropdown to select pattern or blinking speed

Implementation Steps

  1. Build the LED circuit on the breadboard
  2. Connect ESP32 to computer and flash MicroPython
  3. Write and upload “** using your IDE (e.g. Thonny)**
  4. Observe LED blinking patterns and modify code
  5. Experiment with pattern functions

Extensions and Challenges

  • Add more LEDs and create more complex patterns
  • Sync patterns to button presses
  • Create a Morse code flasher
  • Add sound using a piezo buzzer
  • Connect via Wi-Fi to trigger patterns remotely

Troubleshooting Guide

  • LED not lighting: Check polarity and GPIO pin number
  • No blinking: Ensure the sleep() function is used correctly
  • All LEDs stay on: Confirm they’re not wired directly to power
  • ESP32 not responding: Confirm correct COM port and MicroPython firmware

Project Code


from machine import Pin
from time import sleep

# Define LED pins
led1 = Pin(23, Pin.OUT)
led2 = Pin(22, Pin.OUT)
led3 = Pin(21, Pin.OUT)

# Blink all LEDs in sequence
def blink_sequence():
for led in [led1, led2, led3]:
led.on()
sleep(0.3)
led.off()
sleep(0.3)

# Alternate LEDs
def alternate():
led1.on()
led2.off()
led3.on()
sleep(0.5)
led1.off()
led2.on()
led3.off()
sleep(0.5)

# Main loop
while True:
blink_sequence()
alternate()

STEM Benefits

  • Science: Understand basic electricity and how energy flows through circuits.
  • Technology: Explore how microcontrollers are programmed to automate tasks.
  • Engineering: Build circuits that control LED behavior using software.
  • Math: Learn about timing, frequency, and how delay intervals affect blinking patterns.

Project Code

Projects
ShowCase

Real-World Projects
with Code & Hardware

Insights, Ideas
& How-Tos

Help, Support, and
Common Questions

What types of projects can I find on your website?

You can explore a wide range of microcontroller and electronics projects, including Arduino, ESP32, IoT, and more. Each project comes with downloadable code, detailed guides, and the necessary hardware list.

You can explore a wide range of microcontroller and electronics projects, including Arduino, ESP32, IoT, and more. Each project comes with downloadable code, detailed guides, and the necessary hardware list.

You can explore a wide range of microcontroller and electronics projects, including Arduino, ESP32, IoT, and more. Each project comes with downloadable code, detailed guides, and the necessary hardware list.

You can explore a wide range of microcontroller and electronics projects, including Arduino, ESP32, IoT, and more. Each project comes with downloadable code, detailed guides, and the necessary hardware list.