Control a RGB LED with an IR Remote

Things used in this project
Hardware components
HARDWARE LIST
1 RGB LED
1 Arduino UNO
1 IR remote and receiver
Story
I couldn't find a super basic program to learn the IRremote v3. All tutorials I found used (receiver.decode(&results)) which is now not used.

Schematics
remote_controlled_rgb_led_7pDYxdN0IO.fzz
Code
Untitled file
CODE
#include <IRremote.h> // include the IRremote library
#define IR_RECEIVE_PIN 2
long data = 0;
int redPin = 9; //select the pin for the red LED
int bluePin = 10; // select the pin for the blue LED
int greenPin = 11; // select the pin for the green LED
void setup() {
Serial.begin(9600); // begin serial communication with a baud rate of 9600
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
pinMode(redPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop() {
if (IrReceiver.decode()) {
if (IrReceiver.decodedIRData.decodedRawData != 0) {
data = IrReceiver.decodedIRData.decodedRawData;
}
switch (data) { // compare the value to the following cases
case 3910598400:
Serial.println("1, Red");
setLed(255, 0, 0);
break ;
case 3860463360:
Serial.println("2, Orange");
setLed(255, 128, 0);
break ;
case 4061003520:
Serial.println("3, Yellow");
setLed(255, 255, 0);
break;
case 4077715200:
Serial.println("4, Green");
setLed(0, 255, 0);
break ;
case 3877175040:
Serial.println("5, Blue");
setLed(0, 0, 255);
break ;
case 2707357440:
Serial.println("6, Intigo");
setLed(127, 0, 255);
break ;
case 4144561920:
Serial.println("7, Violet");
setLed(255, 0, 255);
break ;
}
IrReceiver.resume();
}
}
void setLed(int r, int g, int b)
{
analogWrite(redPin, r); analogWrite(greenPin, g); analogWrite(bluePin, b);
}
License 
All Rights
Reserved

0
More from this category