Introduction: Remote Control Via GPRS/GSM SMS(Arduino)

Picture of Remote Control Via GPRS/GSM SMS(Arduino)

Remote control, especially when this no ethernet or Wifi in the outdoor, has been a very profound things in the past. When I was a child, I always image that I have an equipment which can control all home appliances. Now, this becomes a reality,with Arduino and GPRS modules and some other related modules. And, it is also quite easy, even for the beginners. Here I will step by step to show you how to remote control your home appliances via the GPRS/GSM SMS and relays.

At first, let me give a brief introduction about relay to you.
Relays are used where it is necessary to control a circuit by a low-power signal (with complete electrical isolation between control and controlled circuits). It acts as a “low voltage controlled switch to control high voltage”, For example, if you want to control power of your washer or air conditioner, which is oftern110v or 220v,by microchip such as AVR or PIC, it is necessary and safe to make your microchip control the relay first, and then control the power supply of those device with the relay.

With the GSM SMS, it is possible to control the relay remotely. You can send a message via phone to control the relay on&off. With this, it will convenient to control any device wirelessly, especially helpfully on irrigation, smart home, outdoor remote control etc.
So, let’s make such a “SMS controlled Relay” with Arduino, GPRS/GSM and a Relay module.

Step 1: Prepare Your Tools and Parts.

Picture of Prepare Your Tools and Parts.

Select the module you need, a Xduino, a GPRS/GSM module and relay module is essential. The GPRS/GSM and relay in “Shield” would be more Convenient if works with Arduino:
The modules I used in this application are as below:
Crowduino
GPRS/GSM Shield
Relay Shield
Notice that the Rated Current of the relay Is important, make sure it meets your requirements. Otherwise it maybe dangerous. Here, I use a 2A rating current relay, which is enough for my application to control a lamp. Usually, home appliances consume currents as below
Device Max current(A)
Electric Fan 1
Lamp 2
TV 2
Refrigerator 2
Microwave Oven 8
Air Conditioner Depends on the power, usually <20
Of course, you will need some tools, such as the Insulating tape, Scissors...

Step 2: Insert a SIM Card to the GPRS Shield.

Picture of Insert a SIM Card to the GPRS Shield.

The GPRS module needs a SIM card to work, just the same as a phone. Insert a SIM card to the SIM socket , make sure the SIM is unlocked(that is, it works in your phone). Record the number of SIM Card, it will be used in programming for Arduino.

Step 3: Communicate With Crowduino/Arduino by Hardware Serial.

Picture of Communicate With Crowduino/Arduino by Hardware  Serial.

There are two methods for GPRS/GSM Shield to communicate with the micro controler, one is through the software serial port, another is hardware serial port. I will show you the second method,:communicate with the Crowduino/ Arduino by hardware serial port.
There are three pins 2*3 pins in the GPRS shield. You can see the silk mark in both side of pins, one side is Xduino(this is connect to the hardware serial port), and the other side is SWserial(this side is used as software serial port).  Just as the picture, plug the jumper caps to the Xduino side.

Step 4: Upload the Program.

Picture of Upload the Program.

As the programming, you will need the Arduino IDE to compile and download the program to Arduino.
Download the code :

Using_SMS_to_Control_Relay_Hardware Serial.ino

Before the compiling, please Open the file: SoftwareSerial.h in arduino\libraries\SoftwareSerial, and modify the
#define _SS_MAX_RX_BUFF 64 // RX buffer size
To
#define _SS_MAX_RX_BUFF 128 // RX buffer size
With this modification, the Arduino would have more buffer for the received message to avoid any communication bugs.
If you have not got ready to comprehend the details, you can just copy the codes into your Arduino IDE and down it to Arduino to continue.

Then, open this file by Arduin IDE.  Upload the program to the Crowduino, please note that don't connect the GPRS shield to Crowduino when uploading program,  very important!!!!

Step 5: Plug Relay+GPRS Shields to the Crowduino

Picture of Plug Relay+GPRS Shields to the Crowduino

