2
\$\begingroup\$

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?

\$\endgroup\$
7
  • \$\begingroup\$ ...but my mcu will give 5V 40mA That's not really correct, it delivers 5 V provided the current stays below 40 mA. But 40 mA is a lot to ask from one mcu pin. But we don't need 40 mA, much less is needed as the transistor takes care of the large current. In practice the value of the resistor is not that critical. Indeed a 330 ohm will very likely do the job. \$\endgroup\$ Commented Sep 5, 2017 at 6:15
  • 2
    \$\begingroup\$ 10Hz is a really strange frequency to drive this at, especially since it's tuned for 2048Hz. The frequency response curve in the datasheet doesn't even go down to 10Hz, which means that you will probably have very, very poor performance at that frequency. \$\endgroup\$ Commented Sep 5, 2017 at 6:51
  • \$\begingroup\$ @IgnacioVazquez-Abrams I'm not driving the buzzer at 10Hz frequency. I'm just turning it on and off at 10Hz speed. 100ms on or HIGH 100ms off or LOW. \$\endgroup\$
    – Kokachi
    Commented Sep 5, 2017 at 6:53
  • 1
    \$\begingroup\$ This isn't a buzzer you just turn on and off, it needs to be actively driven. And turning the pin on for 100ms and then off for 100ms is actually 5Hz, so... yeah. \$\endgroup\$ Commented Sep 5, 2017 at 6:55
  • \$\begingroup\$ @IgnacioVazquez-Abrams Yeah but it has the driver built in right? and my bad.. 5Hz it is then. \$\endgroup\$
    – Kokachi
    Commented Sep 5, 2017 at 7:00

3 Answers 3

8
\$\begingroup\$

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.

\$\endgroup\$
6
  • \$\begingroup\$ AVR outputs have an impedance of 25ohm. \$\endgroup\$ Commented Sep 5, 2017 at 6:46
  • \$\begingroup\$ @IgnacioVazquez-Abrams I did say "no more than." So it's probably less. (Which I would not argue about, at all.) Adjust slightly. And thanks for the update. The MSP430 outputs are about \$60\:\Omega\$, from past experience. In case that matters to you. By the way, the added delta you suggest here puts it almost exactly at the \$390\:\Omega\$ I rounded towards. \$\endgroup\$
    – jonk
    Commented Sep 5, 2017 at 6:47
  • \$\begingroup\$ @jonk I'm a bit confused by now. The guy who commented above done some math and it's 1.3K resistor for base. So which one is correct? \$\endgroup\$
    – Kokachi
    Commented Sep 5, 2017 at 6:58
  • 2
    \$\begingroup\$ @Kokachi Design choices vary. The other answer chose \$\beta=50\$ for a saturated BJT for reasoning I find to be both questionable and not directly supported in the text. I picked \$\beta=15\$ by referring to a manufacturer's typical curve, supporting my choice by directly providing at least one reasonable curve to consider and a choice I made using it. Do some googling around and see what you find others using, if you want to get a "consensus" about it, though. Keep in mind the difference between an active mode \$\beta\$ and a saturated mode \$\beta\$ when you do so. \$\endgroup\$
    – jonk
    Commented Sep 5, 2017 at 7:03
  • \$\begingroup\$ as the resistance increase the base current decreases right? \$\endgroup\$
    – Kokachi
    Commented Sep 5, 2017 at 7:53
5
\$\begingroup\$

Let's calculate all thing backwards, from the idea that the buzzer should be dreiven full swing.

Your speaker has the coil resistance of 42 Ohms. Therefore at +5VDC it would need about 120 mA with fully opened transistor.

The 2222 transistor has the hFE at least 50, so to get it into full saturation the base current should be about 120/50 = 2.4 mA. Let's take it at 3 mA

Since your driver will drive to about 5V (minus pocket change), and Vbe is about 0.7V, you need a resistor that makes 3 mA over 4.3V, which gives 4300/3 = 1433 Ohms.

Therefore you base resistor should be about 1.3k, and the round number of 1k will do just fine.

\$\endgroup\$
8
  • \$\begingroup\$ I'm a bit confused by now. The guy who commented below done some math and it's 390 Ohm resistor for base. So which one is correct? \$\endgroup\$
    – Kokachi
    Commented Sep 5, 2017 at 6:57
  • 2
    \$\begingroup\$ Any value is correct; jonk has more conservative estimate. But I would think that the assumption of β=15 is something that I would pencil in about 50 years ago. Since then there was some progress in transistor technology, one would guess... \$\endgroup\$ Commented Sep 5, 2017 at 7:08
  • \$\begingroup\$ what do you mean by any value is correct? If I choose too low value resistor then won't the transistor be damaged? \$\endgroup\$
    – Kokachi
    Commented Sep 5, 2017 at 7:51
  • 1
    \$\begingroup\$ @Kokachi No, the main function of the resistor is to protect the MCU output if the transistor fails by going short circuit. The transistor will just take whatever base current it wants - making the resistor value too high would stop it doing that and limit the output voltage swing to the buzzer, but making it too low isn't really a problem, even if the transistor saturates rather than staying in the linear region. \$\endgroup\$
    – alephzero
    Commented Sep 5, 2017 at 11:33
  • \$\begingroup\$ ... so I would select the resistor based on the MCU output, not on the transistor parameters. 5V 40ma gives 125 ohms as the minimum value to protect the MCU. Double that (240 or 270) to give you some safety margin, or you just stick with the existing 180. If 240 or 270 is too high to get enough base current into the transistor, you need to select a higher gain transistor, not futz about trying to fine tune the resistor value IMO. \$\endgroup\$
    – alephzero
    Commented Sep 5, 2017 at 11:42
0
\$\begingroup\$

Use NMOS instead of NPN transistor. For your application BS170 is cheap and very simple to operate. If you are using SMD components, you can use 2n7002.

NMOS as a switch

Source of image: http://design.stanford.edu/spdl/ME218a/pastprojects/0708/pennybowling/links/schematics.html

With MOSFET transitors you don't have to calculate value of base resistor. They actualy don't have base but instead they have gate. If you are more interested in knowledge of NMOS check wikipedia article.

\$\endgroup\$
2
  • \$\begingroup\$ (comment deleted; I misread the question and thought the MCU was running at 3.3v) \$\endgroup\$
    – Jules
    Commented Sep 5, 2017 at 15:35
  • \$\begingroup\$ no flyback needed for buzzer? I don't have any logic level mosfets in hand, just bjt npns \$\endgroup\$
    – Kokachi
    Commented Sep 5, 2017 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.