GSM & Arduino based Home Automation using SMS - tutorial and code

GSM and Arduino based Home Automation using SMS

With mobile connectivity came an array of different functionalities we couldn't even fathom before. This includes the concept of IoT which makes it possible to turn a machine on or off by a simple click on your Smartphone, or control the air conditioning at your home while you are still at the office.

You can now use this technology to build concepts, projects and products that use data and interactions between remote devices using open-source tools like Arduino.

This tutorial will show you how you can use Arduino modules to control your appliances just by sending a text message.

The main function of this project will be controlled by an Arduino, which will be set up at your home. GSM wireless communication will be used to transmit commands from your phone to the device. Once the appliance receives a signal through the Arduino, the relays will come into action, turning the switch on or off accordingly.

Planning the Project

Project overview - block diagram

Components for this Arduino project:

Get this Project's full Shopping List

Arduino code: Our Github Page for this SMS Controlled Arduino Project.

Image: electronics for u

SMS Command Design

The commands start with “#A” and end with "*". This is to make sure the Arduino identifies where the command starts and where it ends, thus preventing any problems that might arise due to the mix-up of command lines.

Once a text message is sent to the GSM module from your phone, it’s received and its contents are transmitted to the Arduino. The main command is isolated from the data and stored. The Arduino now identifies a matching string from the predefined list of commands and sends the signal to the relay accordingly.

Ultimately, the command is carried out and status is displayed on a 16x2 LCD screen.
This project will be catering to three appliances, a fan, a light and a TV, represented by respective bulbs. Once tested, you can connect it to the actual devices.

SMS Messages allowed in this Project

  • on* - Fan turns ON
  • off* - Fan turns OFF
  • #A.light on* - Light turns ON
  • #A.light off* - Light turns OFF
  • on* - TV turns ON
  • off* - TV turns OFF
  • #A.all on* - All turn ON
  • #A.all off* - All turn OFF

The GSM Module

Arduino Compatible GSM SIM900 Module 

What is a GSM Module?

GSM (Global System for Mobile Communications) Module, also known as a GPRS module, is a chip or circuit that is used to establish communication between a mobile device and a computerized machine. The SIM900 chip is what processes the Mobile Connectivity and interacts with the Sim Card that you insert into this module.
Designed for the intercommunication of a mobile device and an appliance, this module is powered by a power supply circuit and communication interfaces like RS-232.

A GSM modem is a class of wireless modem, made for communicating over the GSM and GPRS network, and like mobile phones, it requires a sim card to function. The modem requires "AT commands" for efficient and accurate interaction with the processor, that are transmitted through serial communication.

AT Commands for the GSM Module

The AT commands are sent by a processor and transmitted via the cellular network accordingly. The basic functionalities include:
  • Reading, writing and deleting texts
  • Sending text messages
  • Monitoring charging status and battery percentage
  • Searching in phone book
  • Monitoring the signal strength

The simplest command that can be given to the modem is “AT”. If the GSM returns an “OK” message, the modem is working perfectly, else it responds with an “ERROR”. Some other commands are listed below:
  1. ATA – for answering a call
  2. ATD – for dialing a call
  3. AT+CMGR – for reading a message
  4. AT+CMGR – sending a text message

The command lines need to be followed by a 'Carriage return' that is \r – 0D in hexadecimal. For example, "AT+CMGD\r" is the string to be entered for the specific action.

More commands include:
  • ATE0 – For turning off the echo
  • AT+CNMI = 2,2,000 <ENTER> - for automatically opening the message
  • ATD<Mobile Number>;<ENTER> - for making a call
  • AT+CMGF=1<ENTER> - selecting text mode
  • AT+CMGS= <Mobile Number><ENTER> -  assigning a mobile number
Check out in-depth details about AT-commands here.

Setting it up with the Arduino

Circuit and Connections

  • GSM Rx to Arduino Tx.
  • GSM Tx to Arduino Rx.
  • 5v to external 5v supply which can deliver up to 1 amp.
  • Ground to ground.

16×2 LCD Display:
  • VSS to ground.
  • VDD to supply voltage.
  • VO to adjust pin of 10k potentiometer.
  • RS to Pin 6.
  • RW to a ground.
  • Enable to Pin 7.
  • LCD D4 to Pin 8.
  • LCD D5 to Pin 9.
  • LCD D6 to Pin 10.
  • LCD D7 to Pin 11.
  • Ground one end of the potentiometer.
  • 5v to another end of the potentiometer.

4 Channel Relay Module:
  • External 5 volt to JD VCC
  • Ground to ground
  • Ini1 to Pin 3
  • Ini2 to Pin 4
  • Ini3 to Pin5
  • Vcc to Arduino 5V
  • Connect one end of all bulbs to normally open terminal of relays
  • One end of 220VAC to all common terminals of a relay and another end with another terminal of bulbs

Compared to the functionality and the commands, the GSM-based automation circuit is relatively simple. A ‘liquid crystal display’ or LCD screen module shows the status of the appliances that are in direct connection with the Arduino. LCD’s data pins, RS, EN, D4, D5, D6 and D7, are connected to the Arduino's digital Pins 6, 7, 8, 9, 10 and 11 respectively.

The Rx pin of the module is connected to the Tx pin of Arduino, and the Rx pin of Arduino is connected to the Tx pin of the module. Furthermore, a 12V adapter is used as a power supply, and 3 5V SPDT relays are used for controlling how the appliances function.

Ardiuno Code

Get the Code with comments on Github: SMS Control using Arduino, GSM and LCD Display

Copy the contents of this code and paste it in your Arduino IDE to proceed.

How the Code works:
  1. The first step is to include an LCD library and define the control pins
  2. Initialize the serial communication at 9600 baud rate
  3. Read the data that flows in
  4. Store the data
  5. Check is the string defines a command that your project can perform

Now you can try it out by simply sending the commands as SMS messages to the Sim Card on your GSM Module.

Image: microcontrollers lab

It's now as simple as flashing this code to your Arduino, making the connections and testing it out with your Phone. You will be able to control devices using SMS commands. That takes you one step closer to working with GSM Modules and creating IoT Projects.

Try this tutorial next to use a GSM Module for your first real IoT Project over the internet using GPRS Mobile Technology.


  1. I truly appreciate this post. I’ve been looking everywhere for this! Thank goodness I found it on Bing. You’ve made my day! Thank you again
    4.3 inch touch screen

  2. I generally check this kind of article and I found your article which is related to my interest. Genuinely, it is good and instructive information about gsm & arduino based home automation using light hold and other equipments. Thanks for sharing an amazing article here. electrical enclosures

  3. This Article is Awesome. It’s help me a lot. Please keep up your good work. We always with you and Waiting for your new interesting articles. Home Automation Services india.

  4. This information is so useful and informative which you have shared here. It is excellent and good for everyone. Keep posting always. I am very thankful to you. Thanks once again for sharing it. swaraj xt

  5. How often have you gone in search of a phone booth in a large international metropolis, only to discover that a homeless person has previously used it as a toilet due to a lack of other options? Have you ever bought a phone M2M Sim Card thinking it was for an international call, only to find out it wasn't the right one? The old ways have long since passed.

  6. This is actually good to read content of this blog. A is very general and huge knowledgeable platform has been known by this blog. I in reality appreciate this blog to have such kind of educational knowledge.

    essential lighting new jersey


Post a Comment

Popular Posts