Newbie... 12V High side Switch with Arduino - Page 1
Forum section: electronics / projects

author: NivagSwerdna
author_rank: Super Contributor
timestamp: February 14, 2025, 01:05:59 pm
content: [ Specified attachment is not available ]Background... I want to turn a 12V lamp ON and OFF using the digital output of a 5V Arduino... I need high side switching (because the lamps are actually muxed and this is for the high side). I also need common ground between the arduino and the 12V supply...So I googled and foundhttps://forum.arduino.cc/t/high-side-switch-with-p-channel-mosfet/874155which I think is this..I do have some IRF9640 so this feels ideal... but...

author: NivagSwerdna
author_rank: Super Contributor
timestamp: February 14, 2025, 01:08:44 pm
content: So I think this tells me the lamp will always be ON? 100mA should be enough to light it?

author: pqass
author_rank: Super Contributor
timestamp: February 14, 2025, 01:25:59 pm
content: T2 is a P-FET. Source should be connected to +12V and drain to load. You have it reversed.There's an internal body diode that is reverse biased. But because you've put source-drain pins backwards, the diode always conducts.Also, there's usually a 100R between T1 collector and T2 gate. And R1 is usually 1K (vs 10K).

author: tooki
author_rank: Super Contributor
timestamp: February 14, 2025, 01:34:43 pm
content: Flip the MOSFET over. You have it upside down, so it’s always conducting through the body diode.Also, I guess you didn’t keep reading that thread, since you copied the original schematic without any of the modification suggested later on.R1/R3 forms a voltage divider cutting the input voltage in half. Change R3 to 100K and move it to the left of R1.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: February 14, 2025, 02:24:17 pm
content: Thanks so much! I've been pulling my hair out over that!...and..Looking much better (even with a small simplification)

author: PGPG
author_rank: Frequent Contributor
timestamp: February 14, 2025, 05:22:11 pm
content: Quote from: tooki on February 14, 2025, 01:34:43 pmIf there would be anything wrong in it than NEXPERIA would not manufacture it:https://assets.nexperia.com/documents/data-sheet/PDTC114ET.pdfUsing 10k+10k at input is widely used solution worldwide.At Mouser you can order 149 000 of them today.I don't know if in real circuit connection to VG1 is permanent and if VG1 can be HiZ, but if it can be disconnected or VG1 can be set in HiZ state then 10k R3 is perfectly rationale.Quote from: NivagSwerdna on February 14, 2025, 02:24:17 pmR4 8k at 12V needs 1.5mA.At 1mA 2N3904 has hfe21 minimum = 70.So it needs 1.5mA/70 = 0.02mA in base minimum. To work in serious saturation you typically use 20x higher then minimum needed current so 0.02*20=0.4mA.In your first circuit you had 2.5V source with 5k output resistance (Thevenin's voltage source). So you were driving base with (2.5-0.7)/5 = 0.36mA (exactly as needed).Now you give it (5-0.7)/1 = 4.3mA. Instead of saturating it 20 times you saturate it 215 times.

author: tooki
author_rank: Super Contributor
timestamp: February 14, 2025, 06:00:25 pm
content: Quote from: PGPG on February 14, 2025, 05:22:11 pmI never said it was wrong. In some circuits it could be desirable. It’s just something to be aware of, and in this case it probably doesn’t matter much, but changing the resistor order certainly won’t hurt.

