# How does one convert DC to AC in context of playing audio?

I'm working on a little gadget. A simple two button mini game with a simple oled i2c display. I wanted to add sound and a bit of music. Nothing too fancy, mainly drums using white noise and two or three square and sawtooth wave voices for melodies and rhythm.

From what I understand I need a DAC which can be used to produce various levels of DC voltage and then offset it to produce an AC signal for speakers / headphones. I've seen schematics where this was done with nothing more than a capacitor but the logic eludes me. Would any kind folks help me out with understanding how one goes from DC (say from a 3.3c 8bit or 16bit DAC) to ac that is audio speaker friendly?

• What you're asking for is not converting DC to AC, it's removing a DC offset from a signal. That might help you find some resources. May 19, 2022 at 4:44
• Oh I see. Something new I've learned. Should I edit the comment to clarify that? May 19, 2022 at 4:47
• If you use a bunch of unipolar voltages (what you are calling DC) to make a sine-wave, it will be a sine-wave offset to entirely be unipolar. What speakers and headphones want is a sine-wave with no offset such that it is centered around zero and is bipolar (goes both positive and negative). So you want to remove offset. Mathematically going both ways is adding some offset, but physically there is a difference because removing DC offset is easier than adding DC offset. You just use a capacitor, in this case a so called DC-blocking capacitor. If that's what you don't get, dig into how caps work May 19, 2022 at 4:47
• That explains why I could not find anything related when looking for DC to AC conversion as a search query. Thank you very much for clarifying that. I assume that there's a formula to calculating the capacitance based on the DAC output voltage? May 19, 2022 at 4:50
• The capacitor removes DC bias so only AC is left. So in your terms it converts DC to AC. How large voltage is has nothing to do with capacitance, just your frequencies and speaker impedance. Unless you have an amplifier. May 19, 2022 at 4:51

I wanted to add sound and a bit of music ... the simplest way.

If I understand correctly, you want to make "sound" as simply as possible.
Just use the way digital amplifiers using PWM work.
To do this, use two equal resistors to define a voltage midpoint on a GPIO output with the possibility of Tri-state, coupling to the load (high input impedance loudspeaker or piezo, transformer could be used) by a capacitor.
Then apply the sequence of 0 or 1 or Z as desired to restore a sound.
(NB: to create it, one can use the sequence obtained by inputting the original signal wanted through a comparator - either v=0 or Vcc/2).
NB: variations are possible.

A rapidly varying DC signal is indistinguishable from an AC signal with a DC offset (equal to the average voltage) applied.

A capacitor in series with the speaker will block DC, and allow AC through. The impedance of a capacitor is

X = 1 / 2πfC

where C is the capacitance, and f the frequency. DC has a frequency of 0Hz, so the impedance is infinite.

If you haven't got a DAC, then use PWM on a digital pin instead - see the answer by Antonio51.