Considering the following limited knowledge I have:

  1. Arduino boards analogWrite really is a PWM and can't output arbitrary voltages like 1.23V or 4.56V. Furthermore, most pins have a max frequency of 500-1000Hz
  2. Audio range well above 1000Hz
  3. ESP32 boards have DAC pins that allows outputting arbitrary voltages
  4. A speaker coil shouldn't be driven by a square wave as it causes too much stress
  5. A speaker coil shouldn't receive only positive current, otherwise it relies on the diaphragm physical structure to return to its neutral position, which would not return to its neutral position "at the right time", and also not having negative current you can't take advantage of the full speakers movement amplitude and so a weaker sound
  6. For motors, we switch the rotation direction by reversing current with an H-bridge

Not using any shield, I would play a song using an ESP32's DAC pin. I would "encode" 0V to represent -100% amplitude, 2.5V for 0% and 5V for +100%. However then I don't know how to shift that to ±5V (or ±2.5V) at the speaker's leads. I thought about an H-bridge, but I think it only works with PWM and won't work with arbitrary voltages between 0 to 5.

I would appreciate a schematic showing how I should hook the speaker's leads to the DAC pin, with whatever I would need between. To help me learn, I would like 2 versions, where one would have no amplifying circuit (I mean, I know a pin shouldn't output more than a few mA and that it's not gonna do much for a speaker), so I can at least see what's required to shift voltages in such way.

Thanks !

  • 2
    a series connected capacitor would block the DC component of the signal
    – jsotola
    Feb 14 at 20:45
  • How would that shift voltage to -5V to 5V at the speaker ? I'm sorry I can't visualize what you mention
    – MB101874
    Feb 15 at 11:49


Browse other questions tagged or ask your own question.