Electronic – ATtiny13a base resistor for 2N2222A

attinybjtnpnresistorstransistors

I have a small magnetic buzzer which needs to be turned on and off at 10Hz speed via an attiny13a mcu io pin. Since the buzzer is a magnetic one I am using a 2N2222A BJT NPN transistor for the switching part according to what the datasheet suggested along with a 1N4148 diode as flyback just like the diagram suggests.

enter image description here

The diagram base resistor 180 ohm is given for a 3.3V output pin but my mcu will give 5V 40mA on it's pin so what resistor should I choose to substitute. Will a 330 ohm do the job?

Best Answer

Interesting. I'd assumed it was a piezo for a moment. Then the datasheet said otherwise. Actually, it's quite similar to some cheap earphones they used to make -- circular, very thin disk of metal over the top of a circular magnet with a coil present. It'll work over a modest audio range. (I used to dismantle them to see how they worked when I was a kid.)

The datasheet says they require \$\approx 35\:\textrm{mA}\$. But I think that's a mean value, since they are operated typically with 50% duty cycle. (And because the datasheet actually says "mean current", too.) The resistance is given as \$42\pm 6.3\:\Omega\$. So worst case collector current should be \$\frac{5\:\textrm{V}}{35.7\:\Omega}\approx 140\:\textrm{mA}\$ with your \$5\:\textrm{V}\$ rail.

Let's look at the PN2222A curves for a moment:

enter image description here

Entering into this (typical) set of curves, I can see that the \$150\:\textrm{mA}\$ curve flattens out starting at a base current of about \$I_B=5\:\textrm{mA}\$ and is pretty solid by \$I_B=10\:\textrm{mA}\$. So I'd decide to drive it with \$I_B=10\:\textrm{mA}\$ as a reasonably safe choice.

This curve tells us something about \$V_{BE_{SAT}}\$:

enter image description here

I see that \$V_{BE_{SAT}}\approx 850\:\textrm{mV}\$, typically. Let's call it \$V_{BE_{SAT}}= 900\:\textrm{mV}\$ and be safe. The missing bit is the drop from your I/O pin, when high. But my own experience says that you shouldn't expect a drop of more than \$500\:\textrm{mV}\$ when applying \$10\:\textrm{mA}\$ out of a \$40\:\textrm{mA}\$ output.

So your resistor value is \$R_B=\frac{5\:\textrm{V}-900\:\textrm{mV}-500\:\textrm{mV}}{10\:\textrm{mA}}= 360\:\Omega\$. I'd go with a \$390\:\Omega\$ resistor and then take a voltage measurement or two, just to be sure.

Keep in mind that this is a pulsed application. So it's not solely ON and the datasheet's current is listed as "mean current" which does NOT MEAN that this is the actual peak current when turned on.


The BJT power will be \$900\:\textrm{mV}\cdot 10\:\textrm{mA}+100\:\textrm{mV}\cdot 140\:\textrm{mA} < 25 \:\textrm{mW}\$ at 100% duty cycle. So at 50% duty cycle, there's just no worry about using a TO-92 packaged device. You are fine with the PN2222A here. Similarly, the resistor power is \$390\:\Omega\cdot \left(10\:\textrm{mA}\right)^2 < 40 \:\textrm{mW}\$ at 100% duty cycle. Again, most any resistor package will be fine.