Hello all, I am having a problem with my MKR Zero, I am using it cycle a 12v LED strip on and off using a MOSFET. I've used the 'Fading' and 'BlinkWithoutLoop' example scripts (only changing the pin) and run into the same problem. The program runs fine for a couple of minutes and then the LED turns off, the cycle stops, the power LED on the board goes dim. Using a multimeter I measure around 1.5V on the 5V pin, so the board clearly does not have enough power to drive the MOSFET.
I'm using USB power supply to the Arduino (via my laptop, and also tried a full USB battery bank). The LED strip and driver have no issues when I connect them directly without the Arduino.
The MOSFET I'm using is this one, and I'm using a 100k resistor between Pin 2 and Ground. I've also tried adding a 220 Ohm resistor between the pin and MOSFET Gate, but I get the same issue.
This is my code, the only thing I've changed from the example script is the pin and added a couple of lines to print to console.
// constants won't change. Used here to set a pin number:
const int ledPin = 2;// the number of the LED pin
// Variables will change:
int ledState = LOW; // ledState used to set the LED
// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0; // will store last time LED was updated
// constants won't change:
const long interval = 1000; // interval at which to blink (milliseconds)
void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
}
void loop() {
// here is where you'd put code that needs to be running all the time.
// check to see if it's time to blink the LED; that is, if the difference
// between the current time and last time you blinked the LED is bigger than
// the interval at which you want to blink the LED.
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
Serial.print(ledState);
Serial.println();
}
}
Any help would be much appreciated. I've searched and found similar issues, but without solutions. Just to be clear, the system works totally fine for a couple of minutes, and then stops. So I'm (reasonably) confident I haven't made any egregious wiring errors, but I don't think it would be the code as it's essentially an example script. I'm stumped.
Do you have your ground wires connected to the arduino ground as well? You do not show the explicitly in your diagram. It is required so all components have a common reference.
lastchancename: I'm not quite sure what you mean by 'whole arrangement', there are no other components involved. I've re-drawn the diagram and tried to make it a little clearer.
I did try using a 220 Ohm resistor to the arduino pin. The result was no different. Do you think I should try a different resistor value?
If there's another arrangement for the MOSFET, I'm willing to try it, but I don't have the electronic experience to design an alternative circuit myself.
I honestly can’t see an issue at first glance.
Is the Zero running 5V or 3V3 on the pins ?
Maybe 3V3 isn’t enough to turn on the FET .
Also just a hint for future schematics, consider drawing it with signalflow from left-to-right, and voltages from positive at the top, to negative at the bottom as a convention. People will be able to follow it much faster, especially on more complex circuits.
Symbols rather than component ‘outlines’ are also more typical in schematics, but you’re forgiven with such a simple circuit !
The logical step is to try a common LED/resistor (220 ohm) on that pin, and connect the board ONLY to USB.
No fet, no LED strip, no LED driver.
That fet seems to have a high gate charge.
I would use that 220 ohm resistor between pin and gate,
and 10k (not 100k) from pin (not gate) to ground.
Not that relevant with the on/off switching you do now, but extra security when you start with PWM dimming.
Leo..
10/100k, not much difference here, but 10k could be preferred if long-ish wires are involved.
It's function is to keep the gate firmly at source (ground) potential during bootup.
Gate capacitance of that fet is rather high.
With 500Hz PWM, that 'cap' is charged/discharged 1000 times per second.
Every time the pin sees a short circuit to VCC or GND for a short period of time.
That resistor makes sure pin current stays below the chip's absolute max pin current.
Some say it doesn't matter, but would you try for 10 cents. Read this page.
Leo..