author: PGPG
author_rank: Frequent Contributor
timestamp: February 14, 2025, 07:38:20 pm
content: Quote from: tooki on February 14, 2025, 06:00:25 pmCertainly?Calculate the situation when we drive it from low impedance 0/5V sourse.Situation 1 - second 10k direcly at base.Base on current: (2.5V-0.7V)/5k = 0.36mABase discharge current: 0.7V/5k = 0.14mA.Situation 2 - second 10k is on the left (if source is low impedance we can ignore this resistor).Base on current: (5V-0.7V)/10k = 0.43mA - 20% higher then previously - 20% deeper saturation.Base discharge current: 0.7V/10k = 0.07mA.When turning off the transistor you need to remove excess carriers from the base area. You have 20% more of them and use 2 times smaller current to take them off. 1.2/0.5 = 2.4. Not sure but I would expect 140% longer switching off time.Does it hurt - it depends... In OPs circuit probably not.I think I sow there (in mentioned discussion) a solution with this 10k not only moved to the left but also changed into 100k. Now imagine beginner will use it with input from any reason driven from pnp collector from 12V.On current: (12-0.7)/10k = 1.13mAOff current: 0.7/110k = 0.00635mACompared to situation 1:Saturation 3.1 times higher. Discharge current 22 times smaller. We got probably 68 times (6700%) longer switch off time. Even if it is not 68 but only 20 or even only 10 it can be important. I'm not using Spice, but someone interested in it may be will check what Spice tells for all these 3 situations (third circuit will have to have also driving pnp transistor).If someone will be taught from infancy to use second resistor directly at base he will never, ever make such mistake.As I've said in the OP's circuit it is probably not too important, but I always opt for learning better practices from beginning.

author: robert.rozee
author_rank: Frequent Contributor
timestamp: February 15, 2025, 01:37:35 pm
content: in the schematic of Reply #4, adding a small capacitor across R1 (or a small capacitor in series with a smallish resistor) may help square-up the rising edge shown on the Vgate trace - although in the intended application this is likely to not matter much.cheers,rob :-)

author: NivagSwerdna
author_rank: Super Contributor
timestamp: February 15, 2025, 06:04:19 pm
content: I admit I don't understand some of the replies...and...So using the terminology of this schematic... I can see R3 might be useful when VG1 is Z... which is true at start-up. It is a digital output from a 5V Arduino... 0V or 5V.However in my application I think being ON whilst the uP is starting probably isn't an issue. Didn't know you could get transistors with the two resistors built-in... that's interesting.During simulation I see to think that the value of R4 is more significant to my design. I chose 8k because that is literally the first value I found when I reached into my random through hole resistor pile! From the simulation though I do notice that the ramp of turn off is accelerated by reducing R4.My application uses this for the high side of a 3x3 grid of incandescent 12V 1.2W bulbs; when I get it working they will be operating at approx 200Hz muxed... i.e. on for 1/3 of the time at which point I will increase the supply to 34V (or maybe 28V) depending on what is to hand.I will try and keep re-reading your replies until I understand them!

author: tooki
author_rank: Super Contributor
timestamp: February 16, 2025, 11:50:14 am
content: Quote from: PGPG on February 14, 2025, 07:38:20 pmIn this circuit, I would say it certainly won’t hurt. I’m not talking about other circuits.

author: madires
author_rank: Super Contributor
timestamp: February 16, 2025, 04:00:55 pm
content: Regarding T1 plus R1 and R3: What is a digital transistor? (https://www.rohm.com/products/faq-search/faqId/234)

author: SteveThackery
author_rank: Super Contributor
timestamp: February 16, 2025, 06:01:56 pm
content: Quote from: madires on February 16, 2025, 04:00:55 pmThat's fascinating! I had no idea there was such a thing. That's another day I've learned something.Thanks!

author: Zero999
author_rank: Super Contributor
timestamp: February 17, 2025, 11:16:06 am
content: The BJT is not the speed bottleneck in the OP's design. It's the gate-source resistor (R4) which is slowly discharging the MOSFET's gate. This can be seen by the slow rise time of the gate voltage on the graphs.The solution is to add another BJT, configured as an emitter follower to help pull up the gate voltage. The diode bypassing the emitter-base enables the existing BJT to pull the voltage down.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: February 17, 2025, 09:26:29 pm
content: @Zero999Thanks. That makes a lot of sense... and explains why reducing R1 (in your schematic) has the effect it does.I'm too tight to add another transistor (and diode) but I do see your point.