Components and supplies
2
LED (generic)
1
Breadboard (generic)
1
IR Remote
2
Resistor 220 ohm
1
Jumper wires (generic)
1
Arduino UNO
1
IR receiver (generic)
Project description
Code
Code
arduino
Comments
Only logged in users can leave comments
Components and supplies
LED (generic)
Breadboard (generic)
IR Remote
Resistor 220 ohm
Jumper wires (generic)
Arduino UNO
IR receiver (generic)
Project description
Code
Code
arduino
1/* 2 3 This sketch reads the value from an IR Remote, decodes it and turns 4 on or off two LEDs accordingly. 5 6 This program is made by Shreyas for Electronics Champ YouTube Channel. 7 Please subscribe to this channel. Thank You. 8 9*/ 10 11// Including the library 12#include <IRremote.h> 13 14// Define IR Receiver's output pin 15IRrecv irrecv(3); 16 17// Decoded results are saved in 'data' variable 18decode_results data; 19 20bool state1 = 0; 21bool state2 = 0; 22int led1 = 8; 23int led2 = 9; 24 25// Assign the HEX number obtained from your IR Remote here 26#define btn1 0x0 27#define btn2 0x0 28 29void setup() { 30 31 // Define the pins as output 32 pinMode(led1, OUTPUT); 33 pinMode(led2, OUTPUT); 34 35 //Start Serial Communication 36 Serial.begin(9600); 37 38 // Configure the timer and the state machine for IR reception 39 irrecv.enableIRIn(); 40} 41 42void loop() { 43 44 if (irrecv.decode(&data)) { //If the sensor detects a signal 45 46 //Prints a decoded value (This value is different for each button on the remote) 47 Serial.print("0x"); 48 Serial.println(data.value, HEX); 49 delay(1000); 50 irrecv.resume(); 51 52 if (data.value == btn1) { 53 54 //Toggles the boolean value 55 state1 = !state1; 56 digitalWrite(led1, state1); 57 58 /* 59 These lines prevent the receiver 60 from reading the same value twice 61 */ 62 irrecv.disableIRIn(); 63 delay(500); 64 irrecv.enableIRIn(); 65 66 } 67 68 else if (data.value == btn2) { 69 70 //Toggles the boolean value 71 state2 = !state2; 72 digitalWrite(led2, state2); 73 74 /* 75 These lines prevent the receiver 76 from reading the same value twice 77 */ 78 irrecv.disableIRIn(); 79 delay(500); 80 irrecv.enableIRIn(); 81 82 } 83 } 84} 85
Comments
Only logged in users can leave comments