SWITCH LED BY REMOTE

Remote LED

#include <IRremote.h>

int RECV_PIN = 3; // the pin where you connect the output pin of TSOP4838

int led1 = 2;

int led2 = 4;

int led3 = 7;

int itsONled[] = {0,0,0,0};

/* the initial state of LEDs is OFF (zero)

the first zero must remain zero but you can

change the others to 1’s if you want a certain

led to light when the board is powered */

#define code1 552656927 // code received from button A

#define code2 552600317 // code received from button B

#define code3 552624287 // code received from button C

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()

{

Serial.begin(9600); // you can comment this line

irrecv.enableIRIn(); // Start the receiver

pinMode(led1, OUTPUT);

pinMode(led2, OUTPUT);

pinMode(led3, OUTPUT);

}

void loop() {

if (irrecv.decode(&results)) {

unsigned int value = results.value;

switch(value) {

case code1:

if(itsONled[1] == 1) { // if first led is on then

digitalWrite(led1, LOW); // turn it off when button is pressed

itsONled[1] = 0; // and set its state as off

} else { // else if first led is off

digitalWrite(led1, HIGH); // turn it on when the button is pressed

itsONled[1] = 1; // and set its state as on

}

break;

case code2:

if(itsONled[2] == 1) {

digitalWrite(led2, LOW);

itsONled[2] = 0;

} else {

digitalWrite(led2, HIGH);

itsONled[2] = 1;

}

break;

case code3:

if(itsONled[3] == 1) {

digitalWrite(led3, LOW);

itsONled[3] = 0;

} else {

digitalWrite(led3, HIGH);

itsONled[3] = 1;

}

break;

}

Serial.println(value); // you can comment this line

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

}

}

OTHER SKET

#include <IRremote.h>

int RECV_PIN = 3; // the pin where you connect the output pin of TSOP4838

int led1 = 2;

int led2 = 4;

int led3 = 7;

int itsONled[] = {0,0,0,0};

/* the initial state of LEDs is OFF (zero)

the first zero must remain zero but you can

change the others to 1’s if you want a certain

led to light when the board is powered */

#define code1 552656927 // code received from button A

#define code2 552600317 // code received from button B

#define code3 552624287 // code received from button C

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()

{

Serial.begin(9600); // you can comment this line

irrecv.enableIRIn(); // Start the receiver

pinMode(led1, OUTPUT);

pinMode(led2, OUTPUT);

pinMode(led3, OUTPUT);

}

void loop() {

if (irrecv.decode(&results)) {

unsigned int value = results.value;

switch(value) {

case code1:

digitalWrite(led1, HIGH);

digitalWrite(led2, LOW);

digitalWrite(led3, LOW); // turn it off when button is pressed

break;

case code2:

digitalWrite(led1, LOW);

digitalWrite(led2, HIGH);

digitalWrite(led3, LOW);

break;

case code3:

digitalWrite(led1, LOW);

digitalWrite(led2, LOW);

digitalWrite(led3, HIGH);

break;

}

Serial.println(value); // you can comment this line

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

}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s