2n2222 arudino and piezo

Ok, so I’m at a loss here. I have the below circuit setup. Using a 2n2222 as a switch to turn on a piezo buzzer that runs on 12v. When the arduino pin is set to LOW, I’m getting 2.8v at the screw terminals for the buzzer and a slight whine out of it. (not what i want). When I set the pin to HIGH I get the full 12v and the thing works as intended. I’m thinking that the wiring is correct but my values or assumptions are wrong. I need this thing to sit at or close to 0v when the arduino pin is LOW the buzzer shouldn’t be making noise until its set to high.

Any help is appreciated, I’m new to this thing so I’m probably missing some of the basics…

P.S. Missing from the drawing is the 12v ground and arduino ground run into the same ground as the emitter.

http://i.imgur.com/6KJMa.jpg

When the pin is set low, what is the voltage at the pin? If it was anything just a bit more than 0.00000 than a small current will flow into the base that will get amplified allowing more to flow through the collector-emitter.

If this is the issue, then as a last resort you need to add a pull down resistor from the pin to ground. When you want the buffer off, set the pin as an output with no pullup. The pulldown will prevent the flow of current into the base. When you want the buzzer on, change the pinSelect to an output set high.

An intermediate solution might just be a pulldown to drain off the “low” voltage from the Arduino so that it does not flow into the base.

My best guess. YMMV

Thanks, I will check this out tomorrow and let you know the voltage at the pin.

Make really really sure the grounds are indeed all connected together. My guess is so long as you’re doing a digital write (not an analog write) the voltages at pin3 should be good. Make sure pin 3 is always an output. Lastly be aware not all transistors have the same pinout, ie - EBC. Some, for some reason, are CBE though I can’t see how this reversal would yield the results you’ve seen.

http://www.electronics-related.com/usen … 5032-1.php

I will check the grounds and pin voltage today. I’m using a radioshack transistor has the pinout on the package so I think that’s wired correctly. Code is just a simple loop.

I can see the voltage go high 12v for the 5seconds and then low to 2.8v for 5 seconds and keep looping.

int buzzer = 3;

void setup() {

pinMode(buzzer, OUTPUT);

}

void loop() {

digitalWrite(buzzer, HIGH);

delay(5000);

digitalWrite(buzzer, LOW);

delay(5000);

}

I wouldn’t trust the labelling on the RS package but I still can’t explain the observed behavior. How sure are you that a high output yields a loud buzz and that it’s not reversed ? Could you make the high and low times different, like 5 secs high, 2 secs low, just to check by ear ?

A very leaky transistor could explain that behavior. It is hard to imagine how a normally functioning, but miswired transistor could behave that way. Please measure and report the voltages on the IO pin in both the high and low states!

Here was my thinking. The 2N2222 has a breakdown voltage for the E->B junction of 6V min. So if the transistor is in backwards the EB junction may be breaking down when the pin output is low, and then it conducts a tiny amount of juice through that reversed junction to that pin. Thus the voltage at the piezo is some odd amount. But the “sense” of the buzz should be reversed as well.

Turns out not to be the case.

I put 2 transistor circuits into LTSpice, one normal (per the OP) and one with the 2N2222 in backwards, to test the above hypothesis. It didn’t show what I expected but it did show the observed measurements, depending on what the resistance of the piezo was set to. A value in the neighborhood of 2k to 2.5k yields the OP’s results.

(click on to enlarge)

It does sound a bit like a transistor in backwards, but if it is going into reverse breakdown, it could quickly become an ex-transistor.

Measuring the voltages at the pins of the transistor would tell you. If the base is higher than the Arduino pin then it is indeed in the breakdown region. Warning it could be a race between the transistor and the pin on the Arduino as to which burns up first. The broken down transistor would be trying to pull the Arduino pin above the 5V supply.

Transistor do somewhat work when in a circuit backwards, though their performance will be pretty bad in the reverse direction. When the base is about 0.6V higher than the emitter, then the transistor conducts and the collector gets pulled low.

PS - as for the pin diagram, more than once I’ve mistakenly looked at one and seen what I thought was “viewed from the top” to be really viewed from the bottom.

ok, so I tested the voltage. I’ve got 3.18v at the arduino pin when set to HIGH, and 0v when set to LOW. Grounds are all tied in and looking good. I’ve got no 0v at the base pin when set to LOW and .71v on base pin to gnd when set to HIGH.

Now I’ve got some weird measurements possibly the cause?

The pinout I think is based on the diagram so these could be incorrect.

These were done with the diode setting

Base(pos) to emitter(neg) - .649v

Base(pos) to collector(neg) - .649v

Collector(neg) to emitter(pos) - .912v (shouldn’t this be 0v ?)

emitter(pos) to collector(neg) - 0v

Is there any way to test to see what the actual pin out is of the transistor if the RS pinout diagram is actually wrong?

If the latter measurements were made with the meter in “diode mode” and the transistor out of the circuit, then collector to emitter connection should be indicated as an open circuit (overload or infinite resistance) in either direction. The base to collector and emitter readings are normal, but the transistor is probably bad, with a C to E conductive path.

With the simple “diode test” it is possible to identify whether a transistor is NPN or PNP, and also possible to identify the base lead, but it is very difficult to distinguish the collector from the emitter. For that you need to make a simple circuit with a resistor (from the assumed C to the B) and check the current gain.

Well the diode measure on the meter for base to collector/emitter looks OK, as it is an NPN transistor, and PN junctions are diodes with about 0.6 - 0.7V when in forward bias.

It depends on your meter what it is really measuring, and I’m not sure what it would say collector to emitter (as it is really an open circuit). The collector to emitter showing 0.9 V is a bit suspect and maybe means the transistor is blown.

When in the circuit and the Arduino pin high and 0.7V on the base what is the voltage at the collector (should be 0.3 to 1V depending on current through the piezo)? Also when the Arduino pin is low what is the voltage on the collector (should be 12V)? If in the off state the voltage is much less than 12V, then yes your transistor is toast.

SOLVED! Ok so possibly one issue caused by the other. Radioshack pin out was wrongish and the transistor was bad. I wired up another test circuit to isolate the problem. The collector pin according to rs diagram needed to go to ground, and the emitter to the ground on the speaker. The transistor ended up being faulty, not sure if it was because of the flip flopped pins. But all is working now, I changed the transistor out and swapped its orientation on the board and its working perfectly!

Thanks for all the help