Ready-to-teach lab
Arduino blink lab: a first program
This Arduino blink lab is a first lesson in code: an LED on pin 13 of a simulated Uno blinks once a second, and students change the sketch to make it do something else.
The lesson
Objective and parts
By the end, students can
- Say what setup() and loop() are for.
- Use pinMode, digitalWrite and delay, and say what LED_BUILTIN stands for.
- Change a program, run it again and describe what changed.
Parts, already on the bench
- An Arduino Uno
- One LED
- One 220 ohm resistor, from pin 13 to the LED
Nothing to hand out or collect: the circuit opens built and wired.
Steps
What students do
Each step is short enough to read out. Students work in the simulator beside this page.
- Open the lab and press Run. The LED blinks once a second.
- Open the code and read it out loud, one line at a time. Which line turns the LED on?
- Change both delay(500) lines to delay(100) and run it again. It blinks five times as fast.
- Make the LED stay on for two seconds and off for a tenth of a second.
- Write a pattern of your own: three short flashes, then a long pause.
- Move the resistor wire from pin 13 to pin 8. Run it, see that the LED stays dark, then fix the sketch.
Questions
Questions for students
Hand these out as they are. The expected answers are under the list, for you.
- What is the number inside delay() measured in?
- How many times does setup() run, and how many times does loop()?
- After the wire moved to pin 8 the LED stopped. What has to change in the sketch?
- With both delays at 5 the LED seems to be on all the time, only dimmer. Why?
Answer key for the teacher
- Milliseconds. delay(500) waits half a second, so on plus off takes one second.
- setup() runs once when the board starts. loop() runs again and again until the power is removed.
- LED_BUILTIN is a name for pin 13. It has to become 8 in all three places: in pinMode and in both digitalWrite lines.
- It is still blinking, 100 times a second, which is faster than the eye can follow. It is off half the time, so it looks dimmer.
Go further
For students who finish early
- Add a second LED on another pin and blink the two in turn.
- Send the letters SOS in Morse code.
Your class
Give this lab to every student
Assign to my class puts this circuit on each student’s class page as a starter. They change their own copy and hand it in, and the work comes back to you in one list.
The class tools are free for 30 days for one class of up to 20 students, with no card. Opening and running the lab needs no account and stays free.
More labs
The other labs in the set
Ohm's lawCircuits. 40 min.Series and parallelCircuits. 45 min.Voltage dividerCircuits. 40 min.LED and resistorCircuits. 30 min.RC circuitElectronics. 50 min.Transistor switchElectronics. 45 min.Logic gatesElectronics. 40 min.Button and LEDArduino. 40 min.Traffic lightArduino. 45 min.Ultrasonic distanceArduino. 45 min.Servo sweepArduino. 40 min.All labsThe whole set on one page.