I found a tiny speaker while tearing down an old P.C. for recycling and thought I'd see what it sounded like using the Arduino Tone() function. I began with one 10Ω potentiometer to control the pitch and started making some noise. The Tone() function uses a simple pulse pattern. It turns the sound on and off at different frequencies in a square wave-pattern. I had two other potentiometers lying around so I added them and used them to control the tone duration. One to control the length of the tone and one to control the silent space in between the tones. It's basically using another square wave-pattern but at a much lower frequency. You can achieve a good variety of noise with this circuit. It works well with a piezo buzzer too, but lacks the bass response of a speaker.
Step 1: Parts You Will Need
Breadboard and jumper wires
1 Small speaker or Piezo buzzer
1 Pushbutton switch
3 10Ω Potentiometers
1 22Ω resistor
1 10kΩ resistor
Step 2: Build the Circuit
Connect the breadboard to your Arduino 5V pin and GND. Place the Pushbutton switch on the far right or left of the breadboard and connect it to 5V and ground using the 10kΩ resistor. Connect a wire from the switch circuit to pin 2 on your Arduino.
On the other side of the breadboard set up the speaker/piezo circuit to 5v and ground using the 220Ω resistor. This resistor controls the current thus controling the volume; you can try different resistors here for higher or lower volume.
Arrange your potentiometers in the center of the breadboard giving enough space to fiddle with the knobs. Each pot will need to be connected to 5V and ground and the center pins on each connected to analog pins A0, A1 and A2
Step 3: The Code
A potentiometer or pot is a variable resistor which when connected to an Arduino will return a value between 0 and 1023. We will use the map() function to change these values to suit our own needs. The map() function takes five arguments and in our case we need to re-map the range to between 220 and 2200 to produce a reasonable audible sound.
The function looks something like this:
map(pot, 0,1023, 220,2200);
You can play around with the last two values for higher and lower frequency tones, just be careful you don't upset your dog.
Step 4: The End
So that's all there is to it. Play around with the values in the code, add more pots /buttons and see what else you can control. Let me know if I've made any mistakes and I hope you enjoy the music.