Creamms
Published © GPL3+

LED Control IRremote. h v3

Control a RGB LED with an IR Remote

BeginnerShowcase (no instructions)211
LED Control IRremote. h v3

Things used in this project

Story

Read more

Schematics

remote_controlled_rgb_led_7pDYxdN0IO.fzz

Code

Untitled file

Arduino
#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);
}

Credits

Creamms

Creamms

0 projects • 0 followers

Comments