After following a guide and searching all around the internet, i could not find a any guide related to P channel and arduino tutorials so i decided to follow a N channel one but after powering it all up, the LED remains on and nothing happens to it.
With P-channel MOSFET, gate needs to swing between 12V (off) and 2V (Standard FET) or ~7V (Logic level FET) to be on with the FET between 12V and the load.
With a Logic Level N-channel FET, the gate needs to swing between ~5V (on) and 0V (off) with the FET between the load and Gnd as you have shown.
This would a good N-channel MOSFET
With a Standard N-channel FET, the gate needs to swing between 10V (on) and 0V (off).
Have i actually bought the wrong mosfet or can this do the work too? If i can wire, then what am i missing? The light remains on after connecting it as shown in the first post and arduino has no control over it. Again i really apologise for my lack of knowledge in all electronic stuff. Doing mechanical engineering but electrical is part of the final year project.
That circuit is for an N-ch and as you found out it doesn't work. There must be millions of P-ch tutorials on the web, doesn't have to be Arduino specific.
I assume the bulb shown is really a LED? As such you need a current-limiting resistor in series with the LED or you will blow it up.
If I read that data sheet correct the FET you have should be suitable, you just have to wire it up right.
As you have it the gate resistor will turn the FET on with no signal on pin D3, try moving the resistor to pull the gate to 5V instead of GND, that shoud turn the FET off.
That said if you are driving the gate with a digital output it should overwrite the resistor anyway. Do you have code that drives the D3 pin high for say 1 second then drives it low for 1 seoind. Try the blinky example and change the pin from D13 to D3.
Typical circuit for controlling P-channel MOSFET as high side power switch.
NPN is used to pull the gate Low to turn it on, 1K resistor to 12V pulse gate to turn it off.
Graynomad:
That circuit is for an N-ch and as you found out it doesn't work. There must be millions of P-ch tutorials on the web, doesn't have to be Arduino specific.
I assume the bulb shown is really a LED? As such you need a current-limiting resistor in series with the LED or you will blow it up.
Rob
I've been searching for some time, I think i did find a few but could not understand the drawings. (yes i'm that bad). I understood the part about the G D S but I can't seem to figure out how to put it in a real practical board with arduino. And yeah the bulb is really a LED. I bought a bunch of 10k resistors too.
Graynomad:
If I read that data sheet correct the FET you have should be suitable, you just have to wire it up right.
As you have it the gate resistor will turn the FET on with no signal on pin D3, try moving the resistor to pull the gate to 5V instead of GND, that shoud turn the FET off.
That said if you are driving the gate with a digital output it should overwrite the resistor anyway. Do you have code that drives the D3 pin high for say 1 second then drives it low for 1 seoind. Try the blinky example and change the pin from D13 to D3.
Rob
I tried moving the gate to 5v, It still did not switch off. For the code wise I'm actually using the fade example code from arduino ide. P.S i was using pin 9 instead of 3 as the third one is being used by a motor shield
/*
Fade
This example shows how to fade an LED on pin 9
using the analogWrite() function.
This example code is in the public domain.
*/
int led = 9; // the pin that the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 9:
analogWrite(led, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
CrossRoads:
Many "12V" LEDs have the resistor built in somehow.
I believe it does have a built in resistor but won't wanna risk it anyway
CrossRoads:
Typical circuit for controlling P-channel MOSFET as high side power switch.
NPN is used to pull the gate Low to turn it on, 1K resistor to 12V pulse gate to turn it off.
I did see some setups where they used a NPN, i assumed it wasn't necessary. Do i have to buy that separately too?
The circuit Crossroads posted is the way to do it with 12v, you could try as I suggested running the LED at 5v just to see something working. But for 12v you will have to either buy an NPN to control the FET or buy an N-ch FET.
Also, it's always best to debug ONE thing at a time, ditch that code and write something simple that JUST cycles the pin at a speed you can see (IE the blink example in the IDE), when that works then reinstate the more complex code.
For that matter you can prove the LED circuit by just moving the control wire between GND and 5v, even simpler.
Graynomad:
The circuit Crossroads posted is the way to do it with 12v, you could try as I suggested running the LED at 5v just to see something working. But for 12v you will have to either buy an NPN to control the FET or buy an N-ch FET.
Also, it's always best to debug ONE thing at a time, ditch that code and write something simple that JUST cycles the pin at a speed you can see (IE the blink example in the IDE), when that works then reinstate the more complex code.
For that matter you can prove the LED circuit by just moving the control wire between GND and 5v, even simpler.
Rob
Okay I'll head down to a shop to buy a N channel FET if this doesn't work.
About the debugging, I switched the power to 5 volts and GND as stated and now the LED is completely off, is is possible that the mosfet might be damaged? I ran the blink code as you said and it doesnt work at all
Make sure it's a Logic Level N-channel MOSFET.
Otherwise you will need a NPN in front of it, same as the P-channel, so the gate can swing to 10V to fully turn on, while the NPN pulls it low to turn off.
I still want to thank you both for helping me so much! May i just ask 1 more question, is 1 mosfet enough to power 2 LEDs or I need to buy 2 mosfets? Both the LEDs are gonna be doing the same actions.
I guess I'll have to wait for the seller to contact me asap on the part.
Thank you everyone, grabbed a few mosfets from the college drawers and settled down on IRL540N. I have one last question before i can continue, how will i wire the board if i want to add another LED to this setup? I don't wanna randomly wire because I think i almost blew my arduino yesterday.
If the LEDs are "12 volt" LEDs with internal resistors, and the FET is up to the job current wise, then just put the second LED in parallel with the first.
Graynomad:
If the LEDs are "12 volt" LEDs with internal resistors, and the FET is up to the job current wise, then just put the second LED in parallel with the first.
Rob
THANKS MAN!!!!!!!!!!! I really appreciate how you guys help so much even though you don't have to