InfraRed/RBG LED problem

Hi, I just want to make a RBG LED light up with various colors using an IR remote, but as soon as I press a button once, everything else stops working, I need to press the reset button on my arduino UNO to make it work again, here is my code:

#include <IRremote.h>
const int IR_PIN = 2;
IRrecv irrecv(IR_PIN);

const int ledPinRed = 11;
const int ledPinGreen = 10;
const int ledPinBlue = 9;

const int buttonPin = 4;

int buttonState = 0;

void setup() {
irrecv.enableIRIn();
pinMode(ledPinRed, OUTPUT);
pinMode(ledPinGreen, OUTPUT);
pinMode(ledPinBlue, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}

void loop() {
buttonState = digitalRead(buttonPin);

  if (buttonState == LOW){
    analogWrite(ledPinRed, 0);
    analogWrite(ledPinGreen, 0);
    analogWrite(ledPinBlue, 0);
  }
irrecv.decode();
switch(irrecv.decodedIRData.decodedRawData) {
    
case 0xB946FF00:    // VOL+
// mettre ici le code à exécuter
analogWrite(ledPinRed, 255);
analogWrite(ledPinGreen, 0);
analogWrite(ledPinBlue, 0);
break;
    
case 0xEA15FF00:    // VOL -
// mettre ici le code à exécuter
analogWrite(ledPinRed, 60);
analogWrite(ledPinGreen, 140);
analogWrite(ledPinBlue, 250);
break;

case 0xBC43FF00:    // FLÈCHE DROITE
// mettre ici le code à exécuter

break;

case 0xBB44FF00:    // FLÈCHE GAUCHE
// mettre ici le code à exécuter

break;

case 0xBF40FF00:    // PAUSE
// mettre ici le code à exécuter

break;

default:
break;
} 
irrecv.resume();
delay(15); 
}

Did you forget to use current limiting resistors for each of the R, G and B LEDs?

well, usually I don't use any and it works fine

If you were lucky, the I/O pins on the MCU were not destroyed. But they have surely been damaged, and perhaps other parts as well.

the I/O pins? and what is the MCU?

The Arduino processor is an MCU, MicroController Unit.

ok, but I will test with resistors to each LED pins

Did you put a resistor on the push button as well?
You know that delicate components like the arduino don't like a really high current going trough their I/O pins.

I think everytime you press a button you short the arduino, luckily, the arduino has short circuit protections so you didn't really destroy anything, just put resistors trought the led and the button and it should be fine.

well, thats the thing, INPUT_PULLUP solves that, but its not when I press the button that it crashes, its after I press a button on my IR remote

No, it does not. There are separate, strict limitations on the current that can be drawn from any pin, and on the sum of currents to or from all of the pins.

It is safe to draw 20 mA from one I/O pin, on an Arduino Uno, Mega, etc., but much less on some other types of Arduinos.

ok so, I put resistor, and it still does not fix the problem unfortunately

wait a sec, I changed the wrong variables

INPUT_PULLUP just makes sure that it doesn't get static signals from the air, you need a current limiting resistor from the button to the I/O pin.

Not if you use INPUT_PULLUP, with the switch wired to GND.

Please brush up on circuit basics, before posting bad advice.

1 Like

Without a schematic it's hard to understand how he wired the button,
I tought the button was connected from vcc to the I/O pin, and that "INPUT_PULLUP" was only to ensure that he can't get static signals from air or by touching the circuit.

From what I understand now, he wired the button from the I/O pin to GND, and INPUT_PULLUP is just to have an HIGH signal always read from the pin, and when you push the button it discharges on ground giving a "LOW" signal, it's just an unusual way to wire a simple button.

Ask for a circuit diagram instead, then make a (hopefully) well-informed suggestion.

sure, but there's no need for that arsh response.

This is a technical forum. Posters with questions have a right to expect technically correct, useful answers.

1 Like

There is a need for a response, as noted. The response was not harsh. Do not be offended by good information, be thankful. Always be learning.

You're right, next time I'm going to be sure I've understood the topic, and assuring a right and good response, have all a good day.