2.1.20. Exercise: Blink Bulb¶
2.1.20.1. Objective¶
Drive a light bulb from an Arduino program.
A microcontroller isn’t very useful without some kind of hardware attached. This exercise introduces driving an incandescent bulb from a digital signal. The transistor is used as a switch to control a higher current flow through the bulb than the Arduino output pin can sink, and at a voltage unsafe for the Arduino.
2.1.20.2. Steps and observations¶
- Adjust the lamp power supply for a safe full-on voltage. (Many lab incandescent lamps are designed for less than than the 12V shown on the schematic.)
- Note that pin 13 is still connected to the onboard LED. Observe the bulb and LED activity.
- Add additional
digitalWrite()
anddelay()
statements to create a different blink pattern.
2.1.20.3. Comments¶
This simple example cannot drive two separate patterns on two pins
simultaneously, since it just stalls during delay()
. Much of the
challenge of programming a multi-function Arduino program comes down to
structuring control flow so the program never stalls so it can service
multiple inputs and outputs simultaneously.
For a challenge, restructure this program to use millis()
to test
for the loop cycles on which to change the output state, then add a
second channel of output with different timing. This will covered in
more detail in a later exercise.
2.1.20.4. Other Files¶
- Fritzing file:
blink-bulb.fzz
- EAGLE file:
blink-bulb.sch