How to get true audio levels out of Arduino?

I am seeking to play sound from an Arduino, using tone(), fairly loud through an amplifier. I think that i will not be getting the full amplitude because Arduino output can only go from 0 to 5 volts. I need the signal to go from +1 volt to -1 volt to get full excursion of the speakers diaphram. If I use a differential input amplifier, will that convert the 0 to 5 volt input (attenuated down to 0 to 1 volt) into a full negative to positive waveform?

If not, how can I bias the signal to get a true audio waveform?

Speakers don't like square waves.
Be careful what you wish for.

Thanks .
Do you know how to get a sinusoidal 400 Hz wave out of an Arduino? I cant find anything on getting one out of the DAC of a zero.

(...and then I will still need to know how to bias the out put around zero volts)

The easiest way would be a DC blocking capacitor followed by a voltage divider. This is effectively a 1st order high pass filter so can be analyzed as such.

So the series circuit would be Arduino output pin to 10uF (e.g.) capacitor to 1k resistor to 1.5k resistor. The output would be taken from between the resistors and has a swing of 2 Vpp given a 0-5 V input.

The transfer function from here gives a cutoff frequency of about 6 Hz. The output impedance is the parallel value of 1k & 1.5k or 600 Ohms which is typical of audio line in.

I don't have a Zero, but setup a timer interrupt for, say, 32 times 400 (12800Hz), and output successive samples from a 32 entry pre-calculated sine function lookup table each time the interrupt fires.

Edit: And what he ^^^ said about a DC-blocking cap.

Thanks guys, I will give it a try.

Just clarifying the the setup described by MrMark. I attach an image of the circuit diagram. Is this what you meant?

Also the resistors are connected in series so how does the output impedance end up as 600 ohms (the parallel impedance)?

Circuit.jpg

I doubt if that circuit is what Mark described. I suspect that it is more like the one I have attached. The white shows what I have erased and the black show that inserted.

The output impedance of the Arduino pin will be very close to zero so, assuming the input impedance of the amplifier is very high, then the output impedance of the potential divider will be in effect the parallel resistance of the two resistors (i.e. 600 ohms). The theory for this can be found in basic circuit theory books.

Edit: for some reason the modified image was not included. Will try to add it.

I give in - the error message -

There was a problem during the uploading of Circuit.jpg.
Your post has been made, however the above attachment was not attached. Please use the Back button to edit your post and submit any required changes.
Your attachment has failed security checks and cannot be uploaded. Please consult the forum administrator.

I'm just trying to upload a Gimp edited jpg copy of the OP's circuit!

lemming:
Just clarifying the the setup described by MrMark. I attach an image of the circuit diagram. Is this what you meant?

Also the resistors are connected in series so how does the output impedance end up as 600 ohms (the parallel impedance)?

The circuit I was suggesting is pictured below. The red trace on the waveform is the output of the 400 Hz block (the Arduino "tone" output pin) and the green trace is at the "out" node.
captureHPF.PNG

For what it's worth, this picture comes from the simple online simulation tool at Circuit Simulator Applet. It's not a very sophisticated schematic capture tool nor a particularly good circuit simulator, but for quick and dirty stuff it's always there.

captureHPF.PNG

You could perhaps use a SPI dac like MCP8401 to get a true sine wave output. I did some tests in this thread and was able to get 630Hz. If exactly 400Hz is a requirement it may not work without some kind of tweaking.

Not entirely sure how to get half of the wave negative in reference to the signal ground or if it's actually needed.

Probably all you need is the series "DC blocking" capacitor, and a potentiometer.* If the amplifier already has a volume control all you need is a resistor to ground on the amplifier-side of the capacitor.

...Your amplifier probably already has an input capacitor and resistance-to-ground (possibly a volume pot on the input) but if you don't have a schematic, or if there's a chance of switching amplifiers it's good-practice to add the capacitor & resistor.

Speakers don't like square waves.

There's nothing wrong with square waves. Synthesizers can generate square or other wave shapes and normal audio contains all kinds of complex "random" waveforms.

