Thursday, April 21, 2016

Turn ON-OFF electric appliances using any IR remote control

By this Arduino project you can run any electric devices (AC and DC) by using any IR remote control in your home. (remote control of TV, satellite, air conditioner, etc)
Since each IR remote control button have certain frequency, so you have to determine that and put that in the code.
 

You have to follow this steps:

1-connect your relay module (or LEDs) and infrared receiver module to your Arduino board as shown in following figures

Turn ON-OFF electric appliances using any IR remote control

Turn ON-OFF electric appliances using any IR remote control


Turn ON-OFF electric appliances using any IR remote control

Turn ON-OFF electric appliances using any IR remote control

2-then upload the code (in below of this page) to your Arduino board and open the serial monitor

Turn ON-OFF electric appliances using any IR remote control


3-then press any button of your remote control (put the remote toward the IR receiver)

Turn ON-OFF electric appliances using any IR remote control


4- put the number that appears in serial monitor (in prior step) in your code and repeat this work for each buttons then upload the code again

Turn ON-OFF electric appliances using any IR remote control
 5-Now it is ready to use as you can see in following video, when you press the button key, the load that connected to that pin turn ON and by other press it be turn OFF.


Note: you have to add IRremote.h file to your Arduino library, Download it from here



#include <IRremote.h>

int RECV_PIN = 2; // the pin where you connect the output pin of TSOP4838
int led1 = 13;
int led2 = 12;
int led3 = 11;
int led4 = 10;
int led5 = 9;
int led6 = 8;
int led7 = 7;
int led8 = 6;
int led9 = 5;
int led10 = 4;
int itsONled[] = {0,0,0,0,0,0,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  4590 // code received from button 1
#define code2  12750 // code received from button 2
#define code3  2550 // code received from button 3
#define code4  10710 // code received from button 4
#define code5  6630 // code received from button 5
#define code6  24735 // code received from button 6
#define code7  57375 // code received from button 7
#define code8  4335 // code received from button 8
#define code9  36975 // code received from button 9
#define code10  19125 // code received from button 0

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);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led7, OUTPUT);
  pinMode(led8, OUTPUT);
  pinMode(led9, OUTPUT);
  pinMode(led10, 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;
       case code5:
         if(itsONled[5] == 1) {
            digitalWrite(led5, LOW);
            itsONled[5] = 0;
         } else {
             digitalWrite(led5, HIGH);
             itsONled[5] = 1;
         }
         break;
       case code6:
         if(itsONled[6] == 1) {
            digitalWrite(led6, LOW);
            itsONled[6] = 0;
         } else {
             digitalWrite(led6, HIGH);
             itsONled[6] = 1;
         }
         break;
       case code7:
         if(itsONled[7] == 1) {
            digitalWrite(led7, LOW);
            itsONled[7] = 0;
         } else {
             digitalWrite(led7, HIGH);
             itsONled[7] = 1;
         }
         break;
       case code8:
         if(itsONled[8] == 1) {
            digitalWrite(led8, LOW);
            itsONled[8] = 0;
         } else {
             digitalWrite(led8, HIGH);
             itsONled[8] = 1;
         }
         break;
       case code9:
         if(itsONled[9] == 1) {
            digitalWrite(led9, LOW);
            itsONled[9] = 0;
         } else {
             digitalWrite(led9, HIGH);
             itsONled[9] = 1;
         }
         break;
       case code10:
         if(itsONled[10] == 1) {
            digitalWrite(led10, LOW);
            itsONled[10] = 0;
         } else {
             digitalWrite(led10, HIGH);
             itsONled[10] = 1;
         }
          break;         
    }
    Serial.println(value); // you can comment this line
    irrecv.resume(); // Receive the next value
  }
}