Introduction To Coding Class

Lesson #2: Blink an LED

The Signal Pulse

The clocktower's brass mechanisms tick steadily in the morning air as you climb the spiral staircase to Engineer Cogsworth's workshop. Steam hisses from the pipes lining the walls, and the familiar scent of oil and metal fills your nostrils. Today feels different though. Today, you're not just learning about gears and springs.

"Ah, perfect timing," Cogsworth says without looking up from his workbench. His brass goggles reflect the light from a small red beacon pulsing rhythmically on his desk. "The city's communication network is expanding, and we need reliable signal repeaters. Every lighthouse, every guard tower, every emergency beacon needs to pulse with precise timing."

He turns to face you, the red light casting dancing shadows across his weathered face. "This little device might seem simple, but it's the foundation of how machines communicate across distances. Before we can build complex systems that talk to each other, we need to master the art of the controlled pulse."

The beacon continues its steady rhythm: on, off, on, off. Each pulse carries meaning, each pause has purpose. In your hands lies the power to bring silicon and copper to life, to make electricity dance to your commands. The city's future communications network starts here, with you, with this single blinking light.

What You'll Learn

When you finish this lesson, you'll be able to:

  • Wire an LED to your HERO Board safely and correctly
  • Write code that turns an LED on and off with precise timing
  • Control the speed of blinking by changing delay values
  • Understand how digitalWrite() sends HIGH and LOW signals
  • Debug common wiring mistakes that prevent LEDs from lighting
  • Experiment with different blink patterns and timing sequences

Understanding Digital Signals

Think of your bedroom light switch. It has exactly two positions: completely on or completely off. There's no halfway setting, no dimmer control, just two distinct states. Digital electronics work the same way.

When your microcontroller sends a digital signal, it's like flipping that light switch. HIGH means "switch on" (5 volts flowing), and LOW means "switch off" (0 volts, connected to ground). Your LED responds to these commands instantly, lighting up when it receives HIGH and going dark when it receives LOW.

The magic happens when you control the timing. By rapidly switching between HIGH and LOW states, you create patterns. A lighthouse beacon doesn't just turn on and stay on forever. It pulses with a specific rhythm that ships can recognize from miles away. Your LED will do the same thing, but instead of guiding ships, it's teaching you the fundamental language that all digital devices use to communicate.

This concept underlies everything in modern electronics. Whether it's your phone's notification light, a computer's power indicator, or the brake lights on a car, they're all controlled by the same principle: precisely timed HIGH and LOW signals creating meaningful patterns.

Wiring Your LED Circuit

LED wiring diagram
  1. Connect the LED's long leg (positive/anode) to digital pin 8 on your HERO Board
  2. Connect the LED's short leg (negative/cathode) to any GND (ground) pin
  3. Double-check that the long leg goes to pin 8 and short leg goes to ground

Why this wiring matters: LEDs are polarized components, meaning electricity must flow through them in the correct direction. The long leg is the anode (positive terminal) where current enters. The short leg is the cathode (negative terminal) where current exits toward ground.

Pin 8 can output either 5V (HIGH) or 0V (LOW). When we set it HIGH, current flows from pin 8, through the LED, and down to ground, lighting the LED. When we set it LOW, pin 8 becomes 0V just like ground, so no current flows and the LED stays dark.

Tip

If your LED doesn't light up, try flipping it around. LEDs only work in one direction, and getting the legs backwards is the most common mistake.

Code Walkthrough: Building Your Blink Program

Just like we learned with the servo motor, we start by telling our program which pin controls what. This time, we're controlling an LED instead of a motor.

Step 1: Declare Your LED Pin

int LEDPIN = 8;

This line creates a variable named LEDPIN and sets it equal to 8. Think of it as giving a nickname to pin 8. Throughout your program, whenever you write LEDPIN, the microcontroller knows you mean digital pin 8.