LED Strip stops working with IR stuff

Hello, a newbie here. So I have a couple of problems that have been killing me for hours now and Im desperate. You see, I managed to connect my Arduino to my LED Strip (12V). I set up a program, where I can change the brightness of each color (rgb) depending on Serial Communication. With a button I attached, I could change it to the next color. So I put a number into Serial, and it would modify the brightness on my LED Strip, to make all sorts of colors. Okay I got that program working nice and swiftly, and I decided it would be cooler to incorporate an IR receiver so that instead of typing on Serial, I could just put the number on my IR remote, and the brightness would change. So when I was working on that, I tested it a couple of times to make sure I was doing everything correctly. Then I discovered the RED on my LED strip has suddenly stopped Working. I change to green and it works great, I change it to blue, works great. But Red doesn't work, and the weird part is that It does work If I put 255 as brightness. but anything below that, it basically makes it 0. I know that must sound pretty confusing. Then I started tinkering around with some of my code. And I realized erasing one line of code solves everything.

Im using 12V LEDS and IRFZ44N MOSFETS if it somehow helps.

Here's my code.

#include <LiquidCrystal_I2C.h>
#include <IRremote.h>

#define BLUE_LED 9
#define RED_LED 11
#define GREEN_LED 10
#define CHANGE_BUTTON 2

#define IR_PIN 5



// Starts up Liquid Crystal
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Button debounce variables
unsigned long lastButtonChange = millis();
unsigned long debounceDelay = 60;
byte buttonState = LOW;

// Variable that gives current Color the Serial is changing
int currentColor = 1;

// Arrays for IR buttons
const byte buttonCode[10] = { 74, 22, 12, 24, 94, 8, 28, 90, 66, 82 };
const byte digit[10] = { 9, 0, 1, 2, 3, 4, 5, 6, 7, 8 };

// Button for enter
const byte hash = 64;  // #  <-----<<<<<  use a button and it's code from your remote

//To get number
unsigned int myNumber;

// ************************************************************************************************************************************************
// ****************************************************************** Color LEDS ******************************************************************
// Function to change current color selected brightness
void colorCurrentColor(int value) {
  switch (currentColor) {
    case 1:
      {
        analogWrite(RED_LED, value);
        break;
      }
    case 2:
      {
        analogWrite(GREEN_LED, value);
        break;
      }
    case 0:
      {
        analogWrite(BLUE_LED, value);
        break;
      }
  }
}  // END of colorCurrentColor()

// **************************************************************************************************************************************************
// ****************************************************************** COLOR ON LCD ******************************************************************
// Function for LCD
void setCurrentColorOnLCD() {

  // Clearing top half
  for (int i = 0; i < 16; i++) {
    lcd.setCursor(i, 0);
    lcd.print(" ");
  }

  switch (currentColor) {
    case 1:
      {
        lcd.setCursor(0, 0);
        lcd.print("Current: RED");
        break;
      }
    case 2:
      {
        lcd.setCursor(0, 0);
        lcd.print("Current: GREEN");
        break;
      }
    case 3:
      {
        lcd.setCursor(0, 0);
        lcd.print("Current: BLUE");
        break;
      }
  }
}  // END of setCurrentColorOnLCD()

// *************************************************************************************************************************************************
// ****************************************************************** Initial LCD ******************************************************************
// Little menu for when you start up the program
void initialLCDScreen() {
  // TOP PART
  lcd.setCursor(0, 0);
  lcd.print("Current: RED");

  //BOTTOM PART
  lcd.setCursor(0, 1);
  lcd.print("R0   G0   B0  ");
}  // END of intialLCDScreen()

// ************************************************************************************************************************************************
// ****************************************************************** RGB ON LCD ******************************************************************
// Prints out the rgb values on the LCD screen
void rgbValuesOnLCD(int value) {
  switch (currentColor) {
    case 1:
      {
        for (int i = 1; i < 5; i++) {
          lcd.setCursor(i, 1);
          lcd.print(" ");
        }

        lcd.setCursor(1, 1);
        lcd.print(value);
        break;
      }
    case 2:
      {
        for (int i = 6; i < 10; i++) {
          lcd.setCursor(i, 1);
          lcd.print(" ");
        }
        lcd.setCursor(6, 1);
        lcd.print(value);
        break;
      }

    case 0:
      {
        for (int i = 11; i < 16; i++) {
          lcd.setCursor(i, 1);
          lcd.print(" ");
        }
        lcd.setCursor(11, 1);
        lcd.print(value);
        break;
      }
  }
}  // End of rgbValuesOnLCD()

