O'Reilly logo

Adventures in Arduino by Becky Stewart

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

image

THERE ARE LOTS of ways to make code control things in the real world. You have already controlled movement with motors and controlled light with LEDs. In this adventure you’re going to create sound!

In Adventures 3 and 4, you discover some new ways to make your code more efficient when you need to repeat the instructions more than once. The for loop is a great tool for repeating something a set number of times. When you combine a for loop with special lists in code—called arrays—you end up with a powerful coding tool.

After learning how to harness the power of arrays and figuring out how to get your Arduino to sing to you, you’re going to put your new skills into practice by building an augmented wind chime that plays both acoustic and electronic sounds.

What You Need

You need a few things for the first part of this chapter (the electronic components are shown in Figure 5-1):

  • A computer
  • An Arduino Uno
  • A USB cable
  • A breadboard
  • 7 jumper wires
  • 6 LEDs
  • 6 220Ω resistors
  • A piezo
image

Figure 5-1 The electronic components you need for the first part of this adventure

Making a List

Variables are useful ways of keeping track of information like the numbers of the pins on your Arduino Uno. Creating a variable to store the number of the pin to which a particular LED is connected makes your ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required