Devices & Components
Arduino Uno Rev3
IR receiver (generic)
Relay (generic)
Jumper wires (generic)
Project description
Code
Code snippet #1
text
1#include <IRremote.h> 2int relayPin = 2; 3int irPin = 7; 4IRrecv irRecive(irPin); 5decode_results results; 6 7void setup() { 8 Serial.begin(9600); 9 irRecive.enableIRIn(); 10 pinMode(relayPin, OUTPUT); 11} 12 13void loop() { 14 15 if (irRecive.decode(&results)) { 16 17 Serial.print("Received value = "); 18 Serial.println(results.value); 19 Serial.print("Received code = "); 20 Serial.println(results.decode_type); 21 Serial.print("Received bits = "); 22 Serial.println(results.bits); 23 24 switch (results.value) { 25 case 16754775: 26 Serial.println("LIGHTS ON"); 27 digitalWrite(relayPin, HIGH); 28 break; 29 30 case 16769055: 31 Serial.println("LIGHTS OFF"); 32 digitalWrite(relayPin, LOW); 33 break; 34 35 default: 36 Serial.println("case: default"); 37 delay(1000); 38 } 39 40 irRecive.resume(); 41 } 42 43} 44
Code snippet #2
text
1#include <IRremote.h> 2int relayPin = 2; 3int irPin = 7; 4IRrecv irRecive(irPin); 5decode_results results; 6 7void setup() { 8 Serial.begin(9600); 9 irRecive.enableIRIn(); 10 pinMode(relayPin, OUTPUT); 11} 12 13void loop() { 14 15 if (irRecive.decode(&results)) { 16 17 Serial.print("Received value = "); 18 Serial.println(results.value); 19 Serial.print("Received code = "); 20 Serial.println(results.decode_type); 21 Serial.print("Received bits = "); 22 Serial.println(results.bits); 23 24 switch (results.value) { 25 case 16754775: 26 Serial.println("LIGHTS ON"); 27 digitalWrite(relayPin, HIGH); 28 break; 29 30 case 16769055: 31 Serial.println("LIGHTS OFF"); 32 digitalWrite(relayPin, LOW); 33 break; 34 35 default: 36 Serial.println("case: default"); 37 delay(1000); 38 } 39 40 irRecive.resume(); 41 } 42 43} 44
Code snippet #1
text
1#include <IRremote.h> 2int relayPin = 2; 3int irPin = 7; 4IRrecv irRecive(irPin); 5decode_results results; 6 7void setup() { 8 Serial.begin(9600); 9 irRecive.enableIRIn(); 10 pinMode(relayPin, OUTPUT); 11} 12 13void loop() { 14 15 if (irRecive.decode(&results)) { 16 17 Serial.print("Received value = "); 18 Serial.println(results.value); 19 Serial.print("Received code = "); 20 Serial.println(results.decode_type); 21 Serial.print("Received bits = "); 22 Serial.println(results.bits); 23 24 switch (results.value) { 25 case 16754775: 26 Serial.println("LIGHTS ON"); 27 digitalWrite(relayPin, HIGH); 28 break; 29 30 case 16769055: 31 Serial.println("LIGHTS OFF"); 32 digitalWrite(relayPin, LOW); 33 break; 34 35 default: 36 Serial.println("case: default"); 37 delay(1000); 38 } 39 40 irRecive.resume(); 41 } 42 43} 44
Downloadable files
Circuit
Circuit

Circuit
Circuit

Comments
Only logged in users can leave comments