Plug your shields to the Crowduino, you can put the GPRS Shield in the top or put the Relay Shield in the top. In here, because we need operating the Relay Shield later, so I put the Relay Shield in the top.

Step 6: Have a Try:Control the Relay Shield by Manually.

Picture of Have a Try:Control the Relay Shield by Manually.

Now, the hardware has been connected, the program has been uploaded, we can have a try of the Relay Shield, This Relay Shield is very interesting! There are 4 Independent relays on the relay shield, each one can be controlled by the Arduino or manually. Also, there are 4 LEDs to show user the working state of relays.

Step 7: Have a Test for the Manual Control.

Picture of Have a Test for the Manual Control.

Before remote control the lamp, we can make a test. Here, we need a breadboard, a LED, two AA battery and some breadboard cables.

Plug the anode wire(the red one) of power supply to the anode of LED via the breadboard, using the same method, plug the breadboard jumper wire to the cathode of LED.

As we only need one relay here, we use the relay U3, which was controlled by the Arduino Pin5.
There are 3 terminals for U3 relay: COM3, NC3 and NO3. The COM3 is the common port, while the “NO” means “Normally Open” and NC means “Normally Connected”. That’s to say, the logic between these 3 terminals is:
When the relay is not active:
COM3 connected to NC3 and disconnected to NO3;
When the relay is active:
COM3 disconnected to NC3, and connected to NO3;

Insert the cathode wire(black one) of power supply to NO3, insert the cathode wire(orange) of LED to COM3 and tighten the terminal with a screwdriver.

Now, you can control the LED on or off via button 3, it is funny, hah...

Step 8: Control the LED Via SMS.

Picture of Control the LED Via SMS.

It is time to take out your mobile phone, (make sure your Gprs/Gsm shield is on) sent a text ”onb” to the number of the SIM card in GPRS module, the relay would be on, and the LED on!

It is necessary to explain the program, if you feel it is boring or it is too simple, just skip the following paragraph and remember there are 4 relays: U1, U2, U3, U4 each corresponding to d, c, b, a, if you want to control U1 on or off, you can send 'ond' or 'offd' to the number of the SIM card in GPRS module, the relay U1 would be on or off. If you want to control multiple relays in one SMS, just send the control commands in one SMS. For example, if I want to control U1, U2, U3 on and U4 off, sending 'ond onc onb offa' would reach this purpose. In here, I was using U3 to control the LED, so after I send 'onb', the relay U3 would be on , and the LED on!

There are some important functions you need to learn if you want to learn more on the gprs shied:

void ProcessGprsMsg()
Function: process the data Arduino get from the GPRS shield. If there is a string “+CMGR:” in the received data, theArduino will get to know: “I have received a short message, I need to analyze the message to know what to do next!”
Parameter: none
Return: none;

void ProcessSms( String sms )
Function: Arduinoanalyze the short message received. As received a string: ”ona”, it will pull up the related pin to active the relay, making the terminal COM4 connected NO4; while received a string “offa”, it will pull down the pin to make the COM4 and NO4 disconnected.
Parameter: the received message;
Return : none
In this program, once the Arduino receive the command ”offa”, which means “off the a” it will pull download the Arduno pin4, which change the relay U4 from inactive to active state. You will hear some noise like “bang..bang”, and also the LED would blinks.

Step 9: Connect the Lamp to the Relay Shield.

Picture of Connect the Lamp to the Relay Shield.

Finally to the another leading role  to play, do you still remember the lamp at the begining?  This step I will show you how to 'destroy' this nice and cute lamp.

Cut off the power supply wire of the lamp(as the picture), and insert one end to COM3,tighten the terminal with a screwdriver, and the other end to NO3 with the same method.

Make sure the Crowduino and Shields are connected to the power and the program was run normally.

Give the power to the lamp, push the switch of lamp to on, and stay away from it...

Step 10: Control the Lamp Via SMS.

Picture of Control the Lamp Via SMS.

Everything is ok, but the SMS. Take out your phone again, sent a text ”onb” to the number of the SIM card in GPRS module. The lamp was finally lit...

You can control all the device you want via this method. and, you can even control 4 relays simultaneously to control 4 device by modifying the program in Arduino. But again, Notice the Potential danger especially for the high voltage and big current decice. Good luck…

Comments

PietNel (author)2017-10-26

How do command the arduino over the gsm to send me the values of an analog signal i.e tempereture sensor.

RahmatS15 (author)2017-10-20

am using sim900a, whats code should i change ?

i was try, but while am open serial monitor just show " ? " not show the message.

AshanW3 (author)2017-06-29

how can i alter this soo it works withe the SIM5320E

alisafari186 (author)2017-05-07

hello i'm sorry i am new in this

is crowduino the arduino?

and if it not could i use arduino instead?

i search to buy this crowduino but i could not find it for buy it in my country

what shall i do?

ksve (author)2017-02-19

Hi,

i need remote controlling for single led without using relay board connections with arduino uno. can u please let me know how to do it..!!

Thanks in advance..!!

moskaski (author)ksve2017-02-23

Hi, I did what you are asking, using the above example with some modifications.

#include <SoftwareSerial.h>

//SIM800 TX is connected to Arduino D11
#define SIM800_TX_PIN 11

//SIM800 RX is connected to Arduino D10
#define SIM800_RX_PIN 10

//Create software serial object to communicate with SIM800
SoftwareSerial serialSIM800(SIM800_TX_PIN,SIM800_RX_PIN);

// EN: String buffer for the GPRS shield message
String msg = String("");
// EN: Set to 1 when the next GPRS shield message will contains the SMS message
int SmsContentFlag = 0;

void setup() {
//Begin serial comunication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(19200);
while(!Serial);

// Initialize PINs

pinMode( 2, OUTPUT);
digitalWrite( 2, LOW);

//Being serial communication with Arduino and SIM800
serialSIM800.begin(19200);
delay(1000);
Serial.println("Setup Complete!");
serialSIM800.println("AT+CMGF=1");
delay(200);
// serialSIM800.println("AT+CNMI=3,3,0,0,0"); // set module to send SMS data to serial out upon receipt
delay(200);

}

void loop() {
//Read SIM800 output (if available) and print it in Arduino IDE Serial Monitor
// if(serialSIM800.available()){
// Serial.write(serialSIM800.read());
// }
//Read Arduino IDE Serial Monitor inputs (if available) and send them to SIM800
if(Serial.available()){
serialSIM800.write(Serial.read());
}
char SerialInByte;
if(serialSIM800.available())
{
SerialInByte = (unsigned char)serialSIM800.read();
Serial.print(SerialInByte);

delay(5);

// -------------------------------------------------------------------
// EN: Program also listen to the GPRS shield message.
// -------------------------------------------------------------------
// EN: If the message ends with <CR> then process the message
if( SerialInByte == 13 ){
// EN: Store the char into the message buffer
ProcessGprsMsg();
}
if( SerialInByte == 10 ){
// EN: Skip Line feed
}
else {
// EN: store the current character in the message string buffer
msg += String(SerialInByte);
}
}
}
// EN: Make action based on the content of the SMS.
// Notice than SMS content is the result of the processing of several GPRS shield messages.
void ProcessSms( String sms ){

if( sms.indexOf("ona") >= 0 ){
digitalWrite( 2, HIGH );
}
if( sms.indexOf("offa") >= 0 ){
digitalWrite( 2, LOW );
}

}
// EN: Request Text Mode for SMS messaging
void GprsTextModeSMS(){
Serial.println( "AT+CMGF=1" );
}

void GprsReadSmsStore( String SmsStorePos ){
serialSIM800.print( "AT+CMGR=" );
serialSIM800.println( SmsStorePos );
delay(200);

//Deletes SMS from sim once read

serialSIM800.print( "AT+CMGD=" );
serialSIM800.println( SmsStorePos );
}

// EN: Clear the GPRS shield message buffer
void ClearGprsMsg(){
msg = "";
}

// EN: interpret the GPRS shield message and act appropiately
void ProcessGprsMsg() {
if( msg.indexOf( "Call Ready" ) >= 0 ){
Serial.println( "*** GPRS Shield registered on Mobile Network ***" );
GprsTextModeSMS();
}

// EN: unsolicited message received when getting a SMS message
if( msg.indexOf( "+CMTI" ) >= 0 ){
// Serial.println( "*** SMS Received ***" );
// EN: Look for the coma in the full message (+CMTI: "SM",6)
// In the sample, the SMS is stored at position 6
int iPos = msg.indexOf( "," );
String SmsStorePos = msg.substring( iPos+1 );
// Serial.print( "SMS stored at " );
// Serial.println( SmsStorePos );
// EN: Ask to read the SMS store
GprsReadSmsStore( SmsStorePos );
}

// EN: SMS store readed through UART (result of GprsReadSmsStore request)
if( msg.indexOf( "+CMGR:" ) >= 0 ){
// EN: Next message will contains the BODY of SMS
SmsContentFlag = 1;
// EN: Following lines are essentiel to not clear the flag!
ClearGprsMsg();
return;
}

// EN: +CMGR message just before indicate that the following GRPS Shield message
// (this message) will contains the SMS body
if( SmsContentFlag == 1 ){
// Serial.println( "*** SMS MESSAGE CONTENT ***" );
// Serial.println( msg );
// Serial.println( "*** END OF SMS MESSAGE ***" );
ProcessSms( msg );
}

ClearGprsMsg();
// EN: Always clear the flag
SmsContentFlag = 0;


}

ksve (author)moskaski2017-03-10

Hey thanks!! I need code for controlling an led light with sms using SIM 808 using arduino UNO. But i have a doubt, is that necessary that gprs is necessary for sending message through GSM.

purnomohari20 (author)2016-10-21

why, im can't download?

please help me..

ranjeevm (author)2016-09-23

I see no point doing this project unless you have these parts lying around because you happen to be an Arduino and Electronics hobbyist. Here are the reasons:

1. There is another project on this website that achieves the objective in <$50 (search for "start your car from a cell phone via GSM relay" on instructables)

2. Following this idea you can even remote start your car if the need be!

3. You can control up to 7 car functions (if the need be)

4. You do not have to be a software wiz at all. You do need to be a hardware wiz either if all you need is to have one function (to do more look my addition in the comments)

5. I don't see the author being too interactive / helpful. No blames just stating facts

6. You may easily be able to start a lamp with this project but starting a car is a different ball game and certainly not intended here

Wesley R Tech (author)2016-07-04

Will this work with the Arduino Uno?

EricR127 (author)2016-06-08

SOS HELP HELP HELP

So I followed this tutorial step by step until he got to the lamp. I had the GSM controller working fine. The corresponding LED would light when I sent the appropriate text message. Then, I decided to add an LED display(with buttons), mounted right on top of the relay. In the code, I added simple lcd prints that would output the text message on the LCD. After compiling and uploading my code, something made a loud buzzing noise. I immediately killed the power. Now, when I send text messages, the corresponding LED on the relay does not light up. It my be noteworthy that the relay still works manually. PLEASE PLEASE help.

Thanks in advance.

kevanar (author)2016-03-10

im wondering if you can help me...... Im using the arduino uno r3 and when I send the text message it do anything..... I already check the serial monitor..... and if I send the message AT+CMGR=1 and then the second message it appears AT+CMGR=2 and so on and so on..... can you help me please? :)

RonM79 (author)kevanar2016-03-29

Wondering if anyone has solved the problem many of us are having with this sketch. I also get the AT+CMGR printout on the serial monitor, but sending the "ona" sms to the shield does nothing. Thanks, Ron

Fezder (author)2016-03-03

Just when I was wondering whether It's possible, I found this. Thanks for sharing, gotta test this out!

dvillanueva5 (author)2016-02-20

How can you automatically delete sms ?

Nazim1707 (author)2016-02-03

Everything is okay..I programme arduino. ..then what is that you put void processgprsmsg() and void processsms() ? Sir I kindly request you. .can you tell me pls?

BraamV1 (author)2016-01-16

Hi All this is an awesome project, i am going to be building this today, but i do not have an arduino, i'll be using an gsmcommander from gsmcommander.com awesome product.

AlexisM9 (author)2015-11-27

Good Day. Sir. I would like to create the same project using Arduno Mega 2560 and Sim900d GSM shield. I also want to have a feedback message so that the user will know the status of the device. But I dont want to use any sensor. Is it possible that I can check the status of the device by using only the logic from the Arduino?

The20796. (author)2015-11-15

How can i make this work on a SIM900D based gsm shield? I seem to get stuck on the AT+CMGF=1 printout on the serial monitor.

tasosep (author)2015-11-05

The code is only if you send the commands through serial port. What commands can we use to send the sms from cell phone??

MortenD1 (author)2015-10-06

Hi.

I have an Arduino board mega 2560 and a sim900 gprs board.

Can you help with setup, how the two should be connected.

and what changes should be made in your program to the two can talk?

Elecrow (author)MortenD12015-10-16

The program should be the same. You can have a test first.

MotoBean (author)2015-09-13

wouldn't it be possible to say turn on or off a computer with a 860 watt power supply - by attaching the device to the power switch instead of the power supply?

VinodhT (author)2015-08-29

thanks a lot...can you please tell me how to control using gprs rather than sms

Glenn Hornibrook (author)2014-11-26

Hello,

I have bought the items linked on this thread. I uploaded the sketch successfully using Arduino IDE. I followed all the steps but the module does not receive the SMS. When I put the SIM into a phone, the phone does receive the text. Can you please help?

Glenn.

Since my last post I have gotten the GSM module to receive SMS.

It tried the sketch again but the relay does not turn on.

Can you help with this please?

Elecrow (author)Glenn Hornibrook2015-08-28

Hi Glenn Hornibrook, You can test the voltage of the relay control pin to have a look.

Iqrar AliS (author)2015-01-06

its not receiving the sms . what should i do?

Elecrow (author)Iqrar AliS2015-08-28

You can test it on serial monitor on the computer to have a look that whether the short message is received or not.
The is the wiki page using the gprs shield http://www.elecrow.com/wiki/index.php?title=GPRS/GSM_Shield_v1.0

225 awesome5 (author)2015-01-09

I have used ardiuno uno R3 but when I send ona or onb ect. nothing happens please help

Elecrow (author)225 awesome52015-08-28

Hi 225 awesome5, You can test it on serial monitor on the computer to have a look that whether the short message is received or not.

SirA1 (author)2015-01-08

hi .. i want to know , i wanna make a project to turn on the lamp in the house while im not at the house .. but , if i wanna make sure the light is turn on , can i receive sms from the device to my phone to prove the light is turn on ..

Elecrow (author)SirA12015-08-28

And it is really a great idea.

Elecrow (author)SirA12015-08-28

I think that it is ok. you can add a light sensor or current sensor on this project.

danrose (author)2015-01-11

Please give me the code . Iam also doing this project.i collected the componen.please give the code

Elecrow (author)danrose2015-08-28

You can download the code at the step 4 upload the program

logan.smr (author)2015-02-25

Please upload the code of entire project please!! i am doing the same experiment

My email id: lokeshrrs@gmail.com

i would be obliged if i have been helped!!

Thank u!!

Elecrow (author)logan.smr2015-08-28

You can download the code at the step 4 upload the program.

Fateen74 (author)2015-02-26

Can I use Arduino Uno?

Elecrow (author)Fateen742015-08-28

Yes, The Crowduino atmega328 is Arduino UNO compatible.

Tuli_92 (author)2015-07-19

can i have the code please?

miola001@gmail.com

Elecrow (author)Tuli_922015-08-28

There is a download link at the step of upload program

Tuli_92 (author)2015-07-20

hello. does this use the hardware serial?

Elecrow (author)Tuli_922015-08-28

Yes.

marsekal (author)2015-06-16

good job mr

MaheshG3 (author)2015-05-25

#include "SIM900.h"
#include <SoftwareSerial.h>

#include<string.h>

#include<stdlib.h>

//If you want to use the Arduino functions to manage SMS, uncomment the lines below.
#include "sms.h"
SMSGSM sms;
char num[20],tex[160];
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];

char number[20];
char sende[20]="+919032987470"; // Athenticator mob
char message[180];

char pos;
char a[10];
int i=0,m,p;

void clockwise()

{

;

}


void anticlockwise()

{

;

}


void stop()

{

;

}

int count=0;

void setup()
{
//Serial connection.
Serial.begin(9600);
Serial.println("GSM Based Stepper motor Controling\n");
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(2400)){
Serial.println("\nstatus=READY");
started=true;
}
else Serial.println("\nstatus=IDLE");

/**** stepper motor pins activating ****/
pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
pinMode(pin3,OUTPUT);
pinMode(pin4,OUTPUT);

};//setup()

void clearbuf(char *b)// clearing the buffer
{
while(*b)
*b++='\0';
}


void loop()
{
int r;

pos=sms.IsSMSPresent(SMS_UNREAD);// we can check msg recvd or not

delay(1000);

if((int)pos>=0&&(int)pos<=20){

Serial.print("POS=");

Serial.println((int)pos);

message[0]='\0';

sms.GetSMS((int)pos,number,message,180);// getting the num&mesg
delay(500);
//Serial.println(number);
//Serial.println(message);
delay(3000);

if(number[0])// if number recived or not checking
{
p=strcmp(number,sende); //checking the number

if(!p)// if known number
{
Serial.println("Authorised Person\n");
Serial.print("Mobile Number: ");
Serial.println(number);
Serial.println(" ");
Serial.print("Message: ");
Serial.println(message);
Serial.println(" ");

m=atoi(message);// converting string/char to integer
r=m*510;
// Serial.print("Rotations: ");
// Serial.println(r);
if(m>=0)// checking Clockwise
{
Serial.println("clock wise");
Serial.println(" ");
clockwise(r);
stop1();
Serial.print("rotations:" );
Serial.println(m);
Serial.println(" ");
}
else// checking AntiClockwise checking
{
Serial.println("Anticlock wise");
Serial.println(" ");
anticlockwise(r);
stop1();
Serial.print("rotations:" );
Serial.println(m);
Serial.println(" ");
}
}//if(!p)
else//if unknown number recived
{
Serial.println("Un Authorised Person\n");
Serial.print("Mobile Number: ");
Serial.println(number);
Serial.println(" ");
Serial.print("Message: ");
Serial.println(message);
Serial.println(" ");
Serial.println("Operation not Alloted\n");
}
}//if(number[0])
}//if(pos)
/* else // if messages more than 20 then deleted
{
for(pos=0;pos<20;pos++)
{
sms.DeleteSMS((int)pos);
Serial.println("All Messages Deleting......");
Serial.println(" ");
}
pos=0;
}*/

delay(1000);
/*** clearing all variables***/
sms.DeleteSMS((int)pos);
Serial.println("Message Deleted\n");
clearbuf(message);
clearbuf(number);
p='\0';
m='\0';
r='\0';
delay(2000);
}//loop()

MaheshG3 (author)2015-05-25

ganeshkumar2111 (author)2015-02-26

hai friends iam ganesh. plz help for my project . any one for write the program for control one relay using GSM module (sim900). progarm form msg is given to some text is diplay.

VisakhVasudevan (author)2015-02-11

Hi Team,

What i have to do to register a particular mobile number otherwise anybody can hack the device na...?

About This Instructable

456,454views

596favorites

Bio: Elecrow is an open hardware facilitation company based in Shenzhen. We integrate resources to serve new era of innovation. To make your making and innovation ... More »
More by Elecrow:Easiest Arduino Smart Plant WateringDIY Halloween Haunted House (Arduino Project)Arduino sunflower - An electronic sundancer
Add instructable to: