24V switching with Raspberry Pi GPIO

Beau Schwabe

Joined Nov 7, 2019
155
Something else doesn't look right with the schematic .... Are any of the LEDs coming ON? The way that it is drawn, the common Cathode of the LED's would need to be connected to NEG supply.... but the Collectors of the NPN transistors are also going to the same connection, indicating that this might be the POS supply. .... The "easiest" way to fix this is swap the Emitter and Collector of the transistors, and make sure ALL of the LED Cathodes as well as the Emitter's are connected to the NEG supply. Reduce the 10k resistor to the transistor Bases to 1k and make sure that the COMMON for J1 to J8 is connected to the POS supply.


Anode --->|--- Cathode
 
Last edited:

dl324

Joined Mar 30, 2015
16,845
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
Your design is deficient and rewiring or starting over isn't an option??

If you want to switch high side, you should use a P type device. The voltage difference between the load supply and the GPIO's will require the use of an inverter or other level shifting method so you can turn the switches off.

The easiest option for you is to switch the load low side. Just admit you made a mistake, learn from it, and redo your board.
 

Thread Starter

SILENT001

Joined Jan 14, 2016
35
You should be switching the load low side. If the load is inductive, you need a snubber diode.
View attachment 228456
For a 60mA load, base current needs to be 6mA. Can the GPIO's provide that?
Thank you for that. I just double checked my built circuit and that is exactly how I have it wired up except my R2 value is 10K not 430. The GPIO's can supply 6mA no problem. If I did it exactly as the above drawing then why do I blow transistors? Could it be that I cycle the power too often and the transistor can not handle that?
 

Thread Starter

SILENT001

Joined Jan 14, 2016
35
Your design is deficient and rewiring or starting over isn't an option??

If you want to switch high side, you should use a P type device. The voltage difference between the load supply and the GPIO's will require the use of an inverter or other level shifting method so you can turn the switches off.

The easiest option for you is to switch the load low side. Just admit you made a mistake, learn from it, and redo your board.
I am switching low side. My schematics are not perfect and I am still learning on how to correctly draw them however when building the board I did have it low side switching because from what I have learnt that is the correct way of using a NPN transistor. I admit I made a mistake but I would like to fix the current design because it was a lot of work to build the first board using Vero board(would have had it printed but way to costly in the country I live in) so would prefer not to redo the entire board from scratch but if it is the only option then I will need to do it.
 

dl324

Joined Mar 30, 2015
16,845
I just double checked my built circuit and that is exactly how I have it wired up except my R2 value is 10K not 430. The GPIO's can supply 6mA no problem. If I did it exactly as the above drawing then why do I blow transistors? Could it be that I cycle the power too often and the transistor can not handle that?
What do you mean by "exactly as above"? With a diode, a 10k resistor, or a 430 ohm resistor?

My guess is that you weren't turning the transistor on hard enough and it wasn't saturating. That caused maximum power dissipation to be exceeded.

If the GPIO could source sufficient current, with a diode on the base instead of a current limiting resistor, you could have destroyed the BE junction.
 

dl324

Joined Mar 30, 2015
16,845
My schematics are not perfect and I am still learning on how to correctly draw them however when building the board I did have it low side switching because from what I have learnt that is the correct way of using a NPN transistor.
Drawing a schematic willy-nilly and using incorrect symbols is one thing, but there's no excuse for not being able to accurately show how things are connected.
 

nsaspook

Joined Aug 27, 2009
13,081
I am switching low side. My schematics are not perfect and I am still learning on how to correctly draw them however when building the board I did have it low side switching because from what I have learnt that is the correct way of using a NPN transistor. I admit I made a mistake but I would like to fix the current design because it was a lot of work to build the first board using Vero board(would have had it printed but way to costly in the country I live in) so would prefer not to redo the entire board from scratch but if it is the only option then I will need to do it.
You need to post an actual accurate schematic of what you have on the actual board for people to analyze. My suggestion of using Darlington drivers still stands.

 

Thread Starter

SILENT001

Joined Jan 14, 2016
35
Good day all,

So I have attached two drawings to better explain what my original drawing does. Please see attached. I used fritzing to draw the schematic and also attached a breadboard image
 

