IR Receiver Arduino

In this Project, we will see about how to interface IR Receiver TSOP 1838 with Arduino.

Circuit Diagram:


Arduino Code:
simple_led_control_code.ino
//This Code is Developed by Sdev
//Follow Us Here : https://youtube.com/sdevelectronics

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  Serial.println("Enabling IRin");
  irrecv.enableIRIn(); // Start the receiver
  Serial.println("Enabled IRin");

  pinMode(3, OUTPUT);
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);

    if (results.value == 0x80BF21DE) {  //on
      digitalWrite(3, HIGH);
    }
    if (results.value == 0x80BF916E) {  //OFF
      digitalWrite(3, LOW);
    }
    irrecv.resume(); // Receive the next value
  }
  delay(100);
}

rgb_led_control_code.ino
//This Code is Developed by Sdev
//Follow Us Here : https://youtube.com/sdevelectronics

#include <IRremote.h>

#define RED 9
#define GREEN 10
#define BLUE 11

int RECV_PIN = 8;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  Serial.begin(9600);
  Serial.println("Enabling IRin");
  irrecv.enableIRIn();
  Serial.println("Enabled IRin");

  pinMode(3, OUTPUT);
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);

    if (results.value == 0x80BF916E) {  //RED
      analogWrite(RED, 255);
      analogWrite(GREEN, 0);
      analogWrite(BLUE, 0);
    }
    if (results.value == 0x80BF21DE) {  //GREEN
      analogWrite(RED, 0);
      analogWrite(GREEN, 255);
      analogWrite(BLUE, 0);
    }

    if (results.value == 0x80BF9B64) {  //YELLOW
      analogWrite(RED, 128);
      analogWrite(GREEN, 128);
      analogWrite(BLUE, 0);
    }

    if (results.value == 0x80BF6996) {  //BLUE
      analogWrite(RED, 0);
      analogWrite(GREEN, 0);
      analogWrite(BLUE, 255);
    }
    if (results.value == 0x80BF3BC4) {  //OFF
      analogWrite(RED, 0);
      analogWrite(GREEN, 0);
      analogWrite(BLUE, 0);
    }
    irrecv.resume(); // Receive the next value
  }
  delay(100);
}

Libraries Used:

Youtube Video Tutorial:




Download our official Android App in PlayStore. Click Here
You can get the all the required files (like Circuit Diagram, Arduino.ino file, Libraries Used, and others) for the project  in ZIP format and much more...

No comments:

Post a Comment