In this post we are going to build a home automation circuit by which you can control your home gadgets via GSM network or in other words using SMS commands, you can control up to 5 devices independently. The proposed GSM based home automation system is loaded with several features that make this project standout, like: password protected control for all outputs, automatic recovery from power outage, acknowledgement SMS to the user. We will also see how to automate SMS commands so that you can schedule your commands and execute without your intervention.
We will see:
- Overview and block diagram.
- Key features of the proposed home automation project.
- Full Circuit diagram.
- Source code.
- How to send SMS commands to the circuit.
- Prototype image.
- How to send automated SMS commands to the circuit.
Main Functions of this Home Automation Circuit:
These are the features that out shines other GSM based home automation projects:
1) Pin / password protected ON / OFF action.
2) Automatic recovery after power outage.
3) SMS acknowledgment.
Pin protected operation:
Cyber criminals are on the rise and they will exploit all the loop holes they discover, so it is essential to protect your gadgets that are connected to any home automation system. Not only cyber criminals but anyone who is close to you like: friends, neighbours, even kids may control your home appliances for a prank, so it is very important to protect with a pin or passcode.
In this project we need to enter a 3 digit pin in the program code which must be kept confidential. Only by sending the correct pin number with your SMS command you can turn on or off the connected home appliances.
Automatic recovery after power outage:
Power outages can occur unexpectedly for several reasons and we want all our devices back to operation as soon as power is restored. The proposed home automation circuit can remember which devices were operating before a power outage and it will turn ON those devices when power is restored.
This is accomplished using EEPROM that is present on ATmega328P microcontroller IC. EEPROM is a non-volatile memory which means the data on the microcontroller / Arduino will not get erased when power gets disconnected. In EEPROM, the status of all the 5 relays are stored and when power is restored microcontroller reads the data from EEPROM and turn ON only the devices that were operating before the power outage.
Once you sent an SMS to the circuit you may have a doubt whether your request has been successfully executed or not especially when you are away from your home. The proposed circuit will send you an SMS acknowledgement regarding the status of the relay / device to the phone number that you entered in the source code. By this way you can be sure that your action is executed.
Even if an unauthorized person able to control your home appliances an acknowledgement will be sent to your phone.
Overview and Block Diagram:
The proposed home automation circuit consists of a GSM module SIM 800 (or you can use any other GSM modem), an Arduino board and 5 relays to control 5 electrical appliances independently.
A valid SIM card needs to be inserted to the GSM modem which will send and receive SMS. The Arduino microcontroller communicates with GSM modem using serial communication protocol and Arduino will decode and check incoming SMS for these three parameters:
1) 3-digit pin number.
2) Device number (1 to 5 devices).
3) Action data (ON / OFF action).
If these 3 parameters exist in the SMS command and if the pin number matches with the pin that you entered in the source code, Arduino will take action as per your action data (ON /OFF) that you sent with the SMS.
If someone sends SMS with incorrect pin number or in incorrect format, Arduino will simply ignore the SMS and continue what it was doing before. Once the Arduino turned on or off the gadget as per your request, the circuit will respond with an acknowledgement SMS to you, so that you can be sure that your request has been executed.
NOTE: Disconnect Tx and Rx before uploading code to Arduino.
The Arduino can be powered via VIN pin or USB or even using on-board DC jack, however the GSM modem should be powered only via on-board DC jack using a wall adapter. The whole circuit can also be powered from a 9V wall adapter rated at 1 amp as shown in the diagram.
The Tx of the Arduino should connect to Rx of the GSM module and Rx of the Arduino should connect to Tx of the GSM module and ground to ground connection between Arduino and GSM must be made.
There are 5 relays to control five different gadgets independently. The relay voltage can be 9 to 12V, if you are using 12V relays then you should supply 12V to the circuit and this is the maximum.
The 5 relays are controlled by 5 NPN transistors, where it takes 5V signal from Arduino and switches 9 to 12V rated relay ON and OFF.
A diode across all the 5 the relays must be connected as shown below. Diode will arrest high voltage spike generated while energizing and de-energizing the relay coil.
Cathode terminal of the diode should connect to +Ve supply and anode terminal of the diode should connect to collector of the transistor.
You need to change the following in the code:
1) You need to insert your phone number to receive SMS acknowledgement:
2) You need to create a 3 digit pin (000 to 999 – it should be 3 digits) and insert it here:
How to send SMS commands to the circuit?
When you power ON the circuit with the completed setup, after one minute you will receive a SMS to your phone from the circuit saying that the system is ready to accept your SMS commands. One minute is pre-determined duration, your GSM module will take 30 to 50 seconds to latch in to cellular network.
To send SMS commands to turn ON or OFF individual relay, you need to follow this format:
- Your SMS should start with “/” and end with “/”.
- In the place of xxx, replace with your 3 digit pin that you entered in the code.
- After the pin, “1” represents the device number. We have 5 relay and we are going to turn on relay no. 1 (to turn on or off relay number 2 replace 1 with “2”).
- On or off represents your action to turn on or off your connected device. “on” and “off” must be in small letters and capital letters will get rejected.
For example, I am going to turn on relay no. 1 and my pin is 350. You should send /3501on/. To turn off the relay no. 1 send /3501off/
Now you know how to send SMS commands to the circuit to control individual relays. There are two more commands which enable to us to control all the 5 relays all at once.
- /xxxallon/ to turn on all 5 relays.
- /xxxalloff/ to turn off all 5 relays.
Now let’s see the circuit in action:
You will receive an SMS from the circuit saying that the system is ready to receive your SMS commands.
Now we are sending /350allon/ to the circuit’s phone number. 350 is 3 digit pin number. When this SMS received by the circuit, all the output pins turns high and an acknowledgement SMS will be send to the owner’s phone as shown above.
As we can see all the 5 outputs turned ON, in the place of (green) LED you should connect relays. Now let’s turn off all outputs.
We are sending /350alloff/ this command will turn off all the output at once. We will also receive an acknowledgement saying that devices are turned off.
As you can see all the outputs are turned off.
How to automate SMS commands?
The function of a home automation system is not only to control your gadgets in real time, but also to execute scheduled commands automatically without owner’s intervention.
For example, you left your home for some important function or meeting and no one will be available at your home for next few days. Since you fear theft, you decided to turn ON the lights until you reach home.
Instead of running your lights on continuously, you can turn on say at 6:00 PM and turned off at 6:00 AM automatically without your intervention. Not only you are saving energy but periodic on and off of lights may give an impression that some people may still at home.
Such action can be accomplished by sending SMS commands automatically from your phone.
Ok, how to send SMS commands automatically?
On most of the basic phones and smartphone we have an option to “send later” through which you can schedule your SMS that need to be sent in future. You can schedule a time, date, month even year.
By setting up correct SMS commands and time, your phone will send SMS to the circuit without your intervention. Now this simple hack makes our circuit truly an automated system.
If you have any questions regarding this project, feel free to comment, you will get a guaranteed reply from us.