On Mon, Oct 20, 2003 at 06:47:46PM +0100, dave cunningham wrote: > I'd like to preface this question by saying that while I can program > fine my electronics knowledge goes little beyond the absolute basics. That's cool. The only way to learn is to do. > > 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 Everything but the 6.8K pulldown looks fine. It sets up a voltage divider that also limits the amount of current to the base of the transistor. While some may argue that is keeps the transistor off until the PIC output can be configured, if you're going to do it increase the value of that pulldown so that mode current can be available for the transistor base. I'd initally test with that pulldown off. All of my relay circuits function fine without it. > > 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. Now that's odd. If the PIC output is low, then the transistor should be off and the relay should release. To test, simply ground the base of the transistor. The relay should turn off. Then try tying the base of the transistor to 5V using a 6.8K pullup. Relay should then turn on fully. If those two conditions work, then tie the base of the transistor to the PIC output (BTW which port pin are you using for your output?) and retest. It should work OK now. > 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! OK so you did test it. > > Could anyone explain how the above circuit works and how the values of > the resistors are calculated? The transistor is acting as a switched amplifier. This means that if you provide current through the base/emitter junction, then an amplified amount of current is allowed to flow between the collector emitter junction. The PIC output is supposed to be the switch. The purpose of the resistor is to in fact limit the amount of current that can be pulled through the base. OK I'm just going to throw out some numbers. The 2N3904 has a maximum continuous collector current of 200ma. Relay coils offer a resistance between 50 to 500 ohms depending on the model, so let's be conservative and say that it's 50 ohms and therefore draws 100 ma of current across it. So there will be 100ma of current flowing between the collector and the emitter (Ice) of the transistor. So you go to the datasheet that indicates that the beta (the amplification) is 30 for Ice = 100ma. That means that the base current will get amplified 30 times. So the base current requires is 100ma/30 -> 3.3ma. Now two things comes into play here. One is the fact that the base emitter voltage is 0.6V. The second is that Roman Black taught me that you should drive the base upwards of 10 times harder than the minimum specified to make sure that the transistor turns on solid. Since that's 33ma and overwhelms the PIC's output driver, let's back off and say that we'll use 5 times the base current: 16.5 ma. So here's the string we're trying to drive: Pic output ---R-----BE------GND 5V 4.4V 0.6V 0V So the resistor has to drop 4.4V @ 0.0165A. So we can compute the value: V = IR --> R=V/I -> R = 4.4/0.0165 -> 266 ohms. So now we see why there may be an issue. That 266 ohms is a lot less than both the 2.6K and the 6.8K that you've been testing with. So grab a 270 ohm and retest. >Should it in fact be functioning as in > when connected to a pic as I've described? Looking at these numbers above, it probably should never turn on. > > Any suggestions of suitable foundation electronics books would also be > appreciated! I hope this helps. I always use resistor values 1K and less. It's worked quite well for me. BAJ -- 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