Notifications
Clear all

MOSFET is always on

26 Posts
6 Users
7 Likes
695 Views
TASan
(@tasan)
Member
Joined: 1 year ago
Posts: 46
Topic starter  

I am writing this between work and kids, so I am writing in a rush and not with the clearest head. I am sorry in advance for not providing a drawing of my circuit. I hope this is possible to follow. So I am basically trying to learn about LED strips and Arduinos. I have a 24V RGBW strip that I have connected through a MOSFET using a breadboard just to see if I am able to control it.

The white cable of the strip is connected to the drain of the MOSFET. Pin 7 of the Arduino is connected to the gate of the MOSFET. The source of the MOSFET is connected to the - of the breadboard. The - of the breadboard is connected to the ground of the Arduino. The + of my 24V DC power supply is connected to the + of the breadboard. The - of the power supply is connected to the - of the breadboard. The DC cable of the LED strip is connected to the + of the breadboard.

All this makes the LED strip glow bright white, but setting digitalWrite on pin 7 to high or low does nothing. I would expect that to turn on and off the strip, but it has no effect. What could be wrong? Have I connected the MOSFET the wrong way, meaning the spec sheet I have found maybe have the gate and source on the wrong side? Is the MOSFET not rated for Arduino (it should be, but some reviews say it is not)? Shouldn't the latter mean that I would not be able to turn the LED strip on, not that I wouldn't be able to turn it off?

Again, sorry for not providing a drawing. I am just writing this in an absolute rush in the hopes that there are some answers later when I am able to sit down and look into this! 🙂

Thank you so much in advance!

Interested in learning about electrical engineering!


   
Quote
(@hilldweller)
Member
Joined: 1 year ago
Posts: 111
 

What is the part number of the MOSFET ?


   
ReplyQuote
TASan
(@tasan)
Member
Joined: 1 year ago
Posts: 46
Topic starter  

@hilldweller

8A28RL

P30N06LE

Interested in learning about electrical engineering!


   
ReplyQuote
(@hilldweller)
Member
Joined: 1 year ago
Posts: 111
 

P30N06LE looks good to me. It's logic gate drive which matches the Arduino.

Source to GND - OK

Maybe you forgot to initialise the pin 7 as an output.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2504
 

@tasan

One thing your description of your setup didn't seem to include was a resistor (say 10K or more) between the gate and ground. Its purpose is to make sure that the MOSFET is turned off cleanly when your pin 7 goes LOW.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
TASan
(@tasan)
Member
Joined: 1 year ago
Posts: 46
Topic starter  

@will 

Now this is why I am here! 😊 I did not realize I needed anything more. I did try a resistor of 220 between source and ground, but that just made the LED strip dimmer.

Ok, so I'll try a 10k resistor between the gate and ground. I understand what you are saying about what that does, but how does it do that? Does it dump residual current or something faster to ground? I'm not sure I can picture it clearly 🤔

Interested in learning about electrical engineering!


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2504
 

@tasan 

What it does is connect the gate to ground but through a medium resistance (to keep the current low). This means that if pin 7 doesn't turn all the way off or if it drifts, that the gate will still be at zero volts and should shut off.

Note that for a P-channel MOSFET, you'd tie the gate to VCC with a resistor.

PS - you should definitely declare the pin as OUTPUT too as @hilldweller suggested.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
TASan
(@tasan)
Member
Joined: 1 year ago
Posts: 46
Topic starter  

I must have forgotten the pinMode for some reason. It works without a resistor with this simple code:

void setup() {
  // put your setup code here, to run once:
  pinMode(7, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(7, LOW);
}

Now, is it bad practice to write LOW to the pin repeatedly like this, or does the Arduino do its own checks to avoid spamming the pin? I don't know if my thought here makes sense.

Should I use a resistor even though it works fine without?

Interested in learning about electrical engineering!


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2037
 

@tasan 

Personally I avoid "guess what I have done wrong" questions. Best find how to do it on the internet first. You will get the Arduino code thus not forget what has to be initialized.

It is worth spending time learning about the components before using them.
https://dronebotworkshop.com/transistors-mosfets/
You can attach an image of your efforts (making sure all the wiring is clear to see) with the Attach File option

To enlarge an image, right click image and select Open Link in new window.

attachFile

 


   
ReplyQuote
TASan
(@tasan)
Member
Joined: 1 year ago
Posts: 46
Topic starter  

@robotbuilder 

I did use an example sketch first and then modified it, but I must have somehow modified away the pinOut. It now works as expected and I am controlling the LED strip with an ultrasonic sensor. Yay! 🙂

Interested in learning about electrical engineering!


   
DaveE and Brian reacted
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2504
 

@tasan 

You should ALWAYS set pinMode to adapt the pin to the use you intend for it and you may want to assign an initial value in your setup() routine as well. Otherwise the pin value may "drift" (i.e. vary in voltage) and appear to be HIGH sometimes and LOW other times with a value that you did not set into it.

As for the resistor to the MOSFET gate, it's a good habit to get into (even though you'll rarely find it absolutely critical for operation). You use a moderate value (10K or more) because that induces a subtle pull towards ground and will keep a "drifting" pinned low and keep the MOSFET off but is easily swamped when the the pin is pulled HIGH (since it draws so little current).

