How To Control LED With IR Remote And Arduino UNO|Topped With Fun|Basic Arduino UNO Project With LED
Circuit Diagram:
IR Decoder:-
#include <IRremote.h>
int IRpin = 2;
IRrecv irrecv(IRpin);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
if (irrecv.decode(&results))
{
Serial.println(results.value, DEC); // Print the Serial ‘results.value’
irrecv.resume(); // Receive the next value
}
}
IR Conroller:-
#include <IRremote.h> //Includes IR Library
int RECV_PIN = 2; //IR Receiver Pin
IRrecv irrecv(RECV_PIN);
decode_results results;
#define BUTTON_1 0x1 //Paste Code Of 1st Button
#define BUTTON_2 0x2 //Paste Code Of 2nd Button
#define BUTTON_3 0x3 //Paste Code Of 3rd Button
#define BUTTON_0 0x33 //Paste Code Of 4th Button
#define BUTTON_OK 0x35 //Paste Code Of 5th Button
int blue_LED = 7;
int red_LED = 6;
int green_LED = 5;
void setup()
{
pinMode(blue_LED, OUTPUT);
pinMode(red_LED, OUTPUT);
pinMode(green_LED, OUTPUT);
irrecv.enableIRIn();
}
void loop() {
if (irrecv.decode(&results))
{
if (results.value == BUTTON_0)
{
digitalWrite(blue_LED, LOW);
digitalWrite(red_LED, LOW);
digitalWrite(green_LED, LOW);
}
if (results.value == BUTTON_OK)
{
digitalWrite(blue_LED, HIGH);
digitalWrite(red_LED, HIGH);
digitalWrite(green_LED, HIGH);
}
if (results.value == BUTTON_1)
{
digitalWrite(blue_LED, HIGH);
}
if (results.value == BUTTON_2)
{
digitalWrite(red_LED, HIGH);
}
if (results.value == BUTTON_3)
{
digitalWrite(green_LED, HIGH);
}
irrecv.resume();
}
}
Comments
Post a Comment