SWITCH LIGHT BY REMOTE

ir remote switch

#include <IRremote.h>
int RECV_PIN = 12;
IRrecv irrecv(RECV_PIN);
decode_results results;
int ledPin1 = 10;
int ledPin2 = 9;
int ledPin3 = 8;
int ledPin4 = 7;

int index = -1; // to indicate which led should be turned on
void setup() {
Serial.begin(9600);
Serial.print(“Sketch: “); Serial.println(__FILE__);
Serial.print(“Uploaded: “); Serial.println(__DATE__);
Serial.print(“Time Uploaded: “); Serial.println(__TIME__);
Serial.println(” “);
irrecv.enableIRIn(); // Start the receiver
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
}
unsigned long last = millis();
void loop() {

if (irrecv.decode(&results)) {
if (results.value == 0xEF1001FE) {
// the button is pushed
// turn off the LED which is on now
if(index != -1){ // if index is not the initial value
switch (index){
case 0:
digitalWrite(ledPin1, LOW); // turn the LED off (LOW is the voltage level)
delay(50);
break;
case 1:
digitalWrite(ledPin2, LOW);
delay(50);
break;
case 2:
digitalWrite(ledPin3, LOW);
delay(50);
break;
case 3:
digitalWrite(ledPin4, LOW);
delay(50);
break;

}
}

// turn on the next LED
index ++;
index = index % 5;
switch (index){
case 0:
digitalWrite(ledPin1, HIGH); // turn the LED on (HIGH is the voltage level)
delay(250);
break;
case 1:
digitalWrite(ledPin2, HIGH);
delay(250);
break;
case 2:
digitalWrite(ledPin3, HIGH);
delay(250);
break;
case 3:
digitalWrite(ledPin4, HIGH);
delay(250);
break;
case 4:
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
delay(250);
break;

}
}

irrecv.resume(); // Receive the next value
}

}

============OTHER SKET==================================

#include <IRremote.h>
int RECV_PIN = 12;
IRrecv irrecv(RECV_PIN);
decode_results results;
int ledPin1 = 10;
int ledPin2 = 9;
int ledPin3 = 8;
int ledPin4 = 7;

int index = -1; // to indicate which led should be turned on
void setup() {
Serial.begin(9600);
Serial.print(“Sketch: “); Serial.println(__FILE__);
Serial.print(“Uploaded: “); Serial.println(__DATE__);
Serial.print(“Time Uploaded: “); Serial.println(__TIME__);
Serial.println(” “);
irrecv.enableIRIn(); // Start the receiver
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
}
unsigned long last = millis();
void loop() {

if (irrecv.decode(&results)) {
if (results.value == 0xEF1001FE) {
// the button is pushed
// turn off the LED which is on now
if(index != -1){ // if index is not the initial value
switch (index){
case 0:
digitalWrite(ledPin1, LOW); // turn the LED off (LOW is the voltage level)
delay(50);
break;
case 1:
digitalWrite(ledPin2, LOW);
delay(50);
break;
case 2:
digitalWrite(ledPin3, LOW);
delay(50);
break;
case 3:
digitalWrite(ledPin4, LOW);
delay(50);
break;

}
}

// turn on the next LED
index ++;
index = index % 5;
switch (index){
case 0:
digitalWrite(ledPin1, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
delay(250);
break;
case 1:
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
delay(250);
break;
case 2:
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
delay(250);
break;
case 3:
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, HIGH);
delay(250);
break;
case 4:
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
delay(250);
break;

}
}

irrecv.resume(); // Receive the next value
}

}

========================OTHER SKET=================================

#include <IRremote.h>
int RECV_PIN = 12;
IRrecv irrecv(RECV_PIN);
decode_results results;
int ledPin1 = 10;
int ledPin2 = 9;
int ledPin3 = 8;
int ledPin4 = 7;

int index = -1; // to indicate which led should be turned on
void setup() {
Serial.begin(9600);
Serial.print(“Sketch: “); Serial.println(__FILE__);
Serial.print(“Uploaded: “); Serial.println(__DATE__);
Serial.print(“Time Uploaded: “); Serial.println(__TIME__);
Serial.println(” “);
irrecv.enableIRIn(); // Start the receiver
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
}
unsigned long last = millis();
void loop() {

if (irrecv.decode(&results)) {
if (results.value == 0xEF1020DF) {

// turn off the LED which is on now
if(index != -1){ // if index is not the initial value
switch (index){
case 0:
digitalWrite(ledPin1, LOW); // turn the LED off (LOW is the voltage level)
delay(50);
break;
case 1:
digitalWrite(ledPin2, LOW);
delay(50);
break;
case 2:
digitalWrite(ledPin3, LOW);
delay(50);
break;
case 3:
digitalWrite(ledPin4, LOW);
delay(50);
break;

}
}

// turn on the next LED
index++;
index = index % 5;
switch (index){
case 0:
digitalWrite(ledPin1, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
delay(250);
break;
case 1:
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
delay(250);
break;
case 2:
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
delay(250);
break;
case 3:
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, HIGH);
delay(250);
break;
case 4:
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
delay(250);
break;

}
}
else if (results.value == 0xEF10A05F) {

// turn off the LED which is on now
if(index != -1){ // if index is not the initial value
switch (index){
case 0:
digitalWrite(ledPin1, LOW); // turn the LED off (LOW is the voltage level)
delay(50);
break;
case 1:
digitalWrite(ledPin2, LOW);
delay(50);
break;
case 2:
digitalWrite(ledPin3, LOW);
delay(50);
break;
case 3:
digitalWrite(ledPin4, LOW);
delay(50);
break;

}
}

// turn on the next LED
index–;
index = index % 5;

switch (index){
case 0:
digitalWrite(ledPin1, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
delay(250);
break;
case 1:
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
delay(250);
break;
case 2:
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
delay(250);
break;
case 3:
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, HIGH);
delay(250);
break;
case 4:
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
delay(250);
break;

}
}
irrecv.resume(); // Receive the next value
}

}