multiple outputs as amplification and volume control

Hi, thanks in advance for any assistance in this matter.
So here's the deal, I'm software coder getting into hardware. (LOL :slight_smile: not like I've seen that much on the forum)
I have a pro mini, and would like to use the dac to take in an audio signal, and direct drive a speaker with multiple outputs from the pwm or digital pins. I've seen on the forums that you should not connect multiple outputs, but several systems I've seen seem to? Or maybe it's my lack of understanding.
Hap-hazard and wrong, but can I drive an 8 ohm tiny speaker with say 8 digital IO lines or multiple pwms, allowing for volume control by increasing or decreasing the number of lines that are driving the speaker.
I would like to accomplish this without any external parts for smallest footprint. If there absolutely needs to be external components then I will have to roll my own, since the space available is extremely small.
Any help would be greatly appreciated, and of course the obligatory "Sorry for the silly coder question." :wink:

You cannot directly connect an 8 Ohm speaker.* You need an amplifier. If you want to build your own, the LM386 is popular and easy to use.
Or, you can use computer speakers which are amplified.
Typically, you can control the volume by scaling your audio data... i.e. Multiply each sample by 0.5 to reduce the volume in half, etc.
Note that the Arduino doesn't have a true DAC. It has PWM that can sort-of function as a DAC. (It works very well for dimming LEDs). If you want higher quality audio you'll need a true DAC.
You cannot connect multiple outputs together... If one output goes high and the other goes low, they will be "fighting" each other, excessive current will flow and you can potentially damage the chip.

Some digital chips have "tri-state" outputs (where the output can "float") or open collector outputs that can be logically or'd together. For example, the data lines for a CPU, RAM, and ROM all share the same data bus.
An Arduino I/O pin can be switched to input-mode if you want to connect it to another output pin (then, you don't have to read or use the input). But, this won't accomplish what you want and you have to be very careful using a trick like that.

  • The specs for the Arduino say 40mA per pin maximum. From Ohm's Law that means no less than 200 Ohms at 5V.

Thanks...This explains a quite a few things.
Lol I said dac and meant adc, I intended on putting the input signal into the adc, and out through the pwm, but with the issues of floating pins my idea wouldn't work plus I really wanted to know a solid reason as to why I couldn't connect multiple outputs.
I'm only amplifying voice, and only wanted to use the arduino or rather the atmega 328 for dsp, sound cancellation, volume control, etc.
Thanks again and for the coding tip, that will come in handy. :slight_smile:

If you connect two outputs together then if one is high and the other is low even for a fraction of a second you will cause a lot of current to flow through the pins and damage or even burn them out.
With PWM there are issued with phase that ensure you will always have some period of time with the outputs not being matched. So don't do it.
Why bother with an arduino at all if you only want to drive a speaker from a microphone?