In this post we will be designing home automation using Arduino UNO and IR remote control device.
Components Required
- Arduino UNO board
- TSOP 1738 IR Remote Control Receiver
- 1 KΩ Resistor X 4
- 2N2222 NPN Transistor X 4
- 1N4007 Diode X 4
- 12 V Relay X 4 – relay board
- Remote Control
- Prototyping board (Bread board)
- Connecting wires
- 12 V Power supply
Here for remote control we will be using old TV remote.
Circuit diagram
How it works?
In this project, home automation system controls 4 different appliances with the help of a TV Remote. The working of the project is explained below.
The TSOP1738 IR Receiver Module has a built – in photo receiver, band pass filter and de-modulator. The output of the module can be readily read by a micro-controller. It supports a carrier frequency of 38 KHz. Hence, the carrier frequency of the source i.e. the remote control must be in the range of 38 KHz for it to demodulate.
First step is to decode the data from the remote control using TSOP1738 and Arduino UNO. For that, we need to use a special library called “IRremote”. Download this library from Arduino-IRremote and place it in the libraries folder of Arduino.
The next step is to decode the data of each key of the remote. For this, we will use some functions in the “IRremote” library. The following program will help us in decoding the data from each key of the remote.
NOTE: The following program is an example sketch from the “IRremote” library.
#include <IRremote.h> int RECV_PIN = 11; IRrecv irrecv(RECV_PIN); decode_results results; void setup() { Serial.begin(9600); irrecv.enableIRIn(); } void loop() { if (irrecv.decode(&results)) { Serial.println(results.value, HEX); irrecv.resume(); } delay(100); } view raw
After decoding the keys, we will write the code for our final home automation system using Power key and numeric keys 1 to 4 to control 4 loads. Numeric keys will control individual loads i.e. key 1 can be used to turn ON or OFF load 1 and so on. Power key will turn ON or OFF all the loads at once.
In the code, we will compare the pressed key against the decoded values which we got earlier. If the key is matched, the corresponding load is turned ON. If the same key is pressed once again, the load is turned OFF. Similar operation is applicable for all the other keys.
Sample code
#include <IRremote.h> const int RECV_PIN=11; IRrecv irrecv(RECV_PIN); decode_results results; #define IN1 3 #define IN2 4 #define IN3 5 #define IN4 6 bool i=false; bool j=false; bool k=false; bool l=false; bool m=false; void setup() { Serial.begin(9600); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT); irrecv.enableIRIn(); irrecv.blink13(true); } void loop() { if (irrecv.decode(&results)) { Serial.println(results.value,HEX); delay(100); ///////////////////////// if(results.value==0x40BD00FF) { i=!i; digitalWrite(IN1, i); } //////////////////////// if(results.value==0x40BD807F) { j=!j; digitalWrite(IN2, j); } if(results.value==0x40BD40BF) { k=!k; digitalWrite(IN3, k); } ////////////////////////////// if(results.value==0x40BDC03F) { l=!l; digitalWrite(IN4, l) } ////////////////////// if(results.value==0x40BD28D7) { m=!m; digitalWrite(IN1, m); digitalWrite(IN2, m); digitalWrite(IN3, m); digitalWrite(IN4, m); } irrecv.resume(); // Receive the next value } }