Arduino LED
Light can do more than switch on and off; you can set its brightness too. Arduino uses PWM: the pin flickers very fast and your eye sees the average brightness.
Make a 'breathing' light and mix red, green and blue in an RGB LED. Build a light chaser on an LED module and a countdown timer on a 7-segment display.
In this lab
- PWM and analogWrite
- RGB colour mixing
- light chaser
- 7-segment display
What you learn
Light can be dimmed and coloured, not only switched on and off. An Arduino does this with PWM (pulse-width modulation): the pin switches very fast and the eye sees the average brightness. The aim is to learn PWM, colour mixing and multi-LED displays.
Tasks
- Change LED brightness with analogWrite
- Make a "breathing" light with a for loop
- Mix red, green and blue in an RGB LED
- Build a chaser and a bar graph on the LED module
- Show digits on the 7-segment display
What you can build
- Breathing light — The LED slowly brightens and fades, like a device in sleep mode.
- Colour mixer — Pick the RGB LED colour with a potentiometer.
- LED chaser — 8 LEDs light in turn and seem to run along.
- Electronic dice — Press the button for a random 1…6 on the display.
- Countdown timer — Counts down from 9 to 0, then an LED lights.
- Mood lamp — The RGB LED glides through colours.