You DO have to be careful with ANY continuous "high power" waveforms. A "10 Watt" speaker is designed for normal audio with 10W (maximum) peaks and an average of about 1W. You can fry a 10W speaker with continuous 10W test-tones. In addition to that, a square wave has about twice the power of a sine wave of the same voltage. If you have an amplifier rated for 10W (at low distortion), you can actually get 20W square waves out of it (assuming it doesn't overheat, etc.).

If you have a 2-way or 3-way speaker with a tweeter you have to be especially careful with high-frequency test-tones because the tweeter has a lower wattage rating than the overall speaker. And since your hearing sensitivity drops-off at higher frequencies you can fry a tweeter-frying with tones that don't sound that loud, or with ultrasonic tones that you can't even hear (I once fried an amplifier with an RF "tone" I couldn't hear, but my tweeters survived.)

  • An audio taper pot is best for use as a volume control.

Thanks MrMark for the clarification (and the simulator tool tip). That waveform looks good. I will have to read up on how you can go below zero volts in a circuit whose lowest voltage is zero.

Thanks kamelryttarn for the link. It seems like you are yet another casualty of the acerbic tongue of the GrumpyMike. I always find his withering (but knowledgeable and enlightening) epithets a source of amusement.

Thanks DVDdoug for the pointers. Being interested in HiFi I am cautious of outputs anywhere near the limits of amps and especially speakers. I've allowed plenty of headroom.

Read about 0 volts? Guys gave u a master engineering class already.
Here goes another picture of rc circuit output

https://images.app.goo.gl/kYsiyPR1beEyGf9U7

@oswe

Read about 0 volts?

. No, actually I said

..read up on how you can go below zero volts...

I can see the output of the circuit in the simulator picture provided by MrMark. No need for extra pictures. What the pictures do not do is explain how, in a circuit that has a zero to 5 volt range, you can get a voltage below zero on the output.

What the pictures do not do is explain how, in a circuit that has a zero to 5 volt range, you can get a voltage below zero on the output.

A series capacitor "blocks DC", and the resistor pulls the input of the amplifier down to ground. The "changes" are AC and they pass-through the capacitor. When the Arduino's output goes from high-to-low, the amplifier-side of the capacitor goes negative.

The RC circuit is also a high-pass filter. Since DC is zero-Hz, the DC is filtered-out. A 0 to +5V square wave can be "analyzed" as a -2.5 to +2.5V square combined with +2.5VDC. If you filter-out the DC component, you're left with a -2.5 to +2.5V square wave.

A lot of audio amplifiers work from a single-positive supply. The output is biased at half the supply voltage, but an output capacitor filters-out the DC leaving the AC audio signal. The input similarly has some bias an a capacitor. Some audio amplifiers have bipolar power supplies so they don't need an output capacitor, But often, there is still on the input because DC isn't "audio" and can be "safer" to keep DC out of the speakers.

Study. Charge of the capacitor is holding the voltage my friend very basic....

If the discharging time of the capacitor is long enogh than the period your input is oscillating youll get your fancy "negative voltage" try to read what i sent u about RC series circuit. Bye

The coupling cap is pushing voltage down below zero. It’s not perfect but shouldn’t matter too much using square waves.

It looks like it may need another stage or two to drive a speaker

lemming:
I can see the output of the circuit in the simulator picture provided by MrMark. No need for extra pictures. What the pictures do not do is explain how, in a circuit that has a zero to 5 volt range, you can get a voltage below zero on the output.

One thing I would add to the responses above is that one can use the simulator to look at what's going on with each component in the circuit. So after drawing the circuit, right click on the capacitor and select "view in scope" and it will add an oscilloscope view that shows (by default) the voltage across the component and the current through it.

After resetting the simulation this will show the capacitor charging to the average voltage of the input signal, so 2.5 V being the average of a 0-5 V square wave with 50% duty cycle. In the snapshot below we see that in the first 14 cycles of 400 Hz the capacitor has charged to not quite 2.0 V (green trace) and the current through it (yellow trace) is shifting from ground referenced PWM to zero mean PWM. The current then appears as zero mean voltage across the resistors when the circuit reaches nominal equilibrium.
Selection_002.png

As an exercise one could delete the capacitor and replace it with a 2.5 V two terminal voltage source and the output at 400 Hz would be effectively the same.

Selection_002.png