2Digital Inputs, Outputs, and Pulse-Width Modulation
What You'll Need for This Chapter:
- Arduino Uno or Adafruit METRO 328
- USB cable (Type A to B for Uno, Type A to Micro-B for METRO)
- Half-size or full-size breadboard
- Assorted jumper wires
- Pushbutton
- 220Ω resistors (×3)
- 10kΩ resistor
- 5mm red LED
- 5mm common-anode RGB LED
- CODE AND DIGITAL CONTENT FOR THIS CHAPTER
- Code downloads, videos, and other digital content for this chapter can be found at:
exploringarduino.com/content2/ch2- Code for this chapter can also be obtained from the Downloads tab on this book's Wiley web page:
wiley.com/go/exploringarduino2e
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 will start to learn the skills you need to build projects like these. You'll explore the Arduino's digital input capabilities, learn about pull-up and pull-down resistors, and learn how to control digital outputs. Most Arduinos do not have an analog output, but it is possible to use digital pulse-width modulation (PWM) to emulate it in many scenarios. You will learn about generating pulse-width modulated signals in this chapter. You will also learn how to debounce ...