Using MOSFETs with RGBW striplights

Hi I'm looking for some advice. I'm typing to build a IR controlled RGBW striplights controller and I'm having an issue running multiple colours. My code works fine with LEDs but when I connect some striplights via some MOSFETs that I have it only works for individual RGBW colours. If I try for say yellow, being red and green at full brightness the two colours barely come on. Any advice would be greatly appreciated.

You will only get guesswork without providing a wiring diagram.

What voltage is the strip designed for? How much current to they draw? Does your power supply have enough power?

@mpulham1, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with your project :wink: See About the Installation & Troubleshooting category.

Please explain to the forum why anyone should take their time to help you. On your previous visit you posted a question, got 2 responses and then... nothing for 3 years!

Just waiting for a wiring diagram...

Hi aarg, below is a copy of the wiring layout and my sketch so far. My project is to build a new controller for some existing shelf lighting with the intention to add in some relay outputs for additional light and sound. I'm using the supplied 12vdc 2amp power supply and some MTP3055E N-CHANNEL MOSFETs that I had in the shed as per the wiring diagram, I've used 10k resistors to ground on the MOSFETs. I'm only using a short offcut of LED strip for this test. As I said in my original post everything works fine if I'm only turning on one colour at a time or if I'm only using small LEDs direct from the Arduino. I'm guessing that there is a power drain by using the MOSFETs that the power supply I'm using can't handle but this is beyond my knowledge. Once again any advice would be greatly appreciated.

#include <IRremote.h>
int IRpin=7;
IRrecv irrecv(IRpin);
decode_results cmd;
String myCom;

int rPin=5;
int gPin=6;
int bPin=9;
int wPin=10;

int rBright=255;
int gBright=255;
int bBright=255;
int wBright=255;

float dFact=1;

void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn();

pinMode(rPin,OUTPUT);
pinMode(gPin,OUTPUT);
pinMode(bPin,OUTPUT);
pinMode(wPin,OUTPUT);

}

void loop() {
  while (irrecv.decode(&cmd)==0){
  
}
delay(500);
irrecv.resume();

if (cmd.value==0xF700FF){
  myCom="up";
  Serial.println(myCom);
}
if (cmd.value==0xF7807F){
  myCom="dn";
  Serial.println(myCom);
}
if (cmd.value==0xF740BF){
  myCom="off";
  Serial.println(myCom);
}
if (cmd.value==0xF7C03F){
  myCom="on";
  Serial.println(myCom);
}

if (cmd.value==0xF720DF){
  myCom="c1";
  Serial.println(myCom);
}
if (cmd.value==0xF7A05F){
  myCom="c2";
  Serial.println(myCom);
}
if (cmd.value==0xF7609F){
  myCom="c3";
  Serial.println(myCom);
}

if (cmd.value==0xF710EF){
  myCom="c4";
  Serial.println(myCom);
}
if (cmd.value==0xF7906F){
  myCom="c5";
  Serial.println(myCom);
}
if (cmd.value==0xF750AF){
  myCom="c6";
  Serial.println(myCom);
}

if (cmd.value==0xF730CF){
  myCom="c7";
  Serial.println(myCom);
}
if (cmd.value==0xF7B04F){
  myCom="c8";
  Serial.println(myCom);
}
if (cmd.value==0xF7708F){
  myCom="c9";
  Serial.println(myCom);
}

if (cmd.value==0xF708F7){
  myCom="c10";
  Serial.println(myCom);
}
if (cmd.value==0xF78877){
  myCom="c11";
  Serial.println(myCom);
}
if (cmd.value==0xF748B7){
  myCom="c12";
  Serial.println(myCom);
}

if (cmd.value==0xF728D7){
  myCom="c13";
  Serial.println(myCom);
}
if (cmd.value==0xF7A857){
  myCom="c14";
  Serial.println(myCom);
}
if (cmd.value==0xF76897){
  myCom="c15";
  Serial.println(myCom);
}
if (cmd.value==0xF7E01F){
  myCom="c16";
  Serial.println(myCom);
}

if (myCom=="on"){
  rBright=0;
  gBright=0;
  bBright=0;
  wBright=255;
  dFact=1;
}

if (myCom=="off"){
  rBright=0;
  gBright=0;
  bBright=0;
  wBright=0;
  dFact=0;
}

if (myCom=="c1"){
  rBright=255;
  gBright=0;
  bBright=0;
  wBright=0;
}

if (myCom=="c2"){
  rBright=0;
  gBright=255;
  bBright=0;
  wBright=0;
}

if (myCom=="c3"){
  rBright=0;
  gBright=0;
  bBright=255;
  wBright=0;
}

if (myCom=="c4"){
  rBright=0;
  gBright=0;
  bBright=0;
  wBright=0;
}
if (myCom=="c5"){
  rBright=0;
  gBright=0;
  bBright=0;
  wBright=0;
}
if (myCom=="c6"){
  rBright=0;
  gBright=0;
  bBright=0;
  wBright=0;
}
if (myCom=="c7"){
  rBright=0;
  gBright=0;
  bBright=0;
  wBright=0;
}
if (myCom=="c8"){
  rBright=0;
  gBright=0;
  bBright=0;
  wBright=0;
}
if (myCom=="c9"){
  rBright=0;
  gBright=0;
  bBright=0;
  wBright=0;
}
if (myCom=="c10"){
  rBright=0;
  gBright=0;
  bBright=0;
  wBright=0;
}
if (myCom=="c11"){
  rBright=0;
  gBright=0;
  bBright=0;
  wBright=0;
}
if (myCom=="c12"){
  rBright=0;
  gBright=0;
  bBright=0;
  wBright=0;
}
if (myCom=="c13"){
  rBright=255;
  gBright=255;
  bBright=0;
  wBright=0;
}
if (myCom=="c14"){
  rBright=0;
  gBright=0;
  bBright=0;
  wBright=0;
}
if (myCom=="c15"){
  rBright=0;
  gBright=0;
  bBright=0;
  wBright=0;
}
if (myCom=="c16"){
  rBright=0;
  gBright=0;
  bBright=0;
  wBright=255;
}

if (myCom=="dn"){
  dFact=dFact*.75;
}

if (myCom=="up"){
  dFact=dFact*1.3;
  if (dFact>1){
    dFact=1;
  }
}




analogWrite(rPin,rBright*dFact);
analogWrite(gPin,gBright*dFact);
analogWrite(bPin,bBright*dFact);
analogWrite(wPin,wBright*dFact);


}

