Bet you've got the transistor connections wrong! George ----- Original Message ----- From: "Herbert Graf" To: Sent: Monday, October 20, 2003 8:24 PM Subject: Re: [PIC]: Using a 2N3904 to switch a relay > > I'd like to preface this question by saying that while I can program > > fine my electronics knowledge goes little beyond the absolute basics. > > > > I want to use a pic to switch an inductive load on/off and it was > > suggested (on usenet) that the following should work > > > > VCC (5VDC) > > > > | > > | > > .----o > > | | 5V Coil > > 1N4002 - _|_ Relay > > ^ |_/_|- > > | | > > | | > > |----o > > | > > | > > 6.8K | > > ___ |/ > > o------|___|---o-------| 2N3904 > > PIC Output | |> > > .-. | > > | | | > > 6.8K | | | > > '-' | > > | | > > GND GND > > > > > > I've assembled the circuit (with the input being a PIC pin pulled up to > > 5V via a 10K resistor), however the relay switches (on) as soon as power > > is supplied to the circuit and the output state of the PIC pin has no > > effect on the relay state. > > > > As I've said at the start, my electronics knowledge is basic in the > > extreme but I've been googling a bit to try to understand how the above > > circuit should work (& why it doesn't). I've found a similar (to my > > mind) relay switching circuit using a BC377 rather than 2N3904 and > > missing the 6K8 resistor between ground & the transistor base. Following > > that I removed the ground resistor & replaced the second resistor with a > > 2K6 one (using calculations provided with the BC377 circuit), but this > > doesn't work either! > > > > Could anyone explain how the above circuit works and how the values of > > the resistors are calculated? Should it in fact be functioning as in > > when connected to a pic as I've described? > > Well, the circuit is pretty basic. First off, ignore the 6.8k resistor to > ground, it's not really needed. > > Now, to simplify things: think of the transistor as a current mode switch. > When your input current into the base the collector and emitter are > practically shorted together. When there is no current flowing into the base > the switch is off, and the emitter and collected can be considered open. > > Your PIC's output pin outputs a voltage. The 6.8k resister in series with > it acts as a "safety" to ensure that not too much current flows into the > base (think of a base as a diode going to ground). > > The value of the resistor is not as straightforward to calculate. What you > WANT to do is ensure the transistor is saturated. You have to get the > transistor's datasheet to figure out it's saturation current for your case > (it will depend on the beta of the transistor and your load current), then > go a little high to ensure it's definitely in saturation. So say you > calculate the saturation current is 1mA: > > The value of the resistor would then be: R=V/I=((5V - 0.7V(which is a diode > drop))/1mA ~= 4300ohms = 4.3k > > Now, consider this the BIGGEST resistor you can use. There is no reason to > go this high unless you need to (to save power or other reason). To be safe > go lower. Your lower limit is defined by the max current a PIC pin can > source. Say it's 20mA, then the SMALLEST resistor you can use is: > > R=V/I=4.3V/20mA = 215 ohms. > > So, the SMALLEST resistor you can use is 215ohms. I don't recommend going > that low either since there is also a "per device" current output that you > might violate on the PIC. > > So, what do I recommend? Don't bother with the calculations! :) Why? > Because MOST of the time selecting something like a 1k or 2k resistor will > "work". If you want go through the calculations to ensure you are OK, but > most of the time I just go with a 2k. > > Obviously a 2k won't work in every case, and in fact if you are dealing > with different power supplies 2k will likely be no go. But it usually is. > > Back to your circuit. Disconnect the base and see if the relay still turns > on. If it does then you've likely got a bum transistor, either that or > you've hooked it up wrong. If you've confused the base with the collector > then your symptoms would match. > > Hope this helped, TTYL > > -- > http://www.piclist.com hint: The list server can filter out subtopics > (like ads or off topics) for you. See http://www.piclist.com/#topics > -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics