Controlling LED 5 meter LED strip with IR input

Hello. As the subject states, I am trying to control a 5 meter RGB LED strip with infrared input from a remote. Right now, I have most of the code working. However, when I try to toggle the LED’s down to 10% brightness on any color except red, green or blue, the LED’s flicker like a candle. Can anybody help? To answer any hardware based inquires, I am using 3 MOSFETS, one for each color, I have the ground for the IR sensor, and the LED driver board connected and they are connected to the arduino.
The code is attached below: (I realize that it can be convoluted in some places,that it isn’t always consistent, and that there are large chunks commented out) Thank you in advance!

#include <IRremote.h>

// I/O pins for LED/Arduino connection
int REDPIN = 10;
int GREENPIN = 9;
int BLUEPIN = 6;
int RECV_PIN = 3;
int RELAYPIN = 13;

IRrecv irrecv(RECV_PIN);
decode_results results;
const int TIME = 12000;

// Remote control IR button values
const int POWER = 16712445;
const int RED = 16718565;
const int GREEN = 16751205;
const int BLUE = 16753245;
const int WHITE = 16720605;
const int PINK = 16734375;

const int UPBRIGHT = 16726725;
const int DOWNBRIGHT = 16759365;

const int FADESEVEN = 16769055;
const int FADETHREE = 16736415;
const int JUMPSEVEN = 16752735;
const int JUMPTHREE = 16720095;
const int FASTER = 16771095;
const int SLOWER = 16762935;


const int DIYONE = 16724175;
const int DIYTWO = 16756815;
const int DIYTHREE = 16740495;
const int DIYFOUR = 16716015;
const int DIYFIVE = 16748655;
const int DIYSIX = 16732335;

const int UPRED = 16722135;
const int DOWNRED = 16713975;
const int UPGREEN = 16754775;
const int DOWNGREEN = 16746615;
const int UPBLUE = 16738455;
const int DOWNBLUE = 16730295;

const int DOORONE = 16736925;
const int DOORTWO = 16745085;
const int DOORTHREE = 1784778242;

// LED Fade timer (Make higher to slow down)
int FADESPEED = 5; 

// LED States
boolean powerState = false;
int currentState;
int lastColor = WHITE;
boolean bright = true;
int brightness[3] = {230, 127, 0};
int brightnessCoef = 2;
int red[3] = {255,  0, 0};
int green[3] = {0, 255, 0};
int blue[3] = {0, 0, 255};
int white[3] = {255, 150, 200};
int pink[3] = {255, 0, 212};

int* currentColor = white;
int currentR;
int currentG;
int currentB;
/*boolean fadeSev = false;
boolean fadeThr = false;
boolean jumpSev = false;
boolean jumpThr = false;
*/


void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start Reciever
  pinMode(RELAYPIN, OUTPUT);
  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);
  pinMode(RECV_PIN, INPUT);
  
/*  for(int x = 0; x < 255; x++) {
  analogWrite(REDPIN, x);
delay(10);  
}
for (int x = 255; x > 0; x--)
{
  analogWrite(REDPIN, x);
delay(10);
}*/
  
  
}

void openDoor(){
  digitalWrite (RELAYPIN, HIGH); // relay conduction;
  delay (TIME);
    
  //digitalWrite (relay, LOW); // relay switch is turned off;
  //delay (time / 3);
    
  //digitalWrite (relay, HIGH); // relay conduction;
  //delay (time);
    
  digitalWrite (RELAYPIN, LOW); // relay switch is turned off;
  delay (TIME/6);
}
//Set the color of the LED's
void setColor(){
  currentR = map(brightness[brightnessCoef], 0, 255, 0, currentColor[0]);
  currentG = map(brightness[brightnessCoef], 0, 255, 0, currentColor[1]);
  currentB = map(brightness[brightnessCoef], 0, 255, 0, currentColor[2]);
  analogWrite(REDPIN, currentColor[0] - currentR);
  analogWrite(GREENPIN, currentColor[1] - currentG);
  analogWrite(BLUEPIN, currentColor[2] - currentB);
}

void loop(){
//Read the IR input and decode it to a result.
  if ((irrecv.decode(&results))){
    Serial.println(results.value, DEC);
    irrecv.resume(); // Receive the next value
  }
//Check the IR input against the power button.
  if(results.value == POWER || currentState == POWER){
    if(powerState == true){
      powerState = false;
      digitalWrite(REDPIN, LOW); 
      digitalWrite(GREENPIN, LOW);
      digitalWrite(BLUEPIN, LOW);
      
    }
    else {
      powerState = true;
      currentState = lastColor;
    }  
  }
  
//if the power is on, allow the lights to be controlled
  if(powerState == true){
    //check results against the brightness up and down buttons
    if(results.value == 16726725 && brightnessCoef < 2){
      brightnessCoef++;
    }
    else if(results.value == 16759365 && brightnessCoef > 0){
      brightnessCoef--;
    }
    // check results against button codes and change the lights accordingly.
    /*if(results.value == RED || currentState == RED){
        currentColor = red;
        lastColor = RED;
      }
    else if(results.value == GREEN || currentState == GREEN){
        currentColor = green;
        lastColor = GREEN;
    }
    else if(results.value == BLUE || currentState == BLUE){
        currentColor = blue;
        lastColor = BLUE;
    }
    else if(results.value == WHITE || currentState == WHITE){
        currentColor = white;
        lastColor = WHITE; 
    }
    else if(results.value == PINK || currentState == PINK){
      currentColor = pink;
      lastColor = PINK;
    }*/
    //RED
    if(results.value == 16718565){
        currentColor = red;
        lastColor = RED;
      }
      
    //GREEN
    else if(results.value == 16751205){
        currentColor = green;
        lastColor = GREEN;
    }
    
    //BLUE
    else if(results.value == 16753245){
        currentColor = blue;
        lastColor = BLUE;
    }
    
    //WHITE
    else if(results.value == 16720605){
        currentColor = white;
        lastColor = WHITE; 
    }
    
    //PINK
    else if(results.value == 16734375){
      currentColor = pink;
      lastColor = PINK;
    }
    setColor();
  }
  currentState = results.value;
  results.value = 0;

}

