Shop OBEX P1 Docs P2 Docs Learn Events
using transistor to control relay — Parallax Forums

using transistor to control relay

Jayguy5000Jayguy5000 Posts: 139
edited 2014-01-21 10:08 in BASIC Stamp
For those following along my project I have gotten the IR working! awesome. now I need to re learn how I was using a 2222 transistor to control a small spst reed relay, takes 5vdc across the coil to flip it. my set up was connected to the relay and the basic stamp so when the bs2 sent out a signal to the 2222 it opened up and let 5vdc from the vdd through to the coil of the relay and it worked. The nominal current of the relay coil is 20ma which the bs2 could power, but only one relay, I want to set up multiple relays all controlled by transistors. This set up has worked pleanty in the past I just forget how it was done. I would imagine I had the 5vdc from the vdd connected to the coil and the coil grounded to the transistor and the transistor back to vss. Ofcoarse the other pin of the transistor was connected to a I/O pin and I think I sent a HIGH signal it. Well you get the picture, can you either correct my set up or verify it is correct before I try some smoke testing please? Thanks! this should be my last question for a while.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Actually I think Im going to add the whiskers to my tank and let it roam, just need to figure out where.

Comments

  • JonathanJonathan Posts: 1,023
    edited 2009-03-06 22:01
    Jay,

    Connect the base of the transistor to the stamp with a 1k or so resisitor. Connect the emitter of the transistor to ground. Connect one side of the relay to +5V and the other to the collector of the transistor. To make sure t doesn't have any false triggers, connect a 10 to 47K resistor from ground to the base of the transistor. Don't forget to put a back EMF diode across the coil of the relay.

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • ercoerco Posts: 20,256
    edited 2009-03-06 22:05
    If you're using one 250 ohm, 5V reed relay that operates on 20 mA, you can drive it directly with a Stamp pin. No transistor required. Use a flyback diode in parallel with the coil, and don't have any other big current demands on the Stamp. BTW, this won't work with a BS1 Project Board or a BS2 Homework Board, they have hardwired 220-ohm resistors on all pins.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • Jayguy5000Jayguy5000 Posts: 139
    edited 2009-03-06 22:20
    where do I put this diode exactly? can it be between the coil and the collector? or should it be between the vdd and the coil?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Actually I think Im going to add the whiskers to my tank and let it roam, just need to figure out where.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-03-06 22:23
    Actually it should be across the coil in reverse bias as shown in the attachment.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
    320 x 240 - 6K
  • Jayguy5000Jayguy5000 Posts: 139
    edited 2009-03-06 22:38
    lol I am actually using that diode, It works now. I just put it between the transistor and the coil. Is that ok? and question number two..Where or how do I connect this 10k resistor jonathan is talking about? he said between the base and ground, but the base is connected to the stamp. thanks for the help guys.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Actually I think Im going to add the whiskers to my tank and let it roam, just need to figure out where.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-03-06 22:57
    I don’t understand what you mean on the diode. It should be connected as shown in the diagram. If you’re putting it between the transistor and the relay it’s not going to work. As for the extra resistor, you don’t need it in this configuration because BJTs need current at the base to bias. If you were using a FET you would use the pull-down on the gate to prevent stray capacitance on the gate from turning the FET on. That’s not really going to happen here. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • JonathanJonathan Posts: 1,023
    edited 2009-03-06 23:00
    Jay,

    The diode should be connected to the coil wires of the relay, as close to the relay as possible, just as Chris's schematic shows. The 10-47k would go to the base of the transistor to ground, where the 1k series resistor and base of the transisitor connect. The reason for it is to make sure that noise (small voltage spikes) don't trigger the transisitor. Connecting the base to ground with the resistor means it won't turn on unless you want it to by sending the Stamp pin high.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • ercoerco Posts: 20,256
    edited 2009-03-06 23:01
    Simplest circuit attached. No transistor, no resistor. Just 8.7 beautiful GigaWatts of Flux Capacitor.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-03-06 23:03
    Did I just smell 8.7 Gigawatts of burnt I/O pin? =) I hope it's a very efficient relay to drive directly off the I/O pin.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • JonathanJonathan Posts: 1,023
    edited 2009-03-06 23:06
    Chris,

    Guess I have been wasting resistors for years. [noparse]:)[/noparse] Thanks for setting me straight. Erco, I knew I would find a use for all those flux capacitors I have been saving.[noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • ercoerco Posts: 20,256
    edited 2009-03-06 23:12
    Radio Shack 250-ohm 5V SPST reed relays and my favorite Aromat TQ2E-5V DPDT relays both draw ~20 mA from a 5V pin.

    OK, not quite 8.7 Gigawatts. Not even 8.7 Watts. More like 0.1 Watt. Now where did I misplace·that decimal? [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • ercoerco Posts: 20,256
    edited 2009-03-06 23:22
    Jayguy: Oops, your post started with 'how to control a reed relay', but ended with driving several. My direct-drive circuit will only allow one relay on a time with the Stamp. If you want to simultaneously drive more than one 20 mA relay per 8 IO pins, you will need one transistor per relay. I'll read posts fully before throwing my two cents in!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-03-06 23:23
    Jonathan,

    It depends on the type of transistor and configuration of the circuit as to whether or not you need a pull-up or pull-down resistor. It just happens that in this configuration with an NPN-BJT you would need to draw current (IBE) relative to the load you’re driving based on the HFE of the transistor.

    Now, if you have a (MOS)FET these are voltage driven rather than current and stray signals on the gate can cause it to turn on. So you would put a 10K – 100K pull-down resistor on an N-Channel FET in this configuration.

    There are times in certain circuits where you need to override the startup state until your MCU can get control. In these cases you would use a pull-up or pull-down resistor on the base.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • JonathanJonathan Posts: 1,023
    edited 2009-03-06 23:47
    Chris,

    Thanks for the explanation, and it makes perfect sense. I knew that transistors are current driven and FETS are volatge driven, I just never thought it through. I picked up the pulldown habit long ago, goodness knows where, and then stuck to it. Being self taught has some disadvantages, I've learned more what works than what's right.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-03-10 22:29
    Jonathan,

    I too am self-taught and still pick up stuff here and there. I went to college but never finished due to some personal circumstances in my family life. But I recall my Digital Electronics Professor coming in, giving us a brief dissertation on the current logic gate or whatever and then leaving us to do some project to learn from it while he graded papers from his Math and Science classes. After correcting him on several issues with various diagrams I knew I wasn’t going to get anything from my first 2 years as everything pre-req for EE I learned back in high school. I had a mentor for a few years after that. Being old school I have noticed that some of the ‘standards’ I was taught seem to have changed slightly. I still tend to do things the old way unless protocol dictates otherwise. But the reason I bring this last part up is that a few times in the past on these very forums someone has suggested an alternative or even better way of doing something than what I posted and I too learn from this when it happens. Of course, since I remember you from your first Hydrogen Fuel Cell project I would say there’s something you could probably educate a lot of us on. =) Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • JonathanJonathan Posts: 1,023
    edited 2009-03-11 15:03
    Chris,

    Oh, I don't mind being wrong, especially when someone sets me straight. It's all about learning in the end. After all, we are all usually wrong before we are right. I'm just glad to learn!

    Thanks!

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-03-11 19:24
    One could say there are no wrongs in electronics...only blue smoke activists? Of course I take things more seriously when we step up to electrical stuff dealing with high voltages and currents. Spent two years as an apprentice electrician just for the experience. I can never forget the feeling of 120V going through the human body. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • meganathanmeganathan Posts: 2
    edited 2014-01-20 01:14
    Actually it should be across the coil in reverse bias as shown in the attachment.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
    what is the use of connecting the diode 1N4007
  • meganathanmeganathan Posts: 2
    edited 2014-01-20 01:18
    Actually it should be across the coil in reverse bias as shown in the attachment.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
    with out diode connecting the relay what it will happen?
  • GenetixGenetix Posts: 1,752
    edited 2014-01-20 11:12
    A relay is an inductive load so it will resist any change in voltage causing a kick-back voltage. The diode protects the transistor from the kick-back voltage by absorbing it.
  • Mike GreenMike Green Posts: 23,101
    edited 2014-01-20 12:35
    See this Wikipedia article for an explanation.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2014-01-21 10:08
    When the relay coil is de-energized the collapsing field causes back EMF (simplifying a bit) which the diode clamps/absorbs. Without the diode over time the transistor junction could be damaged causing eventual failure.

    Oops, didn't see answers on the next page. :nerd:
Sign In or Register to comment.