Home Automation using NEC IR Remote

From engineersgarage Friday, June 30, 2017

This is a home automation project using an NEC IR remote to control appliances. In this project a car stereo remote or a general DVD remote or any remote control using NEC key coding format will be used to control switching electrical and electronics appliances. This project is a demonstration of a simple home automation application where the user can switch remote appliances ON or OFF with a handheld IR remote. In the project, four bulbs will be switched ON or OFF using any regular NEC IR remote.

Using an NEC IR remote has the advantage that its receiver needs only one pin of microcontroller to interface and control signal for large number of devices can be sent using NEC encoding scheme on a single microcontroller pin. The NEC format for remote controls is quite popular in India and one of such remote can be easily purchased anywhere at minimal cost of 14 – 16 rupees ($0.205-$0.235). The IR remotes are obviously wireless and easily available too.

Home Automation using NEC IR Remote

The project is built on Arduino UNO and any AC appliance operating at 220V – 240V 50Hz AC supply can be interfaced and controlled by the project. The Arduino UNO is the programmable unit and implements the embedded program to facilitate automation. The Arduino IDE is used to write the program code for decoding NEC signal and accordingly generate digital output to control the relays switching appliances ON or OFF. The program code is burnt to the board using AVR Dude.

COMPONENTS REQUIRED

• Arduino UNO

• NEC IR remote

• TSOP 1738 sensor

• 16×2 LCD

• 12v Relay

• BC 547 transistor

• 1K ohm resisters -7

• Voltage regulator -7805

• LED -5mm RED- 2

• Wire to carry 2A,230v AC

• Two pin Plug

• Three pin holder

• Bulb holder-4pcs

• 220v-240v AC bulb

Arduino IR Remote Controlled Home Automation Project Block Diagram

CIRCUIT CONNECTIONS

The circuit is based on Arduino UNO. The different sections of the circuit will be interfaced with the Arduino board. The circuit will have the following sections – :

Power Supply – The power to the circuit will be supplied by 18V-24V battery. The Arduino board, LCD display and TSOP 1738 IR sensor need 5V supply while the relays will need 12V DC supply. The supply from the battery will be regulated to 5V and 12V using 7805 and 7812 ICs. The pin 1 of both the voltage regulator ICs will be connected to the anode of the battery and pin 2 of both ICs will be connected to ground. The respective voltage outputs will be drawn from pin 3 of the respective voltage regulator ICs.

TSOP 1738 IR Sensor – The TSOP 1738 IR sensor will be used to receive the data from the NEC IR remote. The sensor has three terminals of which pin 1 will be connected to 5V VCC and pin 2 will be connected to the ground. The digital output from the sensor will be received from pin 3 which will be connected to the pin 11 of Arduino board.

16X2 LCD – The 16X2 LCD display will be used to display the increment or decrement of motor speed. It is connected to the Arduino board by connecting its data pins to pins 3 to 6 of the Arduino board. The RS and E pins of the LCD are connected to pins 13 and 12 of the Arduino UNO respectively. The RW pin of the LCD is grounded.

Home Automation using NEC IR Remote

The standard open-source library for interfacing LCD with Arduino UNO is used in the project. The library works as expected and needs no changes or modifications.

Relays – The 12V 2A relays are used to switch the AC appliances ON or OFF in the project. The relays are connected to the pins 7, 8, 9 and 10 of Arduino board via BS547 transistor circuits connected in a common emitter configuration. The phase wire from the AC supply is provided at the COM terminal of the relays. When a HIGH logic is received at the interfaced microcontroller pins, the COM point switches from NC to NO point where a relay short-circuits the phase with the neutral wire switching the supply to the appliance ON.

NEC IR remote – A regular NEC IR remote is used in the circuit. The Power button and keys ONE, TWO, THREE and FOUR of the IR remote will be used for the following functions -:

Arduino IR Remote Controlled Home Automation Project

How the Project Works

When the project is powered on, initial messages are flashed on the LCD display and the microcontroller is set ready to read IR keys decoded by the TSOP 1738 IR sensor. A LOW logic is passed to the microcontroller pins connecting the relays therefore keeping the appliances switched OFF by default.

The NEC IR remote used in the project sends 28-bit long encoded IR keys. NEC IR remote uses a transmission protocol known as pulse distance encoding of the message bits, where each message packet is 562.5us in length and the 38KHz carrier frequency is about 26.3us in length. Logical “0” consists of burst pulses of 562.5us and followed by a 562.5us space. So the total time is 1.125ms while Logical “1” consists of burst pulses of 562.5us and followed by a 16875ms space. So the total time is 2.25ms.

Arduino IR Remote Controlled Home Automation Project

On pressing Power, ONE, TWO, THREE and FOUR buttons following IR keys are transmitted by the remote control.

Arduino IR Remote Controlled Home Automation Project

The IR remote keys are read by the TSOP 1738 IR sensor and transmitted to the Arduino board. The Arduino has the program code to detect the IR key received and accordingly switch digital output to the pins connecting with the relays.

