Adding sound output to your robot
As with lights and displays, sound can be a great way to let your robot communicate with you or anyone else who might interact with it. Sound is made of sound waves, small pressure waves in the air that propagate to your ears and create the sensation of hearing something. Speakers create these waves by making a membrane vibrate, which in turn makes the air around the membrane vibrate to create sound waves. The pitch of the sound is dependent on the frequency of the vibration. The higher the frequency, the higher the pitch of the sound.
Creating sounds with an Arduino and a simple speaker is very easy. However, there are a few different techniques that you can choose from, so let us look at some of them so that you know your options.
Digital sound
The easiest way to create sound is by driving a speaker with a square wave, by simply switching the speaker voltage or current on and off at the frequency that corresponds to the pitch that we want...