My Christmas present this year was a bunch of Arduino gear, so I have spent some time playing with it. I bought a piezo to see what beeping noises I could make. To get accurate tones, it turns out that you need to use the hardware timers to generate the square waves. The Tone library does exactly that, with a nice interface to boot.
To learn my way around larger pieces of arduino code, I decided to change the tone library so that it optionally uses differential drive. This is how you get twice the voltage, and twice the volume, of a regular pin-to-ground piezo setup. By connecting both ends to different pins and making sure their outputs alternate, we can get 10V edges out of the arduino’s 5V pins. While it is well short of my piezo’s 30V range, it’s loud enough to hear it across the apartment (ie sufficiently loud to annoy your SOs).
Anyway, here’s the patched Tone.cpp file. When creating a Tone object, you have the option of passing an extra parameter which is the second pin. If you ignore it, the code won’t tie up any extra pins (but it will use more memory).