Devices & Components
Arduino Uno Rev3
Resistor 221 ohm
Breadboard (generic)
LED (generic)
Jumper wires (generic)
IR Reciever (VS1838)
Software & Tools
Arduino IDE
Project description
Code
IR with LEDs Manual
arduino
In this code, you'll have to replace the value of the button you want to use for the "0xFD08F7" on row 29, as well as in row 32 and 35. With this code, once you press a button, an LED will turn on, and it won't turn off until you press the same button again. If you want them to turn off automatically after a certain amount of time, I left another code after this one.
1#include <IRremote.h> 2 3const int RECV_PIN = 7; 4IRrecv irrecv(RECV_PIN); 5decode_results results; 6 7#define led1 4 //Associates led1 al to pin 4 8#define led2 5 //Associates led2 al to pin 5 9#define led3 6 //Associates led3 al to pin 6 10boolean led1_est = false; //variable that stores the state of the led 11boolean led2_est = false; //variable that stores the state of the led 12boolean led3_est = false; //variable that stores the state of the led 13void setup() 14{ 15 Serial.begin(9600); //Initializes serial port 16 pinMode (led1, OUTPUT); //Establishes led1 as an output 17 pinMode (led2, OUTPUT); //Establishes led2 as an output 18 pinMode (led3, OUTPUT); //Establishes led3 as an output 19 20 irrecv.enableIRIn(); 21} 22 23void loop() 24{ 25 if (irrecv.decode(&results)) //If it recieves data 26 { 27 Serial.println(results.value, HEX); 28 irrecv.resume(); //Prepares to recieve next value 29 if (results.value == 0xFD08F7) led1_est = !led1_est; //Change here for the HEX value of your button 30 //If the recieved data matches the one stored, changes the state of led1 31 32 if (results.value == 0xFD8877) led2_est = !led2_est;//Change here for the HEX value of your button 33 //If the recieved data matches the one stored, changes the state of led2 34 35 if (results.value == 0xFD48B7) led3_est = !led3_est; //Change here for the HEX value of your button 36 //If the recieved data matches the one stored, changes the state of led3 37 38 else 39 { 40 Serial.println ("Invalid Code"); //If it doesnt match the stored values, it prints out "Invalid code" 41 } 42 } 43 digitalWrite(led1,led1_est); //Asigns led1 the state of "led1_est" 44 digitalWrite(led2,led2_est); //Asigns led2 the state of "led2_est" 45 digitalWrite(led3,led3_est); //Asigns led3 the state of "led3_est" 46 47} 48
IR with LEDs Auto
arduino
However, with this code, once you turn on an LED by pressing the button, it will automatically go off after 2000 miliseconds (you can change this in the code in row 25, 32, 39)
1#include <IRremote.h> 2 3const int RECV_PIN = 7; 4IRrecv irrecv(RECV_PIN); 5decode_results results; 6 7#define led1 4 //Associates led1 al to pin 4 8#define led2 5 //Associates led2 al to pin 5 9#define led3 6 //Associates led3 al to pin 6 10 11void setup(){ 12 irrecv.enableIRIn(); 13 14 pinMode(led1, OUTPUT); //Establishes led1 as an output 15 pinMode(led2, OUTPUT); //Establishes led2 as an output 16 pinMode(led3, OUTPUT); //Establishes led3 as an output 17} 18 19void loop(){ 20 if (irrecv.decode(&results)){ 21 22 switch(results.value){ 23 case 0xFD08F7: //Change here for the HEX value of your button 24 digitalWrite(led1, HIGH); 25 delay(2000); 26 digitalWrite(led1, LOW); 27 } 28 29 switch(results.value){ 30 case 0xFD8877: //Change here for the HEX value of your button 31 digitalWrite(led2, HIGH); 32 delay(2000); 33 digitalWrite(led2, LOW); 34 } 35 36 switch(results.value){ 37 case 0xFD48B7: //Change here for the HEX value of your button 38 digitalWrite(led3, HIGH); 39 delay(2000); 40 digitalWrite(led3, LOW); 41 } 42 43 44 irrecv.resume(); 45 } 46} 47
IR with LEDs Manual
arduino
In this code, you'll have to replace the value of the button you want to use for the "0xFD08F7" on row 29, as well as in row 32 and 35. With this code, once you press a button, an LED will turn on, and it won't turn off until you press the same button again. If you want them to turn off automatically after a certain amount of time, I left another code after this one.
1#include <IRremote.h> 2 3const int RECV_PIN = 7; 4IRrecv irrecv(RECV_PIN); 5decode_results results; 6 7#define led1 4 //Associates led1 al to pin 4 8#define led2 5 //Associates led2 al to pin 5 9#define led3 6 //Associates led3 al to pin 6 10boolean led1_est = false; //variable that stores the state of the led 11boolean led2_est = false; //variable that stores the state of the led 12boolean led3_est = false; //variable that stores the state of the led 13void setup() 14{ 15 Serial.begin(9600); //Initializes serial port 16 pinMode (led1, OUTPUT); //Establishes led1 as an output 17 pinMode (led2, OUTPUT); //Establishes led2 as an output 18 pinMode (led3, OUTPUT); //Establishes led3 as an output 19 20 irrecv.enableIRIn(); 21} 22 23void loop() 24{ 25 if (irrecv.decode(&results)) //If it recieves data 26 { 27 Serial.println(results.value, HEX); 28 irrecv.resume(); //Prepares to recieve next value 29 if (results.value == 0xFD08F7) led1_est = !led1_est; //Change here for the HEX value of your button 30 //If the recieved data matches the one stored, changes the state of led1 31 32 if (results.value == 0xFD8877) led2_est = !led2_est;//Change here for the HEX value of your button 33 //If the recieved data matches the one stored, changes the state of led2 34 35 if (results.value == 0xFD48B7) led3_est = !led3_est; //Change here for the HEX value of your button 36 //If the recieved data matches the one stored, changes the state of led3 37 38 else 39 { 40 Serial.println ("Invalid Code"); //If it doesnt match the stored values, it prints out "Invalid code" 41 } 42 } 43 digitalWrite(led1,led1_est); //Asigns led1 the state of "led1_est" 44 digitalWrite(led2,led2_est); //Asigns led2 the state of "led2_est" 45 digitalWrite(led3,led3_est); //Asigns led3 the state of "led3_est" 46 47} 48
Downloadable files
ir_with_leds_I2UyZGhOzz.fzz
ir_with_leds_I2UyZGhOzz.fzz
Schematics
Schematics

Schematics
Schematics

ir_with_leds_I2UyZGhOzz.fzz
ir_with_leds_I2UyZGhOzz.fzz
Comments
Only logged in users can leave comments