Writing Arduino Code
Make It Blink
12 minStudent plan
Add timing. Turn the LED on, wait, turn it off, wait, and understand exactly what delay() costs you.
After this lesson you can
- Write a blink sketch with a chosen frequency
- Work out period and duty cycle
- Explain what delay() stops you from doing
Four steps, repeating
Blinking is on, wait, off, wait, placed inside loop() so it repeats forever.
digitalWrite(13, HIGH); delay(500); digitalWrite(13, LOW); delay(500);
That gives one full cycle per second: half a second lit, half a second dark. The period is the sum of both delays, so 500 + 500 = 1000 ms.
Both delays matter. Leave out the second one and the LED goes off and instantly on again at the top of loop(), thousands of times a second, far too fast for your eye, so it simply looks permanently on but slightly dim.
In the full lesson
- Four steps, repeating
- delay() stops everything
- Duty cycle
This lesson comes with the Student plan. The first module of Programming is free.