When the ONE button is pressed on the IR remote, the IR key transmitted is 0x1FE50AF. When the program code reads the stated key, it switches the device connected at pin 10 ON by sending a HIGH logic to trigger the relay to NO point. If the device is already ON which is traced by a Boolean “a”, device connected at pin 10 is switched OFF by sending a LOW logic to trigger the relay to NC point.

When the TWO button is pressed on the IR remote, the IR key transmitted is 0x1FED827. When the program code reads the stated key, it switches the device connected at pin 7 ON by sending a HIGH logic to trigger the relay to NO point. If the device is already ON which is traced by a Boolean “b”, device connected at pin 7 is switched OFF by sending a LOW logic to trigger the relay to NC point.

When the THREE button is pressed on the IR remote, the IR key transmitted is 0x1FEF807. When the program code reads the stated key, it switches the device connected at pin 8 ON by sending a HIGH logic to trigger the relay to NO point. If the device is already ON which is traced by a Boolean “c”, device connected at pin 8 is switched OFF by sending a LOW logic to trigger the relay to NC point. 

 When the FOUR button is pressed on the IR remote, the IR key transmitted is 0x1FE30CF. When the program code reads the stated key, it switches the device connected at pin 9 ON by sending a HIGH logic to trigger the relay to NO point. If the device is already ON which is traced by a Boolean “d”, device connected at pin 9 is switched OFF by sending a LOW logic to trigger the relay to NC point.

When the Power button is pressed on the IR remote, the IR key transmitted is 0x1FE609F.  When the program code reads the stated key, it switches all the devices ON while if devices are already ON, it switches the devices OFF.

Programming Guide The program code will run on the Arduino board. In the program code, first the standard open-source libraries of Arduino for interfacing LCD and IR receiver are imported. #include #include //import the LCD library A variable is declared and assigned to pin 11 where output from the IR receiver is connected. An object of the IR receiver class is initialized and assigned to the variable. An object of LCD class is declared and is mapped to the Arduino pins where LCD is connected. A variable to hold the IR key is declared and pins 7, 8, 9 and 10 are assigned to variables TWO, THREE, FOUR and ONE representing the devices. Variables a, b, c, d, and e are declared to keep track of device statuses. int RECV_PIN = 11;IRrecv irrecv(RECV_PIN);LiquidCrystal lcd(13, 12, 6, 5, 4, 3);// Pins used for RS,E,D4,D5,D6,D7decode_results results;int a=0,b=0,c=0,d=0,e=0,spd=0; //used for key press or not int ONE=10;    //Digital pin 6 isS used to ON relay 1int TWO=7;    //Digital pin 7 is used to ON relay 2int THREE=8;   //Digital pin 8 is used to ON relay 3int FOUR=9;  //Digital pin 9 is used to ON relay 4 

A setup() function is declared in which the baud rate for serial transmission of data to the  LCD is set to 9600 bits per second using Serial.begin() function. The LCD is initialized using lcd.begin() function and microcontroller is set ready to receive IR keys using irrecv.enableIRIn() function. The pins connecting with the relays are set to digital output using PinMode() function. Some initial messages are flashed on the LCD display indicating the purpose of the project and default OFF status of all the devices.

