RGB LED with Remote Control

RGB LED with Remote Control

Introduction

This experiment demonstrates how to control the color of an RGB LED using an IR remote control and an IR receiver with Arduino.

RGB LED

Components Needed

Circuit Setup

  1. Connect the red, green, and blue pins of the RGB LED to digital pins on the Arduino (e.g., 9, 10, 11).
  2. Connect the anode of the RGB LED to the 5V pin of the Arduino and use 220-ohm resistors for each color pin.
  3. Connect the IR receiver's signal pin to a digital pin on the Arduino (e.g., D2).

Make sure the IR receiver is properly positioned to receive signals from the remote.

RGB LED Circuit Setup

Code for RGB LED with Remote Control

Upload the following code to your Arduino to control the RGB LED with the IR remote:


#include 

const int recv_pin = 2;
IRrecv irrecv(recv_pin);
decode_results results;

int redPin = 9;
int greenPin = 10;
int bluePin = 11;

void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn();
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
}

void loop() {
  if (irrecv.decode(&results)) {
    long int decCode = results.value;
    Serial.println(decCode);
    if (decCode == 0xFF30CF) {
      digitalWrite(redPin, HIGH);
      digitalWrite(greenPin, LOW);
      digitalWrite(bluePin, LOW);
    } else if (decCode == 0xFF18E7) {
      digitalWrite(redPin, LOW);
      digitalWrite(greenPin, HIGH);
      digitalWrite(bluePin, LOW);
    } else if (decCode == 0xFF7A85) {
      digitalWrite(redPin, LOW);
      digitalWrite(greenPin, LOW);
      digitalWrite(bluePin, HIGH);
    }
    irrecv.resume();
  }
}
            

Explanation

The code uses the IRremote library to read signals from the remote control. Each button press corresponds to a different color setting for the RGB LED.

Troubleshooting