๐Ÿ’ก Level 1 โ€“ Fundamentals

Project 1.2: "Hello World LED"

ย 

๐Ÿš€ Project 1.2 โ€“ Hello World LED

๐ŸŽฏ What Youโ€™ll Learn

  • โœ… Goal 1: Blink a LED on and off.
  • โœ… Goal 2: Control blink speed.
  • โœ… Goal 3: Create simple patterns like SOS Morse code.

Key Ideas

  • Digital output: Send ON/OFF signals to a pin.
  • Delay: Pause for a set time.
  • Loop: Repeat actions forever.
  • Pattern: Combine timing to make rhythms.

๐Ÿงฑ Blocks Glossary (used in this project)

  • Digital output: Turn a pin ON (HIGH) or OFF (LOW).
  • Delay: Pause the program for a set time.
  • Loop (while True): Repeat actions forever.
  • Loop (for): Repeat a fixed number of times.

๐Ÿงฐ What You Need

PartHow many?Pin connection
D1 R321USB cable (30 cm)
LED (10mm)1Pin 2 โ†’ GND
Shield1For easy wiring

๐Ÿ”Œ Wiring tip: Connect LED long leg to Pin 2, short leg to GND.
๐Ÿ“ Pin map snapshot: Pin 2 will be our LED control pin.


โœ… Before You Start

  • USB cable is plugged in
  • LED connected correctly (long leg = Pin 2, short leg = GND)
  • Test print shows:
print("Ready!")  # Confirm serial is working

๐ŸŽฎ Microprojects (5 Mini Missions)


๐ŸŽฎ Microproject 1.2.1 โ€“ Basic LED Blink (1s)

Goal: Blink LED every 1 second.
Blocks used: Digital output, Delay, Loop
Block sequence:

  1. Setup Pin 2 as output
  2. LED ON โ†’ Delay 1s
  3. LED OFF โ†’ Delay 1s
  4. Repeat forever

MicroPython Code:

import machine, time                  # Importa librerรญas para controlar pines y tiempo
pin2 = machine.Pin(2, machine.Pin.OUT) # Configura el pin 2 como salida digital

while True:                           # Bucle infinito
    pin2.value(1)                      # LED ON
    print("LED ON")                    # Mensaje serial
    time.sleep(1)                      # Espera 1 segundo
    pin2.value(0)                      # LED OFF
    print("LED OFF")                   # Mensaje serial
    time.sleep(1)                      # Espera 1 segundo

Reflection: Your robot can now control light!
Challenge: Change delay to 0.5s for faster blinking.


๐ŸŽฎ Microproject 1.2.2 โ€“ LED Flashing Rapidly (0.5s)

Goal: Blink LED every 0.5 seconds.
Blocks used: Digital output, Delay, Loop
Block sequence:

  1. Setup Pin 2 as output
  2. LED ON โ†’ Delay 0.5s
  3. LED OFF โ†’ Delay 0.5s
  4. Repeat forever

MicroPython Code:

import machine, time                  # Importa librerรญas
pin2 = machine.Pin(2, machine.Pin.OUT) # Configura pin 2 como salida

while True:                           # Bucle infinito
    pin2.value(1)                      # LED ON
    print("LED ON")                    # Mensaje serial
    time.sleep(0.5)                    # Espera medio segundo
    pin2.value(0)                      # LED OFF
    print("LED OFF")                   # Mensaje serial
    time.sleep(0.5)                    # Espera medio segundo

Reflection: Speed changes the rhythm.
Challenge: Try 0.2s for super-fast blinking.


๐ŸŽฎ Microproject 1.2.3 โ€“ LED Slow Blink (2s)

Goal: Blink LED every 2 seconds.
Blocks used: Digital output, Delay, Loop
Block sequence:

  1. Setup Pin 2 as output
  2. LED ON โ†’ Delay 2s
  3. LED OFF โ†’ Delay 2s
  4. Repeat forever

MicroPython Code:

import machine, time                  # Importa librerรญas
pin2 = machine.Pin(2, machine.Pin.OUT) # Configura pin 2 como salida

while True:                           # Bucle infinito
    pin2.value(1)                      # LED ON
    print("LED ON")                    # Mensaje serial
    time.sleep(2)                      # Espera 2 segundos
    pin2.value(0)                      # LED OFF
    print("LED OFF")                   # Mensaje serial
    time.sleep(2)                      # Espera 2 segundos

Reflection: Longer delays make the LED look calm.
Challenge: Try 3s for extra slow blinking.


๐ŸŽฎ Microproject 1.2.4 โ€“ Brightness Control with Delay

Goal: Simulate brightness by changing ON/OFF timing.
Blocks used: Digital output, Delay, Loop
Block sequence:

  1. LED ON โ†’ Delay short
  2. LED OFF โ†’ Delay long
  3. Repeat forever

MicroPython Code:

import machine, time                  # Importa librerรญas
pin2 = machine.Pin(2, machine.Pin.OUT) # Configura pin 2 como salida

