GSM Based Home Automation using Arduino

Published  February 10, 2016   198
S Saddam
Author
GSM Based Home Automation Using Arduino
GSM Based Home Automation Using Arduino

Mobile phone is a revolutionary invention of the century. It was primarily designed for making and receiving calls & text messages, but it has become the whole world after the Smart phone comes into the picture. In this project we are building a home automation system, where one can control the home appliances, using the simple GSM based phone, just by sending SMS through his phone. In this project, no Smart phone is needed, just the old GSM phone will work to switch ON and OFF any home electronic appliances, from anywhere. You can also check some more Wireless Home Automation projects here: IR Remote Controlled Home Automation using ArduinoBluetooth Controlled Home Automation along with DTMF Based Home AutomationPC Controlled Home Automation using Arduino.

If you are completely new to GSM module, you can also consider reading our Arduino GSM Module tutorial to understand the basics before proceeding with this project.  

Working Explanation

In this project, Arduino is used for controlling whole the process. Here we have used GSM wireless communication for controlling home appliances. We send some commands like “#A.light on*”, “#A.light off*” and so on for controlling AC home appliances. After receiving given commands by Arduino through GSM, Arduino send signal to relays, to switch ON or OFF  the home appliances using a relay driver.

Circuit Components:

  • Arduino UNO
  • GSM Module
  • ULN2003
  • Relay 5 volt
  • Bulb with holder
  • Connecting wires
  • Bread board
  • 16x2 LCD
  • Power supply
  • Cell phone

GSM Based Home Automation System Block diagram

Here we have used a prefix in command string that is “#A.”. This prefix is used to identify that the main command is coming next to it and * at the end of string indicates that message has been ended.

When we send SMS to GSM module by Mobile, then GSM receives that SMS and sends it to Arduino. Now Arduino reads this SMS and extract main command from the received string and stores in a variable. After this, Arduino compare this string with predefined string. If match occurred then Arduino sends signal to relay via relay driver for turning ON and OFF the home appliances. And relative result also prints on 16x2 LCD by using appropriate commands.

Here in this project we have used 3 zero watt bulb for demonstration which indicates Fan, Light and TV.

Below is the list of messages which we send via SMS, to turn On and Off the Fan, Light and TV:

S.no.

Message

Operation

1

#A.fan on*

Fan ON

2

#A.fan off*

Fan OFF

3

#A.light on*

Light ON

4

#A.light off*

Light OFF

5

#A.tv on*

TV ON

6

#A.tv off*

TV Off

7

#A.all on*

All ON

8

#A.all off*

All OFF

 

GSM Module:

GSM module is used in many communication devices which are based on GSM (Global System for Mobile Communications) technology. It is used to interact with GSM network using a computer. GSM module only understands AT commands, and can respond accordingly. The most basic command is “AT”, if GSM respond OK then it is working good otherwise it respond with “ERROR”. There are various AT commands like ATA for answer a call, ATD to dial a call, AT+CMGR to read the message, AT+CMGS to send the sms etc. AT commands should be followed by Carriage return i.e. \r (0D in hex), like “AT+CMGS\r”. We can use GSM module using these commands:

ATE0 - For echo off

AT+CNMI=2,2,0,0,0  <ENTER>          - Auto opened message Receiving.  (No need to open message)

ATD<Mobile Number>; <ENTER>    -  making a call (ATD+919610126059;\r\n)

AT+CMGF=1 <ENTER>                       - Selecting Text mode

AT+CMGS=”Mobile Number” <ENTER> - Assigning recipient’s mobile number

>>Now we can write our message

>>After writing message

Ctrl+Z  send message command (26 in decimal).

ENTER=0x0d in HEX

GSM Module SIM900A

The SIM900 is a complete Quad-band GSM/GPRS Module which delivers GSM/GPRS 850/900/1800/1900MHz performance for voice, SMS and Data with low power consumption.

Circuit Description

