Need help with Raspberry Pi GPIO controlling a relay

Thread Starter

cliff_n

Joined Feb 15, 2014
3
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?
 

Attachments

burger2227

Joined Feb 3, 2014
194
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.
 

Thread Starter

cliff_n

Joined Feb 15, 2014
3
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.
 

MaxHeadRoom

Joined Jul 18, 2013
28,686
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.
 

#12

Joined Nov 30, 2010
18,224
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.
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.
 

MaxHeadRoom

Joined Jul 18, 2013
28,686
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.
 

Attachments

#12

Joined Nov 30, 2010
18,224
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.
 

Attachments

Thread Starter

cliff_n

Joined Feb 15, 2014
3
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!
 
Top