I am trying to hook 12V RGB Led Strip (LTROP SMD 5050 RGB LED Light Strip) to a NodeMCU unit. I know there are many different tutorials on this and I am very new to wiring and electric circuits.
I used BUZ91A n-MOSFETs and 150 Ohm resistors for each of the RGB channels, and the board is using it's own power supply via usb.
I use very simple code to check if the setup works:
#define REDPIN D3
#define GREENPIN D1
#define BLUEPIN D2
#define FADESPEED 5 // make this higher to slow down
void setup() {
pinMode(REDPIN, OUTPUT);
pinMode(GREENPIN, OUTPUT);
pinMode(BLUEPIN, OUTPUT);
Serial.begin(115200);
Serial.println("Finished setup");
}
void loop() {
analogWrite(REDPIN, 800);
analogWrite(BLUEPIN, 1020);
analogWrite(GREENPIN, 400);
delay(100);
Serial.println("Finished loop");
}
I suspect nothing works because NodeMCU and the LED are using different power sources and the fact they have common ground doesn't seem to be everything required.
1 Answer 1
So now we finally know the reason is MOSFET's threshold voltage is too high. The solution is to drive the gate with NPN transistor (you can use BC547 or 2N5551 or similar). You have to connect it's collector to 5 V and it's emitter to GND. Put 10k or 100k resistor between 5 V and the collector, connect the collector to MOSFET's gate and GPIO to the base of NPN transistor. Put some resistor between GPIO and the base of the transistor, maybe 4k7 or similar.
Note:
HIGH from GPIO will switch off the LED strip and LOW will switch it on.
Another solution is to use MOSFET with lower threshold voltage.
EDIT:
If you want to avoid adding NPN transistor you can use NTD5867NL MOSFET which has max threshold voltage 2.5 V so it will for sure work with 3.3 V at the gate but is rather expensive (about 4ドル). Much better solution is adding cheap NPN transistor.
EDIT:
Here is the schematic:
schematic
simulate this circuit – Schematic created using CircuitLab
EDIT:
Here is the correct wiring:
enter image description here
-
Can you please advise on a fitting MOSFET model to use?abolotnov– abolotnov12/13/2016 08:01:53Commented Dec 13, 2016 at 8:01
-
I'll take a look through some other MOSFETs and write you a note if I find the one which might work.Chupo_cro– Chupo_cro12/13/2016 08:15:09Commented Dec 13, 2016 at 8:15
-
I've edited the answer and added the data about MOSFET which will for sure work with 3.3 V.Chupo_cro– Chupo_cro12/13/2016 08:31:11Commented Dec 13, 2016 at 8:31
-
Thank you so much for following through on this problem with me. I wanted to ask one last question. Are there any sort of Led Strip Driver Boards I could just purchase and wire to my nodeMCU? I suck at all this wiring and circuits (you can tell) and the further I go the better I understand I'd rather stick to the programming side of things. Also, I am trying to finish by project on time for someone's Christmas gift. Again, thanks a lot for your kind help.abolotnov– abolotnov12/13/2016 15:13:35Commented Dec 13, 2016 at 15:13
-
1Here you are the wiring diagram. You can use the same 12 V which you are using to power the LED strip instead of 5 V to avoid using 3 different voltages. But, as you are probably getting 3.3 V from 5 V then it isn't a problem if you use 5 V. Of course, a MOSFET must be n-channel and not as in the picture.Chupo_cro– Chupo_cro12/17/2016 08:54:03Commented Dec 17, 2016 at 8:54
analogWrite()
again and again in the loop, it is enough to do that only once insetup()
but that isn't the problem.digitalWrite()
on D1, D2 and D3 (one by one) to see if these outputs are really associated with the pins where you connected the PWM outputs (just don't forget the current limiting resistor, max source current is 12 mA and max sink current is 20 mA). And you might first try to change the PWM frequency, for example try withanalogWriteFreq(200);
. The default PWM frequency is 1 kHz and that should work but nothing to loose if you try.