Connections of this GSM based home automation circuit are quite simple, here a liquid crystal display is used for displaying status of home appliances which is directly connected to arduino in 4-bit mode. Data pins of LCD namely RS, EN, D4, D5, D6, D7 are connected to arduino digital pin number 6, 7, 8, 9, 10, 11. And Rx and Tx pin of GSM module is directly connected at Tx and Rx pin of Arduino respectively. And GSM module is powered by using a 12 volt adaptor. 5 volt SPDT 3 relays are used for controlling LIGHT, FAN and TV. And relays are connected to arduino pin number 3, 4 and 5 through relay driver ULN2003 for controlling LIGHT, FAN and TV respectively.

GSM Based Home Automation System Circuit Diagram

Code Description

In programming part of this project, first of all in programming we includes library for liquid crystal display and then we defines data and control pins for LCD and home appliances.

#include<LiquidCrystal.h>
LiquidCrystal lcd(6,7,8,9,10,11);
#define Fan 3
#define Light 4
#define TV 5
int temp=0,i=0;
int led=13;

After this serial communication is initialized at 9600 bps and gives direction to used pin.

void setup()
{
  lcd.begin(16,2);
  Serial.begin(9600);
  pinMode(led, OUTPUT);
   pinMode(Fan, OUTPUT);
    pinMode(Light, OUTPUT);
     pinMode(TV, OUTPUT);

For receiving data serially we have used two functions one is Serial.available which checks whether any serial data is coming and other one is Serial.read which reads the data that comes serially.

 while (Serial.available()) 
      {
      char inChar=Serial.read();

After receiving data serially we have stored it in a string and then waiting for Enter.

void serialEvent() 
 {
  while(Serial.available()) 
  {
    if(Serial.find("#A."))
    {
      digitalWrite(led, HIGH);
      delay(1000);
      digitalWrite(led, LOW);
      while (Serial.available()) 
      {
      char inChar=Serial.read();
      str[i++]=inChar;
      if(inChar=='*')
      {
        temp=1;
        return;
      } 

When Enter comes program start to compare received string with already defined string and if string matched then a relative operation is performed by using appropriate command that are given in code.

void check()
{
   if(!(strncmp(str,"tv on",5)))
    {
      digitalWrite(TV, HIGH);
      lcd.setCursor(13,1); 
      lcd.print("ON    ");
      delay(200);
    }  
   
   else if(!(strncmp(str,"tv off",6)))
    {
      digitalWrite(TV, LOW);
      lcd.setCursor(13,1); 
      lcd.print("OFF    ");
      delay(200);
    }

Complete Project Code

#include<LiquidCrystal.h>
LiquidCrystal lcd(6,7,8,9,10,11);
#define Fan 3
#define Light 4
#define TV 5
int temp=0,i=0;
int led=13;
char str[15];
void setup()
{
  lcd.begin(16,2);
  Serial.begin(9600);
  pinMode(led, OUTPUT);
   pinMode(Fan, OUTPUT);
    pinMode(Light, OUTPUT);
     pinMode(TV, OUTPUT);
  
  lcd.setCursor(0,0);
  lcd.print("GSM Control Home");
  lcd.setCursor(0,1);
  lcd.print("   Automaton    ");
  delay(2000);
  lcd.clear();
  lcd.print("Circuit Digest");
  delay(1000);
  lcd.setCursor(0,1);
  lcd.print("System Ready");
  Serial.println("AT+CNMI=2,2,0,0,0");
  delay(500);
  Serial.println("AT+CMGF=1");
  delay(1000);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Fan   Light  TV ");
  lcd.setCursor(0,1);
  lcd.print("OFF    OFF   OFF "); 
}
void loop()
{
  lcd.setCursor(0,0);
  lcd.print("Fan   Light  TV");
  if(temp==1)
  {
    check();
    temp=0;
    i=0;
    delay(1000);
  }
}
 void serialEvent() 
 {
  while(Serial.available()) 
  {
    if(Serial.find("#A."))
    {
      digitalWrite(led, HIGH);
      delay(1000);
      digitalWrite(led, LOW);
      while (Serial.available()) 
      {
      char inChar=Serial.read();
      str[i++]=inChar;
      if(inChar=='*')
      {
        temp=1;
        return;
      } 
      } 
    }
   }
 }
void check()
{
   if(!(strncmp(str,"tv on",5)))
    {
      digitalWrite(TV, HIGH);
      lcd.setCursor(13,1); 
      lcd.print("ON    ");
      delay(200);
    }  
   
   else if(!(strncmp(str,"tv off",6)))
    {
      digitalWrite(TV, LOW);
      lcd.setCursor(13,1); 
      lcd.print("OFF    ");
      delay(200);
    }
  
    else if(!(strncmp(str,"fan on",5)))
    {
      digitalWrite(Fan, HIGH);
      lcd.setCursor(0,1); 
      lcd.print("ON   ");
      delay(200);
    }
 
    else if(!(strncmp(str,"fan off",7)))
    {
      digitalWrite(Fan, LOW);
      lcd.setCursor(0,1); 
      lcd.print("OFF    ");
      delay(200);
    }
 
    else if(!(strncmp(str,"light on",8)))
    {
      digitalWrite(Light, HIGH);
      lcd.setCursor(7,1); 
      lcd.print("ON    ");
      delay(200);
    }
 
    else if(!(strncmp(str,"light off",9)))
    {
      digitalWrite(Light, LOW);
      lcd.setCursor(7,1); 
      lcd.print("OFF    ");
      delay(200);
    } 
    
    else if(!(strncmp(str,"all on",6)))
    {
      digitalWrite(Light, HIGH);
      digitalWrite(Fan, HIGH);
      digitalWrite(TV, HIGH);
      lcd.setCursor(0,1); 
      lcd.print("ON     ON    ON  ");
      delay(200);
    }
 
    else if(!(strncmp(str,"all off",7)))
    {
      digitalWrite(Light, LOW);
      digitalWrite(Fan, LOW);
      digitalWrite(TV, LOW);
      lcd.setCursor(0,1); 
      lcd.print("OFF   OFF    OFF  ");
      delay(200);
    }     
}
Video

Have any question realated to this Article?

Ask Our Community Members

Comments

Commented by on | Permalink

can the same program run on arduino mega? ... I can't find uno board in my area but I've a mega board. how can I modify the circuit or /and program to suite mega board?

Commented by on | Permalink

What should be the current rating of the 12 v adapter?

Commented by on | Permalink

I have uploaded the code and made the circuit accordingly but now its not connecting with the gsm module allthough all the connections right. i am using SIM900A mini

Commented by on | Permalink

hye sir, ur code work very fine .. thank u very much .

instead of that , can i know how i want to reset each load . not all of it . its like when the load is ON . but when i sent message OFF . its does't off. so i think if i could put switch . and when i push the switch . my load is reset and it off . but i want it to work each load . means in ur code there 3load . so it will be 3 switch for reset .

sorry for asking too much . can i do that and how i want to do it .

Commented by on | Permalink

please tell me about, what softwares that we should use for dumping and all the details

Commented by on | Permalink

I want references for this to put them in my project report.

Commented by on | Permalink

Relay is On position when arduino powered up ,this will effect at project functioning bcz if power supply gone then all device is automatically shut down, if i connected with AC/DC adapter ,,,how to invert relay on and off in program(CODE) ,,,connection to nc/oc or oc/nc is not a proper solution

All Relays are Off when Arduino powers up initially, please try it out first.

i tried but but relay is not working,,,,,,every thing is gud and working properly.but when i send msg display showed that device is on but relay is not working with arduino board ,i checked connection many times everything is gud , i also checked this on bread board And DIY PCB ,but relays is not working ,,what can i do sir ,,,and how to invert relays in program, i am using arduina uno,and arduino nano,sim900, please help

Good day!

How I can convert this to SoftwareSerial ?

Please help thank you.

 

regards,

I wonder why is that when I monitor the output of SoftwareSerial port it print through Serial monitor a series of -1 and when I try to text a  message through cellphone  #A.Light on* a 255 number are displayed on serial monitor?

Anybody could help please...

Commented by on | Permalink

dear sir i am using gsm900a, i made this cicuit, and relay is working properly from serial monitor, but relay is not working from gsm 900a gsm module , relay is not working through send sms
please sir solve this problem

Commented by on | Permalink

sir in ur code what the mean of this

else if(!(strncmp(str,"all off",7)))

what 7 is representing for ? i bit confuse because there number in each of ur code .
and i face some problem when i change the name . like changing the light to " socketa" . when i sent #A.socketa on* . it does not work . why sir ?

Commented by on | Permalink

someone please help me, can I connect two or more smoke sensor ( MQ ) in one board..???
how to recognition or how to give address one by one of sensor , so I can se where sensor has detect smoke.
thank's

Commented by on | Permalink

Sir, please send me complet code to control home appliences with arduino and sim 900 serial communication(mentioned arduino board type)

Commented by on | Permalink

//YOUR CODE NOT WORKING
//=============================//
//THIS IS WORKING CODE TO USE
//=============================//
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11);
#define Fan 3
#define Light 4
#define TV A0
int temp=0,i=0;
int led=13;
char str[15];
void setup()
{

mySerial.begin(9600);
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(Fan, OUTPUT);
pinMode(Light, OUTPUT);
pinMode(TV, OUTPUT);
//========================================
Serial.println("GSM Control Home");
Serial.println(" Automaton ");
delay(2000);
Serial.println("System Ready");
//========================================
mySerial.println("AT+CNMI=2,2,0,0,0");
delay(500);
mySerial.println("AT+CMGF=1");
delay(1000);

}

void loop()
{

if(temp==0)
{
serialEvent();
temp=0;
i=0;
delay(1000);
}
}

void serialEvent()
{
while(mySerial.available())
{
if(mySerial.find("#A."))
{
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
while (mySerial.available())
{
char inChar=mySerial.read();
str[i++]=inChar;
if(inChar=='*')
{
check();
temp=1;
return;
}
}
}
}
}
void check()
{
if(!(strncmp(str,"tv on",5)))
{
digitalWrite(TV, HIGH);
delay(200);
}

else if(!(strncmp(str,"tv off",6)))
{
digitalWrite(TV, LOW);
delay(200);
}

else if(!(strncmp(str,"fan on",5)))
{
digitalWrite(Fan, HIGH);
delay(200);
}

else if(!(strncmp(str,"fan off",7)))
{
digitalWrite(Fan, LOW);
delay(200);
}

else if(!(strncmp(str,"light on",8)))
{
digitalWrite(Light, HIGH);
delay(200);
}

else if(!(strncmp(str,"light off",9)))
{
digitalWrite(Light, LOW);
delay(200);
}

else if(!(strncmp(str,"all on",6)))
{
digitalWrite(Light, HIGH);
digitalWrite(Fan, HIGH);
digitalWrite(TV, HIGH);
delay(200);
}

else if(!(strncmp(str,"all off",7)))
{
digitalWrite(Light, LOW);
digitalWrite(Fan, LOW);
digitalWrite(TV, LOW);
delay(200);
}
}

Commented by on | Permalink

C:\Users\NTSCHYD\Documents\Arduino\gsm\gsm.ino: In function 'void serialEvent()':

C:\Users\NTSCHYD\Documents\Arduino\gsm\gsm.ino:59:25: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

if(Serial.find("#A."))

^

Sketch uses 4,024 bytes (12%) of program storage space. Maximum is 32,256 bytes.
Global variables use 501 bytes (24%) of dynamic memory, leaving 1,547 bytes for local variables. Maximum is 2,048 bytes.

SENT ME THE WHAT WE DID. WHERE WE DO THE PROBLEM
KINDLY SENT REPLY

Commented by on | Permalink

Sir , GSM based home automation is my final year project. So , can you please provide me the source code for the same and full process of making the project and full details of components required for the same?

Commented by on | Permalink

Sir this project coding is correct or not .this code fake or true . I will try to project so please give me the true coding sir and my friends .thank you......

Commented by on | Permalink

when i am trying to compile your code , i am getting the error given below. Please help me to resolve this error.
Rebuild target 'Target 1'
assembling STARTUP.A51...
compiling l.c...
l.c(1): warning C318: can't open file 'LiquidCrystal.h'
l.c(2): error C129: missing ';' before 'lcd'
Target not created.
Build Time Elapsed: 00:00:00

Commented by on | Permalink

i am trying this project but i am getting compilation error unable to rename core.a reason permission denied..if please anyone know this answer me ....thanks in advance

Commented by on | Permalink

Hi i have done this project but my problem is
If i send any message to the gsm the gsm is receiving message but there is no response in Arduino output as well as in lcd display
The 3 outputs are remains in off position even when the msg is received
Please help me

Commented by on | Permalink

Hi, can this project use ATEMGA32 instead of 8051?

Commented by on | Permalink

First thank you being you are voluntary to help us.
my question is , on what software I will be run this program?

Commented by on | Permalink

Sir, how can I provide an input in simulation(now the bulb is off but I need to on through simulation. How? ?)

Commented by on | Permalink

Sir give me the gsm code to send sms ...code not working

Commented by on | Permalink

Sir shall i use gsm sim900A for same code?

Commented by on | Permalink

Sir, can I use sim800 gsm module for this project? Is there any alteration need to be done if I use sim800? Tq

Commented by on | Permalink

Please do this project without ULN2003.

Thanks

Commented by on | Permalink

Sir, you have defined a function serialEvent() .... bt you didn't called it anywhere in the program,,, Where should i have to call this funcation?

Commented by on | Permalink

The code is working
So how to commands from gsm module
Plz send me

Commented by on | Permalink

sir i just doing this project thku sir but i have face some problem on doing this project that is gsm receives the command and lcd it will displays but the load cant operates. .it does not receives the required supply from the Arduino through ic wht can I do sir can u pls tell me

Commented by on | Permalink

When i tried to turn on the any equipment through text messag then its isnt working . But when i type the those command on serial monitor then its works .

What to do about this problem ?

Commented by on | Permalink

Can I use sim 900 in the place of sim900a.if I use it, is ther any instruction to be changed in the code.pls tell me.
Thank you

Commented by on | Permalink

Hello Sir,

Thanks for the project details, it is a great project my dream come true.
When I compile the sketch it gives the following error:
if(Serial.find("#A."))
^
Can you please provide me the coding for 8 channels relays to be controlled;
Fan
Light
TV
Main Door Light
Socket
Lamp
Mis 1
Mis 2

I can handle the electronics part but don't know anything about the coding part.

I will be grateful to you.

Regards,

Ajay

Commented by on | Permalink

my project is working good but i have one problem that
,when ever i gave a message for first time the output came but, in second time i can't get the output.i have to reset it everytime.please help me.this is my b.tech final year project.
Thank you

Commented by on | Permalink

Sir ,
The code is not working properly. The GSM is responding for the first message .after that it is not responding.
And also the code is run fine in only in serial monitor. So I want to make it working full SMS continuously.what should I do for that.
Please ,send me the valid code for project.
I'm working on it

Commented by on | Permalink

i make this project its working well .but our project is to feedback msg to a personal contact no if current is zero or we remove load then we receive a massage .
this programme is need sir plz send me the edited code .......

Commented by on | Permalink

My code is not working Any one can help me then pls solve this code......
#include<GSM.h>
GSM_SMS sms;
int RedLed=11;
int BlueLed=10;
int GreenLed=9;
String msg;
void setup()
{
Serial.begin(9600);
pinMode(RedLed,OUTPUT);
pinMode(BlueLed,OUTPUT);
pinMode(GreenLed,OUTPUT);
digitalWrite(RedLed,LOW);
digitalWrite(BlueLed,LOW);
digitalWrite(GreenLed,LOW);
Serial.println("WelCome New SMS Tutorial...");
}
void loop()
{
char c;
if(sms.available()>0)
{
Serial.println("AT+CMGR");
while(c=sms.read())
msg=msg+c;
Serial.println(c);
msg.toLowerCase();
if(msg=="redon")
{
Serial.println(msg);
digitalWrite(RedLed,HIGH);
delay(20);
}
if(msg=="blueon")
{
Serial.println(msg);
digitalWrite(BlueLed,HIGH);
delay(20);
}
if(msg=="greenon")
{
Serial.println(msg);
digitalWrite(GreenLed,HIGH);
delay(20);
}
}
}

Commented by on | Permalink

i dont want to use lcd display so is there any editing needed or can go ahead with same coding. plz help

Commented by on | Permalink

sir plz tell me the complete name and module number of gsm module

Its SIM900A, further check the picture of GSM module in the article above.

Commented by on | Permalink

i am doing the same project as my final year project and i am facing a problem regarding authorizattion of number. so, pls help me

Commented by on | Permalink

Currently I didn't purchased LCD. Can I do this project without LCD. Need any editing in the closings? Plz help me.

Commented by on | Permalink

thank you sir for this project...code is working....every thing is good...

Hello daniyal asif i am mahesh i have taken this project for irrigation purpose that is to operate solenoid valve instead of bulb,
i have purchased all the components except LCD, but the problem is i am unable to load the program in to Aurdino will you please help me. I am waiting for your replay

thank you

Commented by on | Permalink

In reply to by Dani

please dania help me , the commands is not working

Commented by on | Permalink

else if(!(strncmp(str,"fan off",7)))
num cha=7 not 6

Dear sir
I have seen ur home automation project,but I needed some help from you for making project on agriculture irrigation system , when electricity come at my farm I need msg on my phone power on ,then m using 3 phase sensor is there if 3phase ok again m need 1 more msg power ok then m given some command like pump 1 on or off,pump 2 on or off m using some valve and operate valve as per my recommendation valve 1 on or off or more valves

Commented by on | Permalink

I need coding without lcd display

Commented by on | Permalink

can I ask whats that third module? how did you do it? arduino, GSM module and the third one im a bit confused :(

Commented by on | Permalink

frist thanks for code about gsm based home automation but i have question on the arduino code
the mobile number is not mention in arduino code how do we put number of mobile

Commented by on | Permalink

sir how are you the code is okay can l use a ULM2004 in place of the ULM2003

Commented by on | Permalink

Sir im doing a project based on motor control ,while recieving a call I need help in coding part.

Commented by on | Permalink

As per subject, I wish everyone will be benefited.

Commented by on | Permalink

thanks for your effort but i have a problem having copied and paste your code to arduino ide i compiled and download, built the circuit as per your instruction but the far i can get is the lcd display fan off, light off tv off.
i sent a msg #A. fan on* but no response i tried with serial monitor too but no change pls advice thanks

Commented by on | Permalink

can you please tell me which relay board is used?

Commented by on | Permalink

hi code does not work with Arduino ide any ideas.

Commented by on | Permalink

Hej! The code is working flawless. But I can't figure out how to make the code running without PC. Everything is working OK if the Arduino is connected to PC. If I connect it to an external 5V battery, my SMS will cause nothing to happen. Some additional info will be great!

The problem is most likely with your power supply. Make sure all your devices ground are connected together and power it with a reliable 5V supply

Commented by on | Permalink

I want to ask if the smartphone can now be used for GSM

Commented by on | Permalink

Perfect project.....but did i need to install the library for The GSM SIM900a
Module

Commented by on | Permalink

could you help me write code ....please ..

Commented by on | Permalink

Iam going to do gsm based home automation and home security .is this ppssible

Commented by on | Permalink

sir this method used to the microcontroller8051.how to put a program please hlp me sir.

Commented by on | Permalink

I connect the circuit as shown in fig. and uploaded the same program in the arduino but I didn't get any output

Commented by on | Permalink

sir, if i use 16chanel relay for more ac loads then what i changing in code? kindle relpy me.
2question. can i send sms any city to operate home automation

Commented by on | Permalink

Can I use dual band gsm for this

Commented by on | Permalink

Sir,
If I use GSM module TTL then is there any changes in code?
If yes plz give me appropriate solution

Commented by on | Permalink

i want relay on or off by a particular mobile number not any other number plz help me the code.

Commented by on | Permalink

please tell me sir. how i done on Proteus?

Commented by on | Permalink

Sir, I am working on this project but I got difficulties for connection can you send me picture of connections

Commented by on | Permalink

hi sir where i can put the mobile number of the system

Commented by on | Permalink

what is the coding for gsm ? Is it the same as Arduino coding.

Add New Comment

Login to Comment Sign in with Google Log in with Facebook Sign in with GitHub