Hardware and Timer Interrupts

Parts You'll Need for This Chapter

Arduino (Uno recommended)

USB cables for programming Arduino


Piezo buzzer

Common cathode RGB LED

10kΩ resistor

100Ω resistor

150Ω resistor

220Ω resistors (×3)

10uF electrolytic capacitor

74HC14 hex inverting Schmitt trigger IC

Jumper wires



Code downloads, video, and other digital content for this chapter can be found at

In addition, all code can be found at on the Download Code tab. The code is in the chapter 12 download and individually named according to the names throughout the chapter.

Up to this point, every Arduino program you've written has been synchronous. This presents a few problems, namely that using deiay() can preclude your Arduino from doing other things. In the preceding chapter, you created a software timer using millis() to avoid the synchronous blocking nature of delay(). In this chapter, you take this idea a step further by adding both timer and hardware interrupts. Interrupts make it possible to execute code asynchronously by triggering certain events (time elapsed, input state change, and so on). Interrupts, as their name implies, allow you to stop whatever your Arduino is currently doing, complete a different task, and then return to what the Arduino was previously executing. In this chapter, you learn how to execute interrupts when timed ...

Get Exploring Arduino: Tools and Techniques for Engineering Wizardry now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.