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.
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.