Please read the instructions for posting and specifically how to post code. Also how to format it for posting - and in fact for the ability to read it easily.

Also look up the "case" statement to tidy up your chains of "if"s or consider some arrays which could be searched easily.

Why do you use the indirection of string tokens, i.e. the 'myCom="c14"' etc., why not just act on the IR hex code directly? It would cut your program size almost in half. I don't see any alternate use of them, other than a print out, which you could also do directly from the place where you detect a hex code.

if (cmd.value==0xF708F7){
myCom="c10";
Serial.println(myCom);
}
...
if (myCom=="c10"){
rBright=0;
gBright=0;
bBright=0;
wBright=0;
}

could just be

if (cmd.value==0xF708F7){
Serial.println("c10");
rBright=0;
gBright=0;
bBright=0;
wBright=0;
}

The MOSFET you are using will require about 10 volts at the gate in order to get the FET into full conduction. The 3055 FET is not a good device for this purpose. I'd recommend a IRF620 for this purpose. The 12 volt rail for your LED strips should be an isolated power source from the power you are using to power the board. The 12 volt rail will connect directly to the Anode or positive connection on the LED strips. The cathode or negative connection on the strip will connect to the Drain on the FET and the source pin will be tired directly to the 12 volt return.

Your gate drive is far from being ideal. It looks like you have a 1K pullup resistor between the gate and the 12 volts. When the digital pin goes low, you are now sinking 12 ma through that pin. But when the pin goes high, 5 volts I am assuming, you now have a very complex voltage divider of 5 volts at the intersection of the gate and resistor and 12 volts on the other side of the resistor. The gate in this case will never reach a potential that will drive the FET into full conduction.

I would recommend adding in a common 2N3904 transistor as a gate driver. The emitter of the transistor connected to the gate on the FET, then Collector tied to the 12 volt rail and the base of the transistor connected to the digital pin through a 470 ohm resistor. When the digital pin goes high, the transistor is saturated and applies the 12 volts to the gate of the FET driving it into full conduction. When the pin is low, the transistor is cutoff and the gate is at a high impedance state and cuts off the FET.