Hi and welcome,

Have you tried swapping the red with the green or blue Arduino output connection to the FETs, and swapping the connections from the FETs to the strip? If red remains steady and blue/green still flicker, this would point to a hardware rather than software problem. (My suspicion is a hardware problem, since red LEDs generally have a lower forward voltage than blue or green. Are they logic-level FETs?)

Please post links to the data sheets or whatever info you have on the strip and the FETs, and a schematic diagram (this can be hand drawn and scanned/photographed if you like).

Paul

Thanks!

Here is a datasheet for the mosfets I am using.

The LED's are just standard, non-addressable waterproof LED strips similar to these:

They have a common cathode and are then the RGB wires are connected to the pins of the arduino through a driver board which follows a schematic my roommate found online. The schematic is at the following URL:

The only change we made was we put our resistors on the left pin for all 3 instead of the middle pin for two and then the left pin for red.

We are also encountering a problem with the whole system hanging when we use brightness down on a common ground through the driver board, but it works perfectly, minus the flickering, when run through a breadboard. Do you have any ideas for that?

Thank you so much.

Hi, as I suspected, you are not using logic-level FETs. Most of the time you are getting away with it, but in certain situations, the FETs are not fully switching on and not giving enough output voltage to reliably light the blue and green LEDs. You are still getting away with it for the red LEDs because they have a lower forward voltage, i.e. they switch on at a slightly lower voltage than the green/blue.

The easiest fix may be to swap your FETs for some logic-level equivalents. They often have an "L" in their part codes, but to be sure, check the data sheet for the "Gate Threshold Voltage" figure. Logic-level FETs will have a maximum threshold of around 2V or less. Your IRF510 have a maximum of 4V, by comparison.

Another way would be to use some intermediary transistors between the Arduino outputs and the FET gates.

Paul

Thanks! I'll get some logic level MOSFETs and try them out!

Thank you so much for your time!

BR0THB3RG:
The schematic is at the following URL:
http://goo.gl/qTXba6

Can’t see a schematic there. Did you mean the Fritzing picture?

BR0THB3RG:
The only change we made was we put our resistors on the left pin for all 3 instead of the middle pin for two and then the left pin for red.

Sorry, don’t understand.

BR0THB3RG:
… the whole system hanging when we use brightness down on a common ground through the driver board…

Nope, can’t understand that either. Maybe I’m just tired!

Breadboards, I’ve been told, have a naturally higher capacitance than a PCB or stripboard, because of their construction. Maybe that has something to do with it.

Yeah, my roommate followed the fritzing picture. In the picture, it shows a resistor on the middle pin of the green mosfet and the blue mosfet. Instead of putting the resistor there, he mirrored the configuration for the red mosfet in that picture. I hope that's a little easier to understand.

The problem is that when the IR sensor is plugged directly into the board and we press the brightness down button on the remote, everything stops working. The sensor starts reading in random values and random time intervals and no longer reads in the commands from the remote. It doesn't start working again until we reset the arduino.

As for logic level MOSFETs, are RFP30N06LE from sparkfun what you were referring to? Sorry, I'm pretty new to this.

BR0THB3RG:
In the picture, it shows a resistor on the middle pin of the green mosfet and the blue mosfet. Instead of putting the resistor there, he mirrored the configuration for the red mosfet in that picture.

Oh, I see now. Yes, either the red or both blue and green FET connections must be wrong. We can't say which without knowing what FET the author of those diagrams was using. Different models of FEt will have Gate/Source/Drain on different pins.

BR0THB3RG:
The problem is that when the IR sensor is plugged directly into the board and we press the brightness down button on the remote, everything stops working. The sensor starts reading in random values and random time intervals and no longer reads in the commands from the remote. It doesn't start working again until we reset the arduino.

No idea without more info, part numbers, schematics and sketch (which you already posted).

BR0THB3RG:
As for logic level MOSFETs, are RFP30N06LE from sparkfun what you were referring to?

Yes, that's more like it. There are lots of logic-level FET models available.

Hey! Sorry, I took so long, I've been busy with school and stuff.

My Logic level MOSFETs arrived and they didn't solve the flickering problem. The lights still flicker when writing low brightness levels to the LEDs, but still only when using a combination of the RGB leds. When writing low brightness values to just red or green or blue, there is no flicker. Any other ideas?

Sorry that the logic level FETs did not fix the problem. Using non logic level FETs with logic citcuits is a frequent cause of problems.

Suggest next step is to narrow problem down to hardware vs software. Start a new sketch and put the absolute minimum lines in it to reproduce the problems. Just enough to set the outputs for one of the colour/brightness values that demonetrates the flickering problem. Cut out everything else, all the IR stuff and so on.