Attachments

Beau Schwabe

Joined Nov 7, 2019
155
What you have fritzed vs what you have drawn in the schematic do not match... The fritzed drawing looks correct, the schematic has the polarity on the power plug backwards.
 

djsfantasi

Joined Apr 11, 2010
9,156
Good day all,

So I have attached two drawings to better explain what my original drawing does. Please see attached. I used fritzing to draw the schematic and also attached a breadboard image
I can’t read Fritzing diagrams without too much work. But you have confused the 24V power connections.

And the schematic’s problems cannot be solved by simply changing the 24V connection polarity.
  • The MCU needs its own power supply (not 24V). It’s ground and the 24V ground needs to be connected
  • The 2N222 emitter needs to be connected to this common ground as well
  • 24V + needs to go to the load + connection
  • The 2N222 collector needs to connect to the load - connection.
 

Beau Schwabe

Joined Nov 7, 2019
155
60mA x 24V = 1.44 Watts of heat from the 2n2222 ... the 2n2222 has a maximum rating of 1.5 Watts at ambient temperatures of 25C . Anything above 25C is derated. It also says that the heat dissipation is 12mW per degree .... This means that at 1.44 Watts you would have an increase above ambient temperature of 120 Deg (1440 mW / 12 mW = 120) ... 120 +25 yields 145 Deg wich is very close to the 150 Deg max.

Simply put ... you need a bigger transistor

1613435781624.png
1613435879765.png

reference datasheet:
https://www.onsemi.com/pub/Collateral/P2N2222A-D.PDF
 

Thread Starter

SILENT001

Joined Jan 14, 2016
35
60mA x 24V = 1.44 Watts of heat from the 2n2222 ... the 2n2222 has a maximum rating of 1.5 Watts at ambient temperatures of 25C . Anything above 25C is derated. It also says that the heat dissipation is 12mW per degree .... This means that at 1.44 Watts you would have an increase above ambient temperature of 120 Deg (1440 mW / 12 mW = 120) ... 120 +25 yields 145 Deg wich is very close to the 150 Deg max.

Simply put ... you need a bigger transistor

View attachment 230543
View attachment 230544

reference datasheet:
https://www.onsemi.com/pub/Collateral/P2N2222A-D.PDF
Would switching out the 2N2222A for a MOSFET work better?
 

Beau Schwabe

Joined Nov 7, 2019
155
" If the transistors are fully saturated with only a fraction of a volt across them when on they won't be dissipating anything like 1.44W! " - Agreed ... my mistake. However it would be worst case scenario.

SILENT001 - How did you measure 60mA and what is the LOAD you are driving? And your absolutely positive you have the CBE of the transistor connected properly?
 

Thread Starter

SILENT001

Joined Jan 14, 2016
35
" If the transistors are fully saturated with only a fraction of a volt across them when on they won't be dissipating anything like 1.44W! " - Agreed ... my mistake. However it would be worst case scenario.

SILENT001 - How did you measure 60mA and what is the LOAD you are driving? And your absolutely positive you have the CBE of the transistor connected properly?
How I measured the current draw of the load is using a lab bench power supply set to 24V. At idle the device uses 0.034A and under load about 0.050A so for safety I have adjusted it to 60mA. I have also updated the schematic again doing my best to follow convention and insuring no errors. The CBE of the transistor could be connected incorrectly so I have decided on getting a schematic with values that will work in theory and rebuilding the entire board from scratch following the schematic as I build.

The schematic connections are as follows:
J1 connects to the Raspberry Pi with relevant pins SDA to SDA, SCL to SCL, GND to GND, 3V3 to 3V3.
J2 to J11 connect to the 24V load @ 60mA
J12 is the 24V PSU input
R21 to R30 is 1K resistors.

Apologies I have tried using eagle to draw schematics but I need more time and practice to use Eagle so I have been using DipTrace to draw the schematic and then exporting it to Eagle for export to PDF as DipTrace schematic prints look horrible in comparison. DipTrace does not show component values on the schematic so I will need to learn to use Eagle (struggling on getting the Net Ports to work with Eagle) as this provides the values of the components on the schematic.

EDIT#1: Added schematic details
 

Attachments

Last edited:
Top