LED Control IRremote. h v3

Control a RGB LED with an IR Remote

projectImage

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.

projectImage

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

The article was first published in hackster, September 25, 2021

cr: https://www.hackster.io/Creamms/led-control-irremote-h-v3-5126c5

author: Creamms

License
All Rights
Reserved
licensBg
0