Flummoxed... again.
I had a circuit which worked fine for months. Put it on a PCB... it worked... briefly... then, I think, the transistor died. Of course, my "translation" to PCB could have involved mistakes... don't think so, though, and I THINK things WERE working... for a little while.
... is relevant sub-circuit. At the moment, the (failed?) transistor always conducts, the relay coil is always energized. The LED goes on and off as it should. I'm driving the sub-circuit with D13, but from a ModernDevice RBBB, which doesn't have an on-board LED on D13.
Anyone see anything "wrong" in that circuit? I've done a bunch of troubleshooting... the relay IS working, for instance, doesn't have "frozen" contacts. (If you know about these things, but when you look at the circuit you can't see anything wrong, that information would cheer me greatly, even if it won't fix my problem!)
A word of explanation... R2 and the capacitor are there to prevent the transistor from switching on unless there is a sustained "high" from the output of the Arduino. R2: 2k2, C1: 1000 uF. (The relay unlocks my front door, and when there's a power cycle, before R2/C1 were added, a brief high on D13 during the Arduino's reset opened the door!)
The transistor is a BC549. Thus there is an error in the diagram above, which shows a PNP wheras I'm using an NPN... I think... (I'm not very good on transistors! I AM using a BC549!)
The Arduino output (driving the base of the transistor, after R2) is usually low... from time to time it is brought high for about 3 seconds, during which time the relay coil should be (and was!) energized.
===
While writing... I put the above circuit together "by guess and by gosh", and it seemed to work. I'm using the same components as were in the breadboard in the PCB.
Design question: When things stopped working, I had a sudden panic... when the output from the Arduino goes low after having been high, it is connected, through the 2k2 resistor, to a "source" of up to 5v... the charge stored in the capacitor. When I calmed down, I told myself that was okay. Is it? Assuming, for simplicity's sake (Is an "okay" assumption for my purpose, which is to see if the circuit is okay?) that no current flows away through the base of the transistor, I think that when the output goes low, for as long as it takes to discharge the capacitor, current will flow into the output. But I think R2 limits that current flow to about 2.5mA, right?(I called R2 2k for the sake of the calculation)... so all well?
===
So! Having given away most of my ignorance, I will be watching this thread with bated breath for advice from you all!
===
If nothing jumps out at you in the above, maybe the following will unveil my mistake/ problem...
a) The transistor MAY have got a bit hot during soldering... Not "terribly" so, but I didn't treat it with GREAT care...
b) I tested the circuit in various ways... probably ran it with the relay not inserted, for instance. (But would never have run it with a coil present, but no snubbing diode... I don't think THAT explains things.)
c) I don't recall doing all the calculations regarding the power dissipation capabilities of the transistor. But the relay is "just a little guy", and the transistor has coped for months with the current which flows.
d) I've checked, and checked again, the orientation of the transistor in the circuit... I don't think it is in "upside down". The middle pin is the base. Anyone know what the circuit would do if the transistor WAS in 180 degrees wrong?
e) I don't see why it should matter... but obviously that may be true of whatever is making my relay stay on all the time!... but maybe I should mention that the voltage which energizes the relay (V-RLY) is also being used to supply the voltage regulator producing the 5v the ARduino is running on.
===
Why did I try to "go tidy"??? The breadboarded version was a mess... but it worked!!! Sigh.
===
Supplemental questions...
Thinking about all this gave rise to another dreadful thought....
Can the relatively high voltage from V-RLY travel "upstream" through the base of the transistor to reach the output of the Arduino, which should not, of course, ever "see" more than 5v? Or can I think of the base as incorporating a diode which would block such flow. Would the base of a PNP transistor in the same circuit also be a barrier to more-than-5v "above" the transistor? (Yes... I do realise that if V-RLY was something really high, the barrier (which I hope is) at the base would break down.)