Controlling a 12v car led bulb with Arduino

Thread Starter

Ping pong

Joined Feb 13, 2022
78
I have a set of switch back led bulbs installed in my car which plug directly into the stock turn signal harness so the orange/amber LEDs get their positive and negative current from there. There is a third wire sticking out which provides positive current to the white LEDs when the car is turned on. Both white and amber LEDs share a common ground from the factory turn signal harness.

Now I have a simple Arduino code that powers on LEDs with a fade effect using pwm when the car is turned on using a trigger from the car ACC wire. The problem is that I don't understand how I will wire this together.

From what I've read, I need a N channel MOSFET that is connected to the negative/ground of the power supply and the led. But in my case the ground is shared with the stock harness and I cannot give a separate ground to the white LEDs.

Please do note that I'm an amateur when it comes to electronics and Arduino stuff is completely new to me :)

Below are the led bulbs I'm using:
https://a.aliexpress.com/_mMwRJPQ
 

Reloadron

Joined Jan 15, 2015
7,523
From what I've read, I need a N channel MOSFET that is connected to the negative/ground of the power supply and the led. But in my case the ground is shared with the stock harness and I cannot give a separate ground to the white LEDs.
Yes, that would be true. What you are getting at is called low side (ground) switching using a N Channel MOSFET. The following is a schematic of an example of doing low side switching.

LED RGB MOSFET DRIVEN.png

The example uses low side switching driving a RGB LED. You would only need a single channel, not 3 as shown. So what you really want and need is high side switching and we go from an N Channel MOSFET to a P Channel MOSFET. Your LEDs are:
Color: White and Amber
Power: 30W per
Voltage(Input):12~24V

So figure 30 Watts / 12 Volts (give or take automotive voltage we get about 2.5 amps of load per lamp. So we change the switching circuit a little, here is an example of both basic circuits.

High Low Switching MOSFET.png

I would use 10K between Gate and VDD and for the Gate resistor to your Arduino about a 1 K resistor. A Google of "logic level p channel MOSFET Arduino" should get you plenty of circuit examples to work from. Next using an Arduino or similar uC with 5.0 volt logic like an Arduino UNO REV 3 the Fade In / Fade Out is a simple matter of the code. You use PWM to get the fade effect. The actual code is not that complex and there are plenty of examples online. Most people here can give you a code example if you can't find one. Just make sure your choice of P Channel MOSFET can handle the current and will run on logic level since less more circuit your PWM will be 0.0 volt or 5.0 volts. The use of a MODFET for either High Side or Low Side switching is basic electronics. Then there is just a matter of interfacing a uC like an Arduino and writing some basic code to get the effect you want. You would be using two channels of PWM out.

Ron
 

Thread Starter

Ping pong

Joined Feb 13, 2022
78
Wow, that is a pretty elaborate explanation. Thank you very much for the help!
As far as the code is concerned, I asked bing search to generate one for me XD. My Arduino board is still somewhere on a ship because of which I haven't been able to test it yet but I have saved a few similar codes from the web incase AI gets it wrong.
 

Reloadron

Joined Jan 15, 2015
7,523
The high-side P-MOSFET switch operating from a 12V supply cannot be controlled directly from the Arduino since the off gate-voltage is 12V.
It needs an NPN or N-MOSFET driver.
Yes and a my bad for leaving that out. Using the P channel you will want a driver transistor for your MOSFET. Thanks for pointing that out.

Again, a Google of "P channel mosfet Arduino circuit" will get you some good examples.

Ron
 

Thread Starter

Ping pong

Joined Feb 13, 2022
78
Yes and a my bad for leaving that out. Using the P channel you will want a driver transistor for your MOSFET. Thanks for pointing that out.
I have been able to extract the following explanation from bing chat. Does this sound right?

To use a P-channel MOSFET as a switch for an LED strip, you need to apply a negative voltage to the gate when you want to turn on the LED strip, and a zero or positive voltage when you want to turn it off. However, since most microcontrollers (such as Arduino) can only output positive voltages, you need another transistor (such as an N-channel MOSFET) to invert the logic signal.

To wire an N-channel MOSFET as an inverter for a P-channel MOSFET, you need to connect the source of the N-channel MOSFET to ground, the drain of the N-channel MOSFET to a resistor and then to the gate of the P-channel MOSFET, and the gate of the N-channel MOSFET to your microcontroller pin. The resistor acts as a pull-up resistor that keeps the gate of the P-channel MOSFET at a positive voltage when the N-channel MOSFET is off. When you apply a high logic signal (such as 5V) to your microcontroller pin, it turns on the N-channel MOSFET and pulls down the gate of the P-channel MOSFET to ground. This creates a negative voltage across the gate and source of the P-channel MOSFET and turns it on. When you apply a low logic signal (such as 0V) to your microcontroller pin, it turns off the N-channel MOSFET and lets the resistor pull up the gate of the P-channel MOSFET to a positive voltage. This closes the channel of holes in the P-channel MOSFET and turns it off.
 

ElectricSpidey

Joined Dec 2, 2017
2,786
Not exactly.

It's because most micros cannot tolerate 12 volts at an input/output.

Normally if you wanted to drive a PMOS with a micro that doesn't have a "LOW" output you would use a pulldown resistor, but you are still restricted to the voltage limit.

Of course, the invert stage may be required in some circumstances. (such as switching a voltage above what the micro can handle etc...)

Personally, I have never used a micro that can't sink current.
 
Last edited:
Top