Need help with Raspberry Pi GPIO controlling a relay

Discussion in 'The Projects Forum' started by cliff_n, Feb 15, 2014.

  1. cliff_n

    Thread Starter New Member

    Feb 15, 2014
    3
    1
    This is my first electronics project. I'm familiar with programming and have lots of experience with low-voltage controls used in HVAC equipment, and now I'd like to combine the two interests. The idea is to control a heater for a fishtank using a Raspberry Pi. I've got a USB temperature sensor and worked out a program to turn on a GPIO pin when the temperature drops, but after reading lots of warnings about what you can (and can't) control with the Pi's 3.3v GPIO pins, I'd really appreciate someone checking what I'm doing.

    I do know that I can't control my relay directly. I thought I'd control the relay through a radioshack TIP3055 transistor, but I found a discussion that said that transistor shouldn't be used directly with the Pi. Instead, the author recommended using a smaller transistor to power the TIP3055, and then the TIP3055 powers the relay coil, and the relay's contacts will switch the line voltage for the heaters.

    So to start with, I found a BF494 transistor and made a small test circuit to power a LED light. Would someone look this over and see if I missed something that might end up damaging my Raspberry Pi? My next step will be to take the LED out and put the TIP3055 in its place. I'll need to power a 12vdc relay coil (75mA) by means of that transistor, so I'll need to add a power source in addition to the Raspberry Pi. That's fine, but how do I work that in to the circuit?
     
  2. burger2227

    Member

    Feb 3, 2014
    190
    24
    You might consider optoisolators instead of trying to power anything directly. The isolator is just like powering an LED. The internal LED turns on a transistor or Darlington pair that can run relays and higher powered devices. Save the Pi to do the thinking.
     
  3. #12

    Expert

    Nov 30, 2010
    16,355
    6,852
    A BF494 can only do 30 ma. A 2N3055 can do several amps. Try this.
     
  4. cliff_n

    Thread Starter New Member

    Feb 15, 2014
    3
    1
    Thanks. I will give that a try. Burger2227 was concerned about isolating the working circuit from the control circuit, but I think I'll be OK with the contacts on the relay doing that part. But I'm not as sure of how to do that same thing with a transistor. Using your drawing, I understand where the 3.3 v comes from -- the Raspberry Pi. It's got a 3.3v IO pin I can control and a ground pin. I also have a "wall-wart" type power supply from a box of spare parts that can provide 2n904 radioshack 12vdc. Can I just take the ground wire from that and connect it to the same ground that the transistor is connected to, and connect the +12 side to the relay's coil? Hopefully that's not too stupid a question.
     
  5. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    4,771
    971
    yes you combine the 2 grounds (at the unfilled downward arrow in the diagram)
     
  6. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,571
    2,381
    Why is it that most posting these type of simple logic driven devices do not look at gate logic Hexfets and lower the demand on the I/O pin?
    This is the first thing I look to.
    Max.
     
  7. #12

    Expert

    Nov 30, 2010
    16,355
    6,852
    Because 1) I'm old and 2) it's likely the OP has a 2N3904 or a 2N2222 or something similar.

    I wish you would post your version of the circuit, the part number, or something that would help the OP.
     
  8. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,571
    2,381
    Essentially the same as your circuit in post #3 except the base resistor is taken to common.
    For low level power I use a 2N7000 and IRL520/530 for power.
    The attached dwg requires a reverse EMF diode across an inductive load.
    Max.
     
    #12 likes this.
  9. #12

    Expert

    Nov 30, 2010
    16,355
    6,852
    Possible problem. Page 4, figure 5 shows that the 2N7000 is just barely starting to conduct at 3.3 volts gate to source. This would work if the Pi was running on 5 volts.
     
    GopherT likes this.
  10. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,571
    2,381
    I also tend to use a larger pull down, the diag was taken off of a web site.
    I use 500Ω to 1k.
    Max.
     
  11. #12

    Expert

    Nov 30, 2010
    16,355
    6,852
    Your drawing already says, "1k".
     
  12. cliff_n

    Thread Starter New Member

    Feb 15, 2014
    3
    1
    Thanks everyone for your help. Sure, there's lots of ways to solve the problem, but the fun is in the learning. I never heard of "gate logic Hexfets" before -- I'm still reading manuals from kid's electronic kits that have smiley faces drawn on the transistors. I ended up using the circuit from post #3, and after a little trouble with the soldering I now have a Raspberry Pi monitoring, reporting on, and *controlling* the temperature in our fishtank. Who says water and electricity don't mix!
     
    #12 likes this.
  13. #12

    Expert

    Nov 30, 2010
    16,355
    6,852
    Sometimes I get lucky.:cool:
     
Loading...