stupidpopia
Posts: 8
Joined: Sat Sep 27, 2014 2:25 pm

Driving 2n2222 with GPIO

Wed Mar 04, 2015 8:20 am

Hello.

I have been trying to troubleshoot what have gone wrong with my transistor or transistorS that I have bought lately.

I am now into getting a 5VDC relay 12VDC output circuit done, and had a hard time wondering what has gone wrong with the 2n2222 transistor. I've tried switching the Resistor to 1k but it didn't do any difference.
Untitled.gif
Untitled.gif (63.62 KiB) Viewed 4921 times
Tested the relay and the red indicator lamp. Nothing's wrong with them. Multimeter hFE checked the 2n2222 as well. Nothing's wrong too.

But couldn't get any value of current nor voltage values from the resistor - collector. If GPIO replaced with LED + resistor, works perfectly fine. But just couldn't get the 2n2222 to work. Been troubleshooting for 2 days.

Thank you for your kindest help.

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: Driving 2n2222 with GPIO

Wed Mar 04, 2015 8:43 am

Hi. I suspect the 2N2222 does not have enough gain to switch such a heavy load as a relay; more often Darlington Pairs or MOSFETs are used instead. Try using an LED as the load instead of the relay - does the 2N2222 switch that lighter load OK?

stupidpopia
Posts: 8
Joined: Sat Sep 27, 2014 2:25 pm

Re: Driving 2n2222 with GPIO

Wed Mar 04, 2015 8:53 am

Yes, the LED lights up, quite bright too. I tried varying the resistor at the Base, apparently lower resistance gives higher voltage across the LED. But still not sufficient to a full 5V.

scotty101
Posts: 4453
Joined: Fri Jun 08, 2012 6:03 pm

Re: Driving 2n2222 with GPIO

Wed Mar 04, 2015 9:08 am

Break the connection between the relay and the transistor, put an ammeter between the two and measure how much current is flowing. If this is less than the relay needs to switch, you need a higher gain transistor.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

User avatar
rpdom
Posts: 20882
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Driving 2n2222 with GPIO

Wed Mar 04, 2015 9:18 am

The usual way to drive something like this is to have the transistor between the relay and ground (which is 0v, not -5v like you have labelled it). You seem to have it between relay and 5v (+5v), which won't give enough power to turn the relay on.

I suggest you search for examples of relay circuits for the Pi to show you how to wire it. A 2N2222 should easily be capable of driving the relay in that configuration.

Also, you are missing the protection diode across the relay coil. This means that the back EMF from the relay could fry your transistor. Pretty much any general purpose diode will do, like a 1N4148 or 1N4001. Negative end of the diode (with the bar) connects to the positive side of the relay coil and positive end of the diode to the negative side of the relay coil.

scotty101
Posts: 4453
Joined: Fri Jun 08, 2012 6:03 pm

Re: Driving 2n2222 with GPIO

Wed Mar 04, 2015 9:55 am

One other thing to check.. I've picked up some relays from junk boxes and it turns out that they already have diodes built in to them. Have you tried connecting the relay coil the other way round?
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

stupidpopia
Posts: 8
Joined: Sat Sep 27, 2014 2:25 pm

Re: Driving 2n2222 with GPIO

Wed Mar 04, 2015 10:24 am

@rpdom

Can you please specify what do you mean by "Relay to Ground"? Do you mean is at the grounding of the coil or the 12V gnd?

Seriously stressing out here on how to get this done.

Thanks.

User avatar
rpdom
Posts: 20882
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Driving 2n2222 with GPIO

Wed Mar 04, 2015 3:10 pm

stupidpopia wrote:Can you please specify what do you mean by "Relay to Ground"? Do you mean is at the grounding of the coil or the 12V gnd?
Sure.
You seem to have your relay wired like in the (very poorly drawn) diagram A. I'm suggesting you wire it like diagram B (which is just as poor).
relay.png
relay.png (3.79 KiB) Viewed 4766 times

User avatar
iinnovations
Posts: 621
Joined: Thu Jun 06, 2013 5:17 pm

Re: Driving 2n2222 with GPIO

Wed Mar 04, 2015 4:42 pm

rpdom wrote:
stupidpopia wrote:Can you please specify what do you mean by "Relay to Ground"? Do you mean is at the grounding of the coil or the 12V gnd?
Sure.
You seem to have your relay wired like in the (very poorly drawn) diagram A. I'm suggesting you wire it like diagram B (which is just as poor).
relay.png
This.
CuPID Controls :: Open Source browser-based sensor and device control
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

ertresvag
Posts: 39
Joined: Sun Oct 27, 2013 1:04 pm

Re: Driving 2n2222 with GPIO

Wed Mar 04, 2015 6:26 pm

iinnovations wrote:
rpdom wrote:
stupidpopia wrote:Can you please specify what do you mean by "Relay to Ground"? Do you mean is at the grounding of the coil or the 12V gnd?
Sure.
You seem to have your relay wired like in the (very poorly drawn) diagram A. I'm suggesting you wire it like diagram B (which is just as poor).
relay.png
This.
And please remember that you loose 0.7V (the Vbe) by using a transistor.
regards Magne

User avatar
iinnovations
Posts: 621
Joined: Thu Jun 06, 2013 5:17 pm

Re: Driving 2n2222 with GPIO

Wed Mar 04, 2015 6:42 pm

I'm going to sound like a broken record, but it would be great if there were an answer rating system. I all too often see five answers of wildly varying accuracy, some completely off-topic, and others completely incorrect. If the goal is to find support, it's much more effective for a user or casual browser to see where to look first, and what is just bunk advice.

C
CuPID Controls :: Open Source browser-based sensor and device control
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

Return to “Troubleshooting”