Lesson 03: Your First Sketch — Blinking an LED

Course: Robotics & Arduino Lesson 03 of 12

Master digitalWrite, delay, setup(), loop() and build 3 LED projects.


Learning Objectives

By the end of this lesson you will be able to:


Hardware Required

See the Kit List on the course overview page for the full component list. For this lesson you will specifically need the components mentioned in the steps below.


Step-by-Step Guide

  1. Wire an external LED: long leg (anode) → 220Ω resistor → pin 7. Short leg (cathode) → GND.
  2. Write your own Blink from scratch. Use pinMode(7, OUTPUT) in setup.
  3. In loop: digitalWrite(7, HIGH); delay(1000); digitalWrite(7, LOW); delay(1000);
  4. Upload. External LED blinks at 1Hz.
  5. Now add a second LED on pin 8. Make them alternate (one on, one off).
  6. Build a traffic light: 3 LEDs (red/pin 5, yellow/pin 6, green/pin 7). Sequence: green 5s → yellow 1s → red 5s → repeat.
  7. Add a for loop that cycles through 3 LEDs: for(int i=5; i<=7; i++) { ... }.
  8. Use the Serial Monitor to print a message each time the light changes.
  9. Use a variable int delayTime = 1000; and change it to affect all delays at once.
  10. Add a function void flashAll() that flashes all 3 LEDs simultaneously.

Extension Challenges


Review Questions

  1. Explain in your own words what this lesson’s main component does.
  2. What would happen if you changed one key parameter in your sketch?
  3. How does this lesson’s content connect to the final robot build in Lesson 12?

Troubleshooting Tips


Back to Course Next: Lesson 04