24V switching with Raspberry Pi GPIO

Thread Starter

SILENT001

Joined Jan 14, 2016
35
Good day all,

Sorry if this question is in the wrong place and has been asked before but I could not find a solution that fits my current predicament. So I have designed a built a electronic circuit, I am no professional with self taught experience, but from my knowledge it should work flawlessly however I keep blowing transistors. My original circuit, attached, did work when I was writing my code however after building it with multiple units I often blow transistors. I am using a 2N2222A transistor that is attached to the 24V line and the base is controlled from GPIO pins (in this case a I2C GPIO expander). So the main design of the board is too be able to turn on and off ten 24V powered devices using GPIO pins of the I2C GPIO expander. I also turn the units on multiple times for a reliable startup test and the units draw 30mA @ 24V. I originally had a diode in between the 3.3V GPIO and the transistor base however I kept blowing transistors so I swapped the diodes out for 10K resistors and still I keep blowing transistors. I do not understand why I keep blowing transistors as the max current I draw is 60mA @24V and the transistor is rated for 800mA. Is the a flaw in my schematic? Have I overlooked something obvious? A friend of mine suggests that I replace the transistors with MOSFET's however I know very little about them to spec the correct one for the 3.3V I have to drive the base. Please can someone assist me with this as I really need to get this working again and reliable as this board is used to test units that I build.

Details of attached circuit:
J1-J10 is the 24V power sockets for the units being tested that gets turned on and off by the GPIO pins via a transistor.
J11 is the 24V input line from a 24V power supply.
J12 is the header that connects to the GPIO header of the Raspberry Pi that is used to control the GPIO expanders
U1 & U2 is the GPIO expanders "Microchip MCP23017-E/SP"
Q1-Q10 is the 2N2222A transistors
D11-D20 is RED & GREEN LED's
D1-D10 is 1N4001 diodes that was swapped out for 10K resistors
*NB I know that the two grounds are not connected in my drawing however I did find the fault in my design while testing it out the first time I built it

Mod: Opened the PDF circuit.E
 

Attachments

Last edited by a moderator:

Thread Starter

SILENT001

Joined Jan 14, 2016
35
I'd use a ULN2803a for open collector drivers like they did on this commercial RPi interface board.
https://www.element14.com/community/servlet/JiveServlet/downloadBody/52867-102-1-267216/Assembled Gertboard Schematics.pdf
Good day nsaspook, thank you for the reply, sadly I have built a board already with everything wired together on a vero board so the current layout will only work for a 3 pin throughhole type hence my earlier statement of using a mosfet but I have no knowledge of the type of mosfet to use.
 

sarahMCML

Joined May 11, 2019
363
Good day nsaspook, thank you for the reply, sadly I have built a board already with everything wired together on a vero board so the current layout will only work for a 3 pin throughhole type hence my earlier statement of using a mosfet but I have no knowledge of the type of mosfet to use.
If your GPIO expanders are running from 5 Volts then they are only driving the transistor bases to ~3 or 4 volts if you're lucky, meaning that they have something like 20 odd volts between their collectors and emitters, and are probably being overloaded! Do check this if you have a multimeter.
 

dl324

Joined Mar 30, 2015
16,839
Details of attached circuit:
That information should be on the schematic.
clipimage.jpg
  1. What is the polarity of the power jack?
  2. What are the resistor values?
  3. What voltage are the GPIO's?
  4. What is their current capability?
  5. What voltage is D1?

Where did you learn to draw a schematic like that? We don't route wires over components or text and we prefer for the flow to be primarily left to right and top to bottom.
 

djsfantasi

Joined Apr 11, 2010
9,156
What is J11 used for? If it’s the power supply and is wired as shown in the picture, the circuit will never receive power from anything plugged into it.

The switched output (J11-3) goes to the circuit. The sleeve will disconnect the switched output from power. Since the sleeve jack output (J11-3) isn’t connected to anything, there will be no power to the circuit.

1611251316096.jpeg
 

