Digital Inputs, Outputs, and Pulse-Width Modulation

Parts You'll Need for This Chapter:

Arduino Uno

Small breadboard

Jumper wires

1 10kΩ resistor

3 220Ω resistors

USB cable


5mm single-color LED

5mm common-cathode RGB LED


Code downloads, videos, 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 02 download and individually named according to the names throughout the chapter.

Blinking an LED is great, as you learned in the preceding chapter, but what makes the Arduino microcontroller platform so useful is that the system is equipped with both inputs and outputs. By combining both, your opportunities are nearly limitless. For example, you can use a magnetic reed switch to play music when your door opens, create an electronic lockbox, or build a light-up musical instrument!

In this chapter, you start to learn the skills you need to build projects like these. You explore the Arduino's digital input capabilities, learn about pullup and pulldown resistors, and learn how to control digital outputs. Most Arduinos do not have analog outputs, but it is possible to use digital pulse-width modulation to emulate it in many scenarios. You learn about generating pulse-width modulated signals in this chapter. You will also learn how to debounce digital switches, ...

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.