Hi Jeff, welcome to the forum. Can you check @mpulham1 's diagram again to see if your advice needs amending? Otherwise could be very confusing four them.

PaukBBm What needs amending? I would recommend a 10K pullup in this configuration, but form what I can see on the diagram that resistor is Brown-Black-Red, 1000 Ohms. The configuration as wired will work, but for any current draw greater than 350 ma your are going to get too much of a voltage drop across the Drain-Source junction with the specified transistor.

Which is also a 10volt mosfet.
The logic-level range usually has an "L" in the number, like IRLxxxx

I only see a resistor between Arduino pin and ground, which has nothing to do with the fet.
The resistor is there to stop the pin (gate) from floating during bootup of the Arduino.
Leo..

Well, it's hard to be certain about resistor colours on Fritzing diagrams. Different monitors might show slightly different colours. This is one of the reasons we ask beginners to post proper schematics. Beginners don't understand what a schematic is and frequently believe what they posted is a schematic.

But to me those resistors look reasonably clearly like brown black orange, which would be the 10K you recommended. I think it's also reasonably clear they are connected to ground, not 12V. Except for the middle MOSFET, where the resistor is not connected to either, which is just a careless mistake, I think, and was intended to be connected to ground.

Beginners often don't follow the normal wire colour conventions entirely, and that is true here. Red has been used conventionaly for +12V but has also been used unconventionally for wiring the MOSFET driving the red channel. Black has been used for ground almost consistently, except for the wire connecting the common anode of the strip to 12V, which should have been red for consistency.

What problem did you see with the model of MOSFET? You sound more of an expert in transistors than I am, but I did look at the data sheet and the gate threshold voltage was typically less than 3V, so an Arduino pin should switch it on sufficiently well with ~2V above that threshold, shouldn't it?

Logic level mosfets have a typical threshold of 1-2volt, not 2-4volt.
But you should look at the 'on' resistance at 4.5volt (if mentioned), to be sure.
Leo..

Thanks for all the advice and constructive criticism. It appears that I briefly had the project working which leads me to think the at least part of my problems are caused by poor connections. I've ordered solder type breadboard which will solve the connection problem and I've also ordered some IRLZ44N FETs. These are the ones used in one of the project I've found online that I'm basing my project on. I will also take the advice given on how to simplify my code, what I've posted is very much a work in progress but your points have been heard. As for the resistor size I did state it earlier but I can confirm that the ones I've used are 10k. Once again thank you all for your help. I'll let you know how I go once the new parts arrive.

1 Like

Yes, Schematics are essential. I will agree that sometimes my monitor is not color balanced at D6500 white!! The MTP3055 MOSFET is a terrible device, old and is far from being recommended for any new designs. When using MOSFET in designs, especially digital and driving LED's, one need to be concerned with gate drive and the Drain-Source ON resistance Rdson. In the case of the 3055 I believe it's worst case Rdson is 0.7 ohms. If you are drawing only a few milliamps, that is not a big deal, but if your LED string is pulling 3 amps, that is a 2.1V drop across that Drain-Source junction. If the LED rail is 5 Volts, that's only a 2.9 volt level driving the LED's and you will not get full brightness from the string. Ohms law is your friend here. This is why when selecting a MOSFET for a project you want the lowest Rdson you can find that will support your rail voltage, gate drive, current draw and physical foot print. The IRLZ44N is a pretty good device and it's Rdson when used at 5 volt gate drive is 0.022 ohms and is good for 110 watts of dissipation.

1 Like

You still didn't fix that post where you didn't use code tags. Please do that, it only takes a moment.

You might think about using a "struct":

struct Command {
  unsigned long irCode;
  char codeName[4];
  byte r, g, b, w;
};

struct Command commands[] = {
  { 0xF720DF, "c1", 255,   0,   0,   0 },
  { 0xF7A05F, "c2",   0, 255,   0,   0 },
  ...
};

const byte commandCount = sizeof(commands) / sizeof(commands[0]);

...

byte c = 0;
while ( c < commandCount && cmd.value != commands[c].irCode) c++;
if(c < commandCount) {
  Serial.println(commands[c].codeName);
  rBright = commands[c].r;
  gBright = commands[c].g;
  bBright = commands[c].b;
  wBright = commands[c].w;
};

Something like that (all written on phone, not tested!)

Commendable determination! :astonished: