Android and Arduino SMS Based Home Automation

23,742

229

41

Introduction: Android and Arduino SMS Based Home Automation

! ! ! N O T I C E ! ! !

Due to the local cellphone tower being upgraded in my area, I am no longer able to use this GSM module. The newer tower no longer supports 2G devices. Therefore, I can no longer give any support for this project.

Recently, I received a relatively cheap Quad Band GSM/GPRS module to play with. It is a SIM800L module, and communicates with any micro via a serial port. It came complete with a panel mount antenna.

I decided to build a simple SMS Controller system which uses short message service (SMS) commands to control devices and indicate alarms.

Step 1: SMS Commands

AS with any communication system, specific commands need to be send to a remote device to tell it what to do. Likewise, the remote device needs to reply or react on these commands. This project consists of two parts, the SMS Controller, and an standard cellular phone.

The idea was to create a simple SMS Controller with four digital outputs. Depending on the received SMS, the unit must be able to control the individual outputs.

I also decided to include four digital inputs. This can be used to indicate alarms or other information.

Before starting the build, I decided to create specific commands for specific functions. This 'commands' will be sent using an SMS from a cellular phone.

SMS Controller Receive Commands:

o1:1 - turn output 1 On

o1:0 - turn output 1 Off

o1:p - pulse output 1 On, then turn Off

o2:1 - turn output 2 On

o2:0 - turn output 2 Off

o2:p - pulse output 2 On, then turn Off

o3:1 - turn output 3 On

o3:0 - turn output 3 Off

o3:p - pulse output 3 On, then turn Off

o4:1 - turn output 4 On

o4:0 - turn output 4 Off

o4:p - pulse output 4 On, then turn Off

???? - Request status of Inputs and Outputs

#### - Reset system

For feedback, the SMS Controller should respond to the received commands, and reply with an SMS. I decided that this reply SMS should include the status of all I/O pins.

SMS Controller Response Commands:

i1:x i2:x i3:x i4:x o1:x o2:x o3:x o4:x

where x is the I/O status, 1 for On, 0 for Off.

Step 2: Building the SMS Controller

Equipment required:

Any Arduino, or stand-alone ATMEGA328p on a breadboard

SIM800L GSM/GPRS Module with a sim card capable of sending and receiving SMS's

Step down DC/DC converter

NOTE !!!

The DC/DC converter is required to power the SIM800L module. This module operates between 3.7V and 5V, depending on the version you have. This module also requires a power supply that can deliver up to 2A when the module transmit data. It can not be powered directly from the Arduino Uno !!!

The circuit is quite simple. I have assembled and tested it on breadboard.

The power to the circuit is via the DC/DC converter, with the output voltage set to 4.5V. There are four LEDs to simulate the digital outputs, and four buttons for the digital inputs. The SIM800L is connected to the Rx/Tx pins of the ATMEGA328p.

A 5th LED is used to indicate when the system in busy sending an SMS.

Step 3: Programming the ATMEGA328p

Before programming, open the INO file, and edit the phone number. Replace xxxxxxxxxx with your own cellular phone number in line 46. Recompile, and upload the file.

Also, read the instructions on how to configure the Software Serial port in the INO file.

//=============================================================================
//

// ! ! ! NOTE ! ! !

// ================

//

// BUFFER IN SOFTWARE SERIAL LIBRARY TO BE CHANGED TO 200

//

// To use Software Serial, the user should also change the Software Serial BUFFER to 200.

// This must be edited in the following file:

//

// C:/Program Files/Arduino x.x.x/Hardware/Arduino/AVR/Libraries/SoftwareSerial/src/SoftWareSerial.h

//

// Change buffer as below:

//

// #ifndef _SS_MAX_RX_BUFF

// #define _SS_MAX_RX_BUFF 200

// RX buffer size

// #endif

//

//=============================================================================

Refer to this instructable to program the ATMEGA328p on the breadboard using an Arduino UNO.

https://www.instructables.com/id/Arduino-UNO-as-AtM...

Step 4: Using the SMS Controller

Using the SMS Controller

The SMS Controller will automatically send an SMS to your phone if any of the four inputs are triggered. The details of the trigger will be contained in the SMS text.

The SMS messages and commands can be edited to your needs in the INO file.

Testing the SMS Controller Outputs

From your cellular phone, send the following commands to your SIM800L simcard number:

o1:1, this will turn on output 1.

On your phone, you will receive the following SMS:

i1:0 i2:0 i3:0 i4:0 o1:1 o2:0 03:0 o4:0

01:0, this will turn off output 1.

On your phone, you will receive the following SMS:

i1:0 i2:0 i3:0 i4:0 o1:0 o2:0 03:0 o4:0

01:p, this will turn on output 1 for 1 second, then turn output 1 off again (pulsed).

On your phone, you will receive the following SMS:

i1:0 i2:0 i3:0 i4:0 o1:0 o2:0 03:0 o4:0

Testing the SMS Controller Inputs

On the SMS Controller, press button 1 briefly

On your phone, you will automatically receive the following SMS:

i1:1 i2:0 i3:0 i4:0 o1:0 o2:0 03:0 o4:0

On the SMS Controller, press button 2 briefly

On your phone, you will automatically receive the following SMS:

i1:1 i2:1 i3:0 i4:0 o1:0 o2:0 03:0 o4:0

On the SMS Controller, press button 3 briefly

On your phone, you will automatically receive the following SMS:

i1:1 i2:1i3:1 i4:0 o1:0 o2:0 03:0 o4:0

As can be seen on the received SMS, the outputs changes according to the commands received. However, the inputs does not change back from a 1 to a 0 after the buttons were pressed. Because I wanted to be able to see any changes on the inputs, I decided to seal in the input status until a reset command is send to the SMS Controller.

Reset Alarms

To reset the input status, send the following command:

####, this will reset the input status.

On your phone, you will receive the following SMS:

i1:0 i2:0 i3:0 i4:0 o1:0 o2:0 03:0 o4:0

Status Updates

You can also request the status at any time by sending the following command:

????, this will request a status update of the I/Os.

On your phone, you will receive the following SMS:

i1:x i2:x i3:x i4:x o1:x o2:x 03:x o4:x

where x indicates the status, 1 for on, 0 for off.

Step 5: Android Application

Using MIT App Inventor 2 (http://ai2.appinventor.mit.edu/), I created a simple user interface for my Android cellular phone. This app allows you to customise the description of each I/O. It also allows for entry of the telephone number.

The four buttons are used to control the Outputs, while the check boxes indicate the input status.

To edit the app, create a MIT App Inventor 2 account, and import the AIA file.

To install the app on your phone, copy the APK file to your phone, and install it. You will have to enable the installation of apps from "Unknown Sources" under your phone's security settings.

Automation Contest 2016

Participated in the
Automation Contest 2016

3 People Made This Project!

Recommendations

  • The 1000th Contest

    The 1000th Contest
  • Battery Powered Contest

    Battery Powered Contest
  • Hand Tools Only Challenge

    Hand Tools Only Challenge

41 Discussions

0
mte16
mte16

4 years ago

Hi Eric,
Can I use this project SIM900 GSM / GPS module?

0
FitriRosli
FitriRosli

Reply 6 months ago

Hye hello, did it work?
If so then may i know how?

0
Eric Brouwer
Eric Brouwer

Reply 4 years ago

I think the code will work with the SIM900. The code does not make use of any "special" AT commands, so give it a try.

0
mte16
mte16

Reply 4 years ago

Thanks Eric.
I hope it works.

0
ShalviT
ShalviT

Reply 2 years ago

Did it worked ??

0
FitriRosli
FitriRosli

Question 6 months ago on Step 2

Hello sir, what changes do i have to make if i want to use gsm module sim900a.

0
szybkijanek
szybkijanek

Question 10 months ago

I have some problems when I run the application project in MIT App Inventor. After compilation and installation, the application does not work as the ready one attached. There are problems like the lack of green and red colors, when I press the relay button, the message is not sent automatically but I am redirected to the SMS application, when I receive an SMS confirming the activation, the button states do not change, I have the impression that the application is issuing an SMS application command but cannot receive information feedback. Your original apk file is 2.2MB and the new one after compilation has 3.9MB. Do you have any idea how to solve it?

0
VasantP
VasantP

Question 1 year ago on Introduction

eric
i tried building the thing as per your instructions as follows
1...supply voltage thro a buck regulator 4.5 volts to sim module as well as uno
2...changed buffer size to 200 as instructed
3...changed mobile number in sketch to my number in international format(+91XXXXXXXXXX)

powered up
sim module searched and gets network is confirmed as when we call the number it rings
when i send sms thro app sms is sent but is not delivered to the sim as i do not get any delivery report.

sim works in a similar setup made by my friend so lets assume that sim setup shold not be a problem.
the sim does not get the message and thus the setup does not respond back.

only changes i made were

1...i used a different smaller sim800l module
2...i used the uno board directly

could you guide me it will be very helpful
thanks in advance

0
VasantP
VasantP

Question 2 years ago on Introduction

Eric
i have a new enhancement needed in the project
can i send a control sms thro a specific number and then the setup will respond only to that number. i think that it will be better that way to avoid misuse.
whats your opinion
thanks for a great project. hoping of doing it now

0
ShalviT
ShalviT

2 years ago

Can we code without using software serial library.

0
MohanN1
MohanN1

Question 2 years ago on Introduction

i have uploaded the sketch but I am not able to control or receive any SMS from the switches.

the sketch has only line upto 594

there is no line 2119 and no string "SendSMS(Master_Nr,RxString);"

the end of the sketch is

S.toLowerCase();

RxString.toLowerCase();

if (RxString.indexOf(S) >= 0) return true; else return false;

}

594 is the last line

At boot-up of the unit, the unit will send a SMS to the master user.
You can disable this in line 2119.

Change:
SendSMS(Master_Nr,RxString);

to

// SendSMS(Master_Nr,RxString);

This will disable the boot-up SMS.

I tried searching for the complete sketch in Google, but I am not able to find any.

Robert

sumoja@gmail.com

0
MohanN1
MohanN1

Reply 2 years ago

Hi Eric Brouwer,

Thanks for the help, found the code V3.02.

Regards,

Mohan

0
ilukic
ilukic

2 years ago

Hi

I made it with Arduino Nano, tested it, all OK. But after inserting another SIM card, LED that indicates bussy is always ON, and Arduino can not read SMS.

SIM card is new, by same provider as first one. Please if you have some Ideas to solve this. Thank you.

0
Eric Brouwer
Eric Brouwer

Reply 2 years ago

Hi
The most likely cause for the new sim card not working, is that it doeas not have airtime available to send an SMS.
At boot-up of the unit, the unit will send a SMS to the master user.
You can disable this in line 2119.

Change:
SendSMS(Master_Nr,RxString);

to

// SendSMS(Master_Nr,RxString);

This will disable the boot-up SMS.

Hope this will help.

Regards

Eric

0
ilukic
ilukic

Reply 2 years ago

Thank you Eric.
I solved this thanks to Your Advice and I changed delay time after NetworkTime sync, to leave more time to register on network.
The next thing that happens is that the device after a while loses the Network, signal here is weak. Stable only 2g.
After connecting back on the Network, it receives not the Messages, and sends not reply. Is OK to reset only SIM800L, or complete Unit ?

Regards

Ivica.

0
sokic
sokic

3 years ago

Hi Finaly this think is working, my arduino was problem,

Thank you very much Eric, This Project is GREAT.

I will add soon readings of temperature and moisture.

0
Eric Brouwer
Eric Brouwer

Reply 3 years ago

Hi again

Great news....

You actually made me build the circuit again to test the software. I was just busy when I noticed your comment. Thanks for your feedback.

Regards

Eric

0
sokic
sokic

3 years ago

Hi Eric,

Did you send and receive any sms using GSM_Android_V200.ino and SIM800L ?

I still think that code is not completed.

I

0
sokic
sokic

3 years ago

Hi Eric,

there are 3 "ino" files? what is the procedure to install to arduino uno and connected sim800l without ATMEGA328p

Thanks