Book Image

Arduino Essentials

Book Image

Arduino Essentials

Overview of this book

Table of Contents (17 chapters)
Arduino Essentials
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Making some noise


We usually associate time with sound, from the tick-tock of an old analog clock to the sound of an alarm in our latest digital clock.

From the hardware point of view, in this chapter I'll take advantage of this association to show you how to connect a speaker or a buzzer to our Arduino board and the way Arduino can generate sounds.

Being able to produce some sounds allows us to account for time in a more sensorial way.

Arduino library sound functions

Because it is a very common task, once again the Arduino library comes to our help with the tone() function that will help us produce those electrical signals that we need to generate different sounds.

The tone() function accepts up to three parameters:

  • pin: The pin number through which we want to generate the sound signal

  • frequency: The frequency in hertz at which we want the signal to oscillate

  • duration: An optional parameter that specifies the total duration of the sound

Everything is almost as expected, but perhaps the duration...