0% found this document useful (0 votes)
52 views2 pages

4 Led Control Code

This code defines an infrared remote control receiver connected to an Arduino board that controls 4 LEDs. It initializes pin connections for the receiver and LEDs. It defines codes for 4 buttons and uses a switch statement to toggle the state of the corresponding LED when each button code is received, turning it on or off.

Uploaded by

shauryakakkar19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views2 pages

4 Led Control Code

This code defines an infrared remote control receiver connected to an Arduino board that controls 4 LEDs. It initializes pin connections for the receiver and LEDs. It defines codes for 4 buttons and uses a switch statement to toggle the state of the corresponding LED when each button code is received, turning it on or off.

Uploaded by

shauryakakkar19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <IRremote.

h>

int RECV_PIN = 10; // Connect your IR reciever to this pin


int led1 = 5;
int led2 = 6;
int led3 = 7;
int led4 = 8;
int itsONled[] = {0,1,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 33 // Code revieved from your 1st button
#define code2 16417 // Code revieved from your 2nd button
#define code3 8225 // Code revieved from your 3rd button
#define code4 24609 // Code recieved from your 4th button

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
Serial.begin(9600); // you can ommit this line
irrecv.enableIRIn(); // Start the receiver
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, 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;
case code4:
if(itsONled[4] == 1) {
digitalWrite(led4, LOW);
itsONled[4] = 0;
} else {
digitalWrite(led4, HIGH);
itsONled[4] = 1;
}
break;
}
Serial.println(value); // you can ommit this line
irrecv.resume(); // Receive the next value
}
}

You might also like