while True:                           # Bucle infinito
    pin2.value(1)                      # LED ON (bright)
    print("LED ON (bright)")           # Mensaje serial
    time.sleep(0.1)                    # Corto tiempo encendido
    pin2.value(0)                      # LED OFF (dim)
    print("LED OFF (dim)")             # Mensaje serial
    time.sleep(0.9)                    # Largo tiempo apagado

Reflection: Timing can simulate brightness.
Challenge: Reverse ON/OFF times for opposite effect.


๐ŸŽฎ Microproject 1.2.5 โ€“ SOS Morse

Goal: Blink LED in SOS pattern (… — …).
Blocks used: Digital output, Delay, For loop
Block sequence:

  1. Setup Pin 2 as output
  2. Blink 3 short (dot)
  3. Blink 3 long (dash)
  4. Blink 3 short (dot)
  5. Pause and repeat

MicroPython Code:

import machine, time                  # Importa librerรญas
pin2 = machine.Pin(2, machine.Pin.OUT) # Configura pin 2 como salida

while True:                           # Bucle infinito
    for i in range(0, 3, 1):          # Tres puntos
        pin2.value(1); print("DOT")   # LED ON corto + mensaje
        time.sleep(0.3)               # Espera 0.3 segundos
        pin2.value(0)                 # LED OFF
        time.sleep(0.3)               # Espera 0.3 segundos

    for i in range(0, 3, 1):          # Tres rayas
        pin2.value(1); print("DASH")  # LED ON largo + mensaje
        time.sleep(0.9)               # Espera 0.9 segundos
        pin2.value(0)                 # LED OFF
        time.sleep(0.3)               # Espera 0.3 segundos

    for i in range(0, 3, 1):          # Tres puntos
        pin2.value(1); print("DOT")   # LED ON corto + mensaje
        time.sleep(0.3)               # Espera 0.3 segundos
        pin2.value(0)                 # LED OFF
        time.sleep(0.3)               # Espera 0.3 segundos

    time.sleep(2)                      # Pausa antes de repetir

Reflection: Your robot can send signals like a lighthouse.
Challenge: Try another Morse code letter.


โœจ Main Project โ€“ Hello World LED

๐Ÿ”ง Blocks Steps (with glossary)

  • Digital output: Control LED ON/OFF
  • Delay: Control timing
  • Loop: Repeat pattern

Block sequence:

  1. Setup LED pin
  2. Blink LED with different delays
  3. Create SOS pattern

๐Ÿ MicroPython Code (mirroring blocks)

# Project 1.2 โ€“ Hello World LED

import machine, time                  # Importa librerรญas para controlar pines y tiempo
pin2 = machine.Pin(2, machine.Pin.OUT) # Configura el pin 2 como salida digital

while True:                           # Bucle infinito
    pin2.value(1)                      # LED ON
    print("LED ON")                    # Mensaje serial
    time.sleep(1)                      # Espera 1 segundo
    pin2.value(0)                      # LED OFF
    print("LED OFF")                   # Mensaje serial
    time.sleep(1)                      # Espera 1 segundo

๐Ÿ“– External Explanation

  • What it teaches: Robots can control light patterns with code.
  • Why it works: Digital output sends ON/OFF signals to the LED pin, and delays control timing.
  • Key concept: Timing + repetition = visible patterns.

โœจ Story Time

Imagine your robot is a lighthouse. It blinks to guide ships safely. By changing timing, you can send secret codes like SOS!


๐Ÿ•ต๏ธ Debugging (2 Common Problems)

๐Ÿž Debugging 1.2.A โ€“ LED does not light up (incorrect pin)

Problem: LED stays off.
Clues: Wrong pin or reversed legs.
Broken code:

pin5 = machine.Pin(5, machine.Pin.OUT)   # Pin incorrecto

Fixed code:

pin2 = machine.Pin(2, machine.Pin.OUT)   # Pin correcto para LED

Why it works: Pin 2 is the correct connection for the LED.
Avoid next time: Always check wiring and pin numbers.


๐Ÿž Debugging 1.2.B โ€“ Irregular blinking (improperly configured delay)

Problem: LED blinks too fast or too slow.
Clues: Delay values are wrong.
Broken code:

time.sleep(0.05)   # Demasiado rรกpido

Fixed code:

time.sleep(1)      # Valor correcto para 1 segundo

Why it works: Proper delay values control blink speed.
Avoid next time: Match time.sleep() to the intended rhythm.


โœ… Final Checklist

  • LED blinked once with test code
  • LED blinked at different speeds
  • SOS pattern worked

๐Ÿ“š Extras

  • ๐Ÿง  Student tip: Try spelling your initials with blink counts.
  • ๐Ÿง‘โ€๐Ÿซ Instructor tip: Watch for reversed LED legs.
  • ๐Ÿ“– Glossary: Digital output, Delay, Loop.
  • ๐Ÿ’ก Mini tips: Always test with a simple blink before complex patterns.
On this page