// **************************************************************************************************************************************************
// ****************************************************************** CHECK IR CODE *****************************************************************
// Checks What value IR remote comes up with
void checkIRcode() {
  //**************************************
  for (byte x = 0; x < 10; x++) {
    //***************
    if (IrReceiver.decodedIRData.command == buttonCode[x]) {
      Serial.print("Button = ");
      Serial.print(digit[x]);

      myNumber = myNumber * 10 + digit[x];

      break;
    }
  }

  Serial.println("");

  //***************
  if (IrReceiver.decodedIRData.command == hash) {
    Serial.print("My number = ");
    Serial.println(myNumber);
    Serial.println("");
    rgbValuesOnLCD(myNumber);
    colorCurrentColor(myNumber);
    myNumber = 0;
  }

  //needed to block repeat codes
  IrReceiver.decodedIRData.command = 0;

}  //END of   checkIRcode()

// *******************************************************************************************************************************************
// ****************************************************************** SETUP ******************************************************************
void setup() {
  // Serial Functions
  Serial.begin(115200);
  Serial.setTimeout(50);

  //LCD intilize
  lcd.init();
  lcd.backlight();

  // Pins to add
  pinMode(CHANGE_BUTTON, INPUT);
  pinMode(BLUE_LED, OUTPUT);
  pinMode(RED_LED, OUTPUT);
  pinMode(GREEN_LED, OUTPUT);

  initialLCDScreen();

  //Starts IR remote
  IrReceiver.begin(IR_PIN); // <----- Erasing this fixes it

}  // END of  setup()

// ******************************************************************************************************************************************
// ****************************************************************** LOOP ******************************************************************
void loop() {

  // Button Debounce
  unsigned long timeNow = millis();
  if (timeNow - lastButtonChange > debounceDelay) {
    lastButtonChange = timeNow;
    byte newButtonState = digitalRead(CHANGE_BUTTON);
    if (buttonState != newButtonState) {
      buttonState = newButtonState;

      if (buttonState == HIGH) {
        currentColor += 1;
        setCurrentColorOnLCD();
        if (currentColor == 3) {
          currentColor = 0;
        }
      }
    }
  }

  // Check Serial Info
  if (Serial.available() > 0) {
    int data = Serial.parseInt();
    if (data > 255) {
      data = 255;
    } else if (data < 0) {
      data = 0;
    }
    colorCurrentColor(data);
    rgbValuesOnLCD(data);
  }

  // IR Receiver
  if (IrReceiver.decode()) {
    //Enable receiving of the next value
    IrReceiver.resume();
  }

  //have we received a new IR code form the remote ?
  if (IrReceiver.decodedIRData.command != 0) {
    checkIRcode();
  }
}  //END of   loop()

The particular line of code im talking about is in setup(). Line 197.

Hope someone can help me, thanks.

I have an Uno ,but I've been using it with no problems at all. I'll change it to see if it fixes the problem.

I changed it to Digital Pin 3 and it still doesn't work. I even searched online and it says 3 is a PMW pin so I dont think that's the problem. Maybe it's something in my code.

How are these connected to the Uno?

If the voltage on the gate is only 5V from the Arduino pin, they may not switch on.

You will need to use a driver circuit to get a higher voltage on the gate, or replace with a logic-level MOSFET like IRLZ44.

I have an external 12V power source.

I have no idea what a driver circuit is haha, but I managed to get it working by watching a YT tutorial. I learned doing it wrong could actually fry my Arduino, but I've powered on the lights many times and left them on for a while and it doesn't fry it.

I don't think you understand, my code and my Circuit does work, at least until I add IR stuff to the code.

Once I removed all the IR related content in my code it would go back to working normally. And after many experiments I realized that...

This line of code is the root of all my problems. As soon as I erase it, everything goes back to working normally.

I don't know If I can attach video on here but If I can it would be very useful.

Yes, you are correct. Read this:

You can't use Uno pins 3 or 11 for analogWrite() when using this library. You can use pins 5, 6, 9, 10.

1 Like

ooohhh that makes a lot of sense, thank you so much

A driver circuit would increase the voltage of the PWM signal from the Uno pin, allowing the IRFZ44N to switch on fully.

The gate threshold voltage of IRFZ44N can be up to 4V, so the 5V PWM signal from the Uno is only just enough to switch on the IRFZ44N at all. It's on-resistance may be quite high like this, causing overheating and a voltage drop which might prevent your LEDs from lighting or reduce their brightness.

The simplest driver circuit would probably be to pull the IRFZ44N's gate up to 12V with a resistor (eg. 10K) and use any ordinary npn transistor to pull the gate down to ground. Another resistor would also be needed to limit the current into the npn base pin, e.g. 4K7.

A simple driver circuit like this would increase the PWM signal to 12V at the MOSFET's gate but it would be inverted, so that analogWrite(pin, 255) would switch the LEDs off and analogWrite(pin, 0) would be max brightness.

Ohhh okay thank you. Do you maybe have the circuit to that, or an image or something so I can try it out. Thanks!

haha its fine, I solved the issue already, thank you either way.

Thank you very much! Can I Just ask what "ESP O/P" is?

In the schematic I found, the microcontroller was an esp8266 or ESP32, but the circuit would also work for an Arduino. So "ESP O/P" means the output pin of the arduino.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.