void setup(){  Serial.begin(9600);  lcd.begin(16,2);//LCD 16×2 initialization  irrecv.enableIRIn(); // Start the receiver  pinMode(ONE, OUTPUT);// Set pim 6 as OUTPUT  pinMode(TWO, OUTPUT);// Set pim 7 as OUTPUT  pinMode(THREE, OUTPUT); // Set pim 8 as OUTPUT  pinMode(FOUR, OUTPUT); // Set pim 8 as OUTPUT  lcd.setCursor(0,0); //Initially set the cursor position of LCD to 1st Columb 1st row.  lcd.print(“Engineers Garage”);//After initialising print data  lcd.setCursor(0,1); //Initially set the cursor position of LCD to 1st Columb 2nd row.   lcd.print(”               “);  //print blank to clear all the data on LCD   delay(3000);   lcd.setCursor(0,0);   lcd.print(”  IR Based Home  “);   lcd.setCursor(0,1);   lcd.print(”   Automation   “);     delay(3000);   lcd.setCursor(0,0);   lcd.print(“D1:OFF    D2:OFF”); //Initially dispaly all are OFF    lcd.setCursor(0,1);   lcd.print(“D3:OFF    D4:OFF”);//Initially dispaly all are OFF } 

The loop() function is called in which the received IR keys are detected using irrecv.decode() function. If the IR key received is 0x1FE50AF corresponding to ONE button, and if Device 1 is OFF traced by checking variable “a” set to 0, a HIGH logic is sent to the pin 10 using DigitalWrite() function and variable “a” is set to 1. If Device 1 is ON traced by checking variable “a” set to 1, a LOW logic is sent to the pin 10 using DigitalWrite() function and variable “a” is set to 0. The current status of Device 1 is updated on the LCD.

void loop() {  if (irrecv.decode(&results)) {    // IF BUTTON 1 PRESSED ….         if(results.value==0x1FE50AF && a==0){   // Checking the received number if found with the given condition       a=1;                       // “a” variable used to checked if button is pressed or not.       digitalWrite(ONE,1);       //if pressed send HIGH value to the pin number 6       lcd.setCursor(3,0);               lcd.print(“ON “);          //Display ON in the location 1st ROW and 3rd COLUMB       }      else if (results.value==0x1FE50AF && a==1)          {// IF BUTTON 1 PRESSED ….           a=0;          digitalWrite(ONE,0);          lcd.setCursor(3,0);          lcd.print(“OFF”);          }

If the IR key received is 0x1FED827 corresponding to TWO button, and if Device 2 is OFF traced by checking variable “b” set to 0, a HIGH logic is sent to the pin 7 using DigitalWrite() function and variable “b” is set to 1. If Device 2 is ON traced by checking variable “b” set to 1, a LOW logic is sent to the pin 7 using DigitalWrite() function and variable “b” is set to 0. The current status of Device 2 is updated on the LCD.

else if (results.value==0x1FED827 && b==0)            {// IF BUTTON 2 PRESSED ….             b=1;            digitalWrite(TWO,1);            lcd.setCursor(13,0);            lcd.print(“ON “);            }      else if (results.value==0x1FED827 && b==1)          {// IF BUTTON 2 PRESSED ….           b=0;          digitalWrite(TWO,0);           lcd.setCursor(13,0);            lcd.print(“OFF “);          }

If the IR key received is 0x1FEF807 corresponding to THREE button, and if Device 3 is OFF traced by checking variable “c” set to 0, a HIGH logic is sent to the pin 8 using DigitalWrite() function and variable “c” is set to 1. If Device 3 is ON traced by checking variable “c” set to 1, a LOW logic is sent to the pin 8 using DigitalWrite() function and variable “c” is set to 0. The current status of Device 3 is updated on the LCD.

 else if(results.value==0x1FEF807 && c==0)      { // IF BUTTON 3 PRESSED ….          c=1;       digitalWrite(THREE,1);       lcd.setCursor(3,1);       lcd.print(“ON “);       }      else if (results.value==0x1FEF807 && c==1)          {// IF BUTTON 3 PRESSED ….             c=0;          digitalWrite(THREE,0);          lcd.setCursor(3,1);          lcd.print(“OFF “);          }

If the IR key received is 0x1FE30CF corresponding to FOUR button, and if Device 4 is OFF traced by checking variable “d” set to 0, a HIGH logic is sent to the pin 9 using DigitalWrite() function and variable “d” is set to 1. If Device 4 is ON traced by checking variable “d” set to 1, a LOW logic is sent to the pin 9 using DigitalWrite() function and variable “d” is set to 0. The current status of Device 4 is updated on the LCD.

else if (results.value==0x1FE30CF && d==0)            {// IF BUTTON 4 PRESSED ….               d=1;            digitalWrite(FOUR,1);             lcd.setCursor(13,1);            lcd.print(“ON “);            }      else if (results.value==0x1FE30CF && d==1)          {// IF BUTTON 4 PRESSED ….           d=0;          digitalWrite(FOUR,0);           lcd.setCursor(13,1);            lcd.print(“OFF “);          }

If the IR key received is 0x1FE48B7 corresponding to POWER button, and variable “e” set to 0, a HIGH logic is sent to the pins 7, 8, 9 and 10 using DigitalWrite() function and variable “e” is set to 1. If all devices are ON traced by checking variable “e” set to 1, a LOW logic is sent to the pins 7, 8, 9 and 10 using DigitalWrite() function and variable “e” is set to 0. The current status of all the devices is updated on the LCD.

else if (results.value==0x1FE48B7 && e==0 )            {// IF POWER BUTTON PRESSED ….               e=1;            digitalWrite(ONE,1);            digitalWrite(TWO,1);            digitalWrite(THREE,1);            digitalWrite(FOUR,1);            lcd.setCursor(0,0);            lcd.print(“D1:ON     D2:ON  “); //Initially dispaly all are OFF             lcd.setCursor(0,1);            lcd.print(“D3:ON     D4:ON  “);//Initially dispaly all are OFF              }      else if (results.value==0x1FE48B7 && e==1)          {// IF POWER BUTTON PRESSED …..              e=0;            digitalWrite(ONE,0);            digitalWrite(TWO,0);            digitalWrite(THREE,0);            digitalWrite(FOUR,0);           // digitalWrite(PWM,0);           lcd.setCursor(0,0);           lcd.print(“D1:OFF    D2:OFF”); //Dispaly all are OFF            lcd.setCursor(0,1);           lcd.print(“D3:OFF    D4:OFF”);//Dispaly all are OFF           } 

In the end of the loop() function, the controller is configured to receive the next IR key by calling the irrecv.resume() function.

irrecv.resume(); // Receive the next value}} This ends the program code for Home Automation Project controlled by NEC IR Remote..

Comments

 
  1. No comment yet, you two

 

Comment

  • Comment