Anything seems possible when you don't know what you're talking about.


   
DaveE reacted
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2504
 

Posted by: @robotbuilder

@tasan 

Personally I avoid "guess what I have done wrong" questions.

But seriously, isn't that the underlying point of almost every question posed here ? Even sophisticated users seem to run up against an incident where they have no idea what's wrong. It seems to me that leaves us all to inspect what details are available and make an educated guess as to the source of the problem.

But, if you meant that everybody should pursue the problem as far as they're able before posing it on the forum, then I agree.

 

Anything seems possible when you don't know what you're talking about.


   
DaveE reacted
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2037
 

Posted by: @tasan

 It now works as expected and I am controlling the LED strip with an ultrasonic sensor. Yay! 🙂

Well done 🙂

 

 


   
DaveE reacted
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1608
 

Hi @tasan,

re: is it bad practice to write LOW to the pin repeatedly like this, or does the Arduino do its own checks to avoid spamming the pin? I don't know if my thought here makes sense.

Should I use a resistor even though it works fine without?

  I would suggest it would be poor (as against 'bad') practice to be in a tight loop repreatedly writing the same thing, as it is making the processor continually do a useless set of instructions, consuming power and so on.

This is probably not of any concern in this case, but if power consumption and/or heat was a concern ... for instance in a battery powered situation, then it would a significant waste.

The Arduino, does exactly what you tell it to do ... it does not have any magic capabilities to do what you might have liked it to do -- luckily it does not get bored with even the most repetitive of tasks!

The resistor should not be needed for normal operation, as the Arduino pin, once it has processed the instructions to be an output pin, and to be set low, is capable of driving the gate to near zero volts. 

However, this implies that there is a time, between power being applied, whist the processor is executing all of the instructions needed to drive the pin low, when the voltage on the pin is undefined.

Thus it is quite possible, that you will see a flash or flicker of light when power is first applied. A resistor to pull the pin 'gently' down in the absence of high output level from the Arduino, should reduce this effect.

It is worth noting that although your visible code only consists of a few instructions, the Arduino IDE will insert a considerable number of initialisation instructions to be executed before calling your setup() function. These instructions, plus the reset delay during power up  cycle could amount to 1 second or so.

Also, I would recommend the first digitalWrite to an output pin should normally occur before the corresponding pinMode, so that the level on the pin is predetermined when it starts to drive current as an output pin. If the operations happen in a reverse order, the pin may produce a short unwanted pulse. In your case, this would be a flash of light, but in more complex systems, such as when the pin is controlling another machine, this could cause a serious event.

Best wishes for your projects .. good to see you moved forward with this one! Dave


   
ReplyQuote
TASan
(@tasan)
Member
Joined: 1 year ago
Posts: 46
Topic starter  

@will To be fair, I completely understand the sentiment. I think my post was just written in a rush, so I didn't get to express the ways I have approached the problem.

I have watched countless videos about voltage, current and resistance. I have also watched at least three videos on transistors, two about MOSFETS in particular. I have also watched at least ten videos about LED strips and several of them showing how to connect them and control them with an Arduino. It's hard to internalize the concepts, but i am getting there slowly.

But when it was my time to shine and to modify a sketch I found online, I must have done something wrong to make the MOSFET always on. And since I had followed what I had learned online I just got completely stumped and needed to ask here for help. And I'm glad I did! 😊

But back to the resistor. Say I get into the habit, and then want to put this contraption of mine in a pretty box. Hooking transistors and resistors up to a breadboard is no big deal, but are there any resources on how to do that out in the open so to speak? Like how do I practically fit an Arduino, three MOSFETS, three resistors, an ultrasonic distance sensor, and a PIR sensor into a neat package? Do i have to solder? Because I have never done that before.

Interested in learning about electrical engineering!


   
ReplyQuote
Page 1 / 2