# How to amplify MCU port output?

Having the following diagram, how can I amplify output from pin 3&4 to speaker, using BC547 transistor?

-
What do you know about use of transistors for amplification? Also what output level do you want? Any data about the speaker? What's the frequency of the output signal? – AndrejaKo Nov 22 '12 at 16:40
I know the basics, but 1st I don't know how to mix those 2 digital outputs into single. I've tried with resistor divider, but 15k resistors gave no output signal. So I also need values of resistors. – Pablo Nov 22 '12 at 17:04
@Pablo Please explain why you need to mix those 2 digital outputs? What exactly is each output? – Anindo Ghosh Nov 22 '12 at 17:13
Those pins are part of DAC. – Pablo Nov 22 '12 at 17:15
I doubt if the above is a good example. A regular speaker is an inductive load and wiring it like that may kill the microcontroller. Attaching the speaker through a (couple of) transistor(s) is a good idea. So you are on the right track :o) – jippie Nov 22 '12 at 21:21

• Create a 2-bit DAC using 2 digital outputs of the ATTiny45
• Produce an audio-frequency output by varying the 2 bits suitably
• Hear this audio signal on the 8-ohm speaker

What you need is an "R-2R" network driven by the two pins. From the diagram you posted:

Connect R15 to Vcc, and R7, R8 and R16 exactly as shown. Keep the values as per the diagram as well, 10k and 20k. Leave out the other resistors in the schematic.

The junction of R16 and R8 will be the DAC output.

This resultant output voltage needs current amplification to drive the speaker:
An 8 ohm speaker with a 5 volt peak-to-peak signal will generate over half a watt of output, which is pretty loud - but will require anywhere from 100 to 300 mA of drive current. The MCU's pins cannot deliver that kind of current (this is with reference to your original schematic), and even the BC547 is rated only to 100 mA.

If distortion of output on the speaker is not a show-stopper, you could make a Common Collector unity gain voltage buffer with your BC547 to generate the speaker output you are expecting. Your speaker will be the load resistor, so no separate resistor is needed there. Your power rail must be able to supply sufficient current for this.

The output will not be a perfect 4-level (i.e. 2-bit) DAC output since we have ignored biasing, but will generate recognizable sound as per the MCU pin values generated.

-
Yep, R-2R is what I needed. So with 50-70 mA MCU output, 5V VCC and BC547, 8 ohm speaker, how much power on speaker can I expect? As far as I was able to play, the output is not audible (I have to keep close to ear). – Pablo Nov 22 '12 at 18:17
with 50ma from an MCU pin it'll be audible WITHOUT a transistor! Try 100R from the MSB pin to spkr, and 200R from the other pin (to the same end of spkr) - the other end of spkr to ground. Crude but effective. If that's not loud enough, we'll work on an amp. – Brian Drummond Nov 22 '12 at 18:34
@Brian Drummond: sounds almost same. Well, it's audible, but like I said, I have to be close to speaker. If possible would like to build a better amp, maybe with different transistor for 5V. – Pablo Nov 22 '12 at 18:49
@BrianDrummond The Attiny45 datasheet says: "Although each I/O port can source / sink more than the test conditions (10 mA at VCC = 5V, 5 mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed: 1] The sum of all IOL, for all ports, should not exceed 60 mA. If IOL exceeds the test condition, VOL may exceed the related specification. Pins are not guaranteed to sink current greater than the listed test condition.". So drawing 50 mA from the MCU pins is pushing it close to those limits. – Anindo Ghosh Nov 22 '12 at 18:59
@Pablo Is it inaudible after adding a voltage buffer, or without? Also, what are you sending to the to output pins for testing (e.g. 500 Hz square wave on PB1 and 1500 Hz square wave on PB4)? – Anindo Ghosh Nov 22 '12 at 19:03

Common emitter amplifier + Buffer (Emitter follower). If you google these you'll find a site that will tell you how to make them. The common emitter is to amplify the signal and the buffer will simply make sure that the speaker gets most of the signal. Also, don't forget to add caps in between!

-
Your answer can be improved with some actual links to sites that answer the question, or ideally write a full answer that contains everything needed to answer that question. That way this site will increase the value of the internet and not just become another link blog. – Trygve Laugstøl Nov 22 '12 at 22:22

Depends on the speaker, and the signal. If it's a piezo, that cct is as loud as it gets without more volts (or a transformer!).

If it's a voice coil, tell us what impedance, and how much power do you want?

-
8 Ohm small speaker. Actually I just need a little power, so it will be audible and right now I have only BC547C transistor. I tried to connect using 15k resistor divider but no sound at all. – Pablo Nov 22 '12 at 16:52
Then you don't need both pins. BC547 is a npn transistor, and the simplest and safest circuit is an emitter follower. Take the Collector to +V, the emitter to the speaker, the base to a 1K resistor to the pin. The other end of the speaker goes to 0V. – Brian Drummond Nov 22 '12 at 17:01
I do need both pins, since they are part of DAC. – Pablo Nov 22 '12 at 17:04
Ah. I thought it was just a logic output. – Brian Drummond Nov 22 '12 at 17:08
I've tried something like this: dmitrstas.ucoz.ru/_tbkp/15/18_1.jpg but like I said, no signal on output. Seems I need precise values. – Pablo Nov 22 '12 at 17:10