Arduino ir receiver tutorial
Below is the code for the arduino ir receiver:
this code is the actual project for the ir receiver |
/*
* Made by DIYrobots * April 2019 */ #include <IRremote.h> #define led 6 #define RECV_PIN 7 #define turnon 3772784863 // these are my codes for the TV remote #define turnoff 3772817503 // and your TV remote might (and respectively probably will) have different values. IRrecv irrecv(RECV_PIN); decode_results results; void setup() { pinMode(led,OUTPUT); irrecv.enableIRIn(); } void loop() { if(irrecv.decode(&results)){ if(results.value == turnon){ digitalWrite(led,HIGH); } else if(results.value == turnoff){ digitalWrite(led,LOW); } delay(100); irrecv.resume(); } } |
this is the irrecvdemo code that comes with the irremote library |
#include <IRremote.h>
int RECV_PIN = 11; IRrecv irrecv(RECV_PIN); decode_results results; void setup() { Serial.begin(9600); // In case the interrupt driver crashes on setup, give a clue // to the user what's going on. Serial.println("Enabling IRin"); irrecv.enableIRIn(); // Start the receiver Serial.println("Enabled IRin"); } void loop() { if (irrecv.decode(&results)) { Serial.println(results.value, HEX); irrecv.resume(); // Receive the next value } delay(100); } |
what the code does:
The project code checks foe any infrared signals from your TV remote and if they are equal to any of the values stored in the variables, then the Arduino either turns on or turns off an LED connected to digital pin 6.