I wanted to use a piezo sounder to sound an alarm in an application. Testing indicated that tone() was not very loud.

I could use some external circuitry to swing the pins ±5V but as I have plenty of spare pins, it seemed feasible to use 2 pins driven in anti-phase to increase the power by 4.

I looked at the source Tone.cpp but the code is somewhat intimidating. Before I start to modify it I was wondering if anyone else has already done something like this.

  • Wouldn't you still end up with the total voltage difference across the two pins being at most 5V?
    – dlu
    Commented Jan 5, 2016 at 8:35
  • 4
    @dlu No The swing is 10V. Think about it - this is a standard technique.
    – Milliways
    Commented Jan 5, 2016 at 9:20
  • -1. No, the swing is 5V, unless you generate 10V with a boost converter or generate a -5V rail. Fundamental flaws in your plan aside, yes it's possible to add an anti-phase pin to the mix a few edits to the Tone library. Commented Jan 5, 2016 at 12:12
  • 4
    @CharlieHanson No, the swing is 10V. At any moment in time the instantaneous voltage between the two outputs is 5V, but into an inductive load (speaker, moving coil) the displacement is double since you are inverting the polarity all the time, and first pushing the coil with +5V and then pulling the coil with -5V giving the equivalent drive displacement of 10V with a -5V offset.
    – Majenko
    Commented Jan 5, 2016 at 12:42

1 Answer 1


Yes, Tim Eckel has already published a library "toneAC" on the Arduino website at http://playground.arduino.cc/Code/ToneAC

All of the syntax is there too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.