nsaspook

Joined Aug 27, 2009
13,079
Good day nsaspook, thank you for the reply, sadly I have built a board already with everything wired together on a vero board so the current layout will only work for a 3 pin throughhole type hence my earlier statement of using a mosfet but I have no knowledge of the type of mosfet to use.
I'm having a hard time making heads or tails of your schematic. It seems to me you're driving the loads using an emitter follower transistor configuration with a series zener of unknown value driving the base from the gpio expander with no obvious return path for base current.
 

GT_1

Joined Oct 9, 2020
7
1) your circuit diagram is very poorly drawn. That is part of your problem. You should draw it in sections using wire names or off page connectors.
2) It looks like you are trying to drive the load as an emitter follower. You can make things MUCH simple by using common emitter, which means, your emitter is grounded and your load is placed between Vcc and the collector.
3) A text drawn pic is shown below. (The transistor doesn't show an arrow due to txt limitations)
4) If any Rl is an inductive load you need a diode placed across Rl with the stripe toward Vcc, For the current you are talking about a 1n914/1n4148 would be fine.
5) the circuit analysis for this is simple: Vgpx -.7v = ib * Rb.
Ic = beta * ib; beta for a 2222A =hfe =~ 100 ; Ic min = 60 ma; => ib = 60ma/ beta = 60ma/100 = > ib = .6ma
and hence Rb = (Vgpx_on -.7v)/.6ma, e.g. for Vgpx_on = 5V then 4.3v/.6ma = ~ 7.2K anything in the range of 4.7k to 7.2k may be used (that's using 60ma which is double your typical required rating. This calculation gives the upper limit. The lower limit depends upon upper limit for base current which you get from the specs and calc the same way, making sure you don't exceed that.
The txt pic I tried to post didn't come out right, but just slide the base back to make the transistor symbol and you have it.

Vcc
|
RL
|
/c
GPx--Rb--b-|
\ e
|
Gnd
 

sarahMCML

Joined May 11, 2019
363
What is J11 used for? If it’s the power supply and is wired as shown in the picture, the circuit will never receive power from anything plugged into it.

The switched output (J11-3) goes to the circuit. The sleeve will disconnect the switched output from power. Since the sleeve jack output (J11-3) isn’t connected to anything, there will be no power to the circuit.

View attachment 228395
What is the load that the emitter of Q1, etc, switches 24 volts to. In other words, what does connector f1, etc, go off to? The current circuit cannot possibly switch more than ~3 or 4 volts max out of f1.
 

djsfantasi

Joined Apr 11, 2010
9,156
What is the load that the emitter of Q1, etc, switches 24 volts to. In other words, what does connector f1, etc, go off to? The current circuit cannot possibly switch more than ~3 or 4 volts max out of f1.
I don’t understand your post. It has nothing to do with my observation. What is J11 connected to?
 

Thread Starter

SILENT001

Joined Jan 14, 2016
35
Good day all, thanks for all the replies but I would appreciate it if people read the full post before replying so I am going to point out a few things again. "I am not a professional, everything I know I taught myself. I have never been taught to draw schematics. This is my second schematic that I have ever drawn" So I decided to draw only the part that is relevant to my question and it is attached. So the right "24V" and "-24V" come from a 24V power supply. The left "24V" and "-24V" go out to a load device. On the left you have a 3.3V GPIO pin that goes through a 10K resistor connected to 2N2222A transistor. The load on the right is max 60mA @ 24V. So the part I am having trouble with is that the transistor tends to burn out. I am assuming it has to do with the voltage difference so I would like to swap out the transistor for a MOSFET as it might be able to handle the voltage difference better.
 

Attachments

nsaspook

Joined Aug 27, 2009
13,079
Good day all, thanks for all the replies but I would appreciate it if people read the full post before replying so I am going to point out a few things again. "I am not a professional, everything I know I taught myself. I have never been taught to draw schematics. This is my second schematic that I have ever drawn" So I decided to draw only the part that is relevant to my question and it is attached. So the right "24V" and "-24V" come from a 24V power supply. The left "24V" and "-24V" go out to a load device. On the left you have a 3.3V GPIO pin that goes through a 10K resistor connected to 2N2222A transistor. The load on the right is max 60mA @ 24V. So the part I am having trouble with is that the transistor tends to burn out. I am assuming it has to do with the voltage difference so I would like to swap out the transistor for a MOSFET as it might be able to handle the voltage difference better.
Notice how the schematic is drawn and how the transistor is connected. With an NPN transistor the emitter is normally directly connected to the negative voltage reference point (the circuit ground/common between the gpio circuit vss and load power supply negative)
while the load is in series with the positive load supply and collector of the transistor. When the gpio current is HIGH the transistor switches ON with a low resistance value from collector to emitter, when the gpio is LOW the transistor is in a high resistance state from collector to emitter. Both transistor switching states reduce the power the transistor dissipates while passing or preventing load power supply current to through the load resistance.
http://raspberrypi-aa.github.io/session2/power-control.html
 
Last edited:

dl324

Joined Mar 30, 2015
16,839
On the left you have a 3.3V GPIO pin that goes through a 10K resistor connected to 2N2222A transistor.
You should be switching the load low side. If the load is inductive, you need a snubber diode.
clipimage.jpg
For a 60mA load, base current needs to be 6mA. Can the GPIO's provide that?
 

GT_1

Joined Oct 9, 2020
7
dl324

You just regurgitated exactly what I said above. except he is using a 2222a which according to the spec sheet has typical hfe of 100. So, only 0.6 ma should be required for a 60 ma max load. And I gave him all the simple math to calculate the real world best case conditions.

I don't know why he is trying to make a such simple problem so difficult. Maybe he should consider having someone do this for him.
 

dl324

Joined Mar 30, 2015
16,839
You just regurgitated exactly what I said above. except he is using a 2222a which according to the spec sheet has typical hfe of 100. So, only 0.6 ma should be required for a 60 ma max load.
You used a beta of 100 for saturation mode and that's wrong. The datasheet uses 10. For some BC transistors, datasheets specify 20.

I gave up trying to read your text schematic. A scribble in paint would have been better.
 

sarahMCML

Joined May 11, 2019
363
I don’t understand your post. It has nothing to do with my observation. What is J11 connected to?
Sorry, I was referring not to you but to the attachment diagram within it. I'm using an Android tablet to access these fora and can't seem to get it to snip and insert parts of previous posts as I would like.
 

dl324

Joined Mar 30, 2015
16,839
I'm using an Android tablet to access these fora and can't seem to get it to snip and insert parts of previous posts as I would like.
Glad it isn't just me. I usually end up bringing the page up in Windows so I can select more easily - and touch type.
 

sarahMCML

Joined May 11, 2019
363
Good day all, thanks for all the replies but I would appreciate it if people read the full post before replying so I am going to point out a few things again. "I am not a professional, everything I know I taught myself. I have never been taught to draw schematics. This is my second schematic that I have ever drawn" So I decided to draw only the part that is relevant to my question and it is attached. So the right "24V" and "-24V" come from a 24V power supply. The left "24V" and "-24V" go out to a load device. On the left you have a 3.3V GPIO pin that goes through a 10K resistor connected to 2N2222A transistor. The load on the right is max 60mA @ 24V. So the part I am having trouble with is that the transistor tends to burn out. I am assuming it has to do with the voltage difference so I would like to swap out the transistor for a MOSFET as it might be able to handle the voltage difference better.
You say that the left "-24V", i.e. the emitter of the transistor, goes out to the load. So you are using the transistor in what is known as "emitter follower" mode. Therefore if its base is switched high ~+5V, its emitter can only be at about +4.5V, leaving about 20 ish volts across the transistor. 20V x 60mA = 1.2Watts, a bit much for a 2N2222A.
As dl324 says in message #14, you should be switching the low side with a "common emitter" circuit.
 
Top