GSM Modem with Arduino UNO

How to send an SMS using GSM Modem connected to Arduino UNO

Components Required:
1. Arduino UNO
2. GSM/GPRS Modem (In this I have used SIM900 Module)
3. PC/Laptop
4. Connecting wires and USB cable for connecting Arduino to PC.

Connection Diagram:
For Code Without using Library files:

For Code With Using Library files:
Because the library files for GSM Shield are defined with software serial with Rx as Pin2 and Tx as Pin3 by default, which we can change if we require in the GSM.cpp file inside the library folder.

Code:
Without using Library files:

void setup()
{
  Serial.begin(2400);  //Baud rate of the GSM/GPRS Module 
  Serial.print("\r");
  delay(1000);                  
  Serial.print("AT+CMGF=1\r");    
  delay(1000);
  Serial.print("AT+CMGS=\"+91944xxxxxx8\"\r");    //Number to which you want to send the sms
  delay(1000);
  Serial.print("Test SMS -Jay\r");   //The text of the message to be sent
  delay(1000);
  Serial.write(0x1A);
  delay(1000); 
}
void loop()
{
}


With using GSM Library file:
#include "SIM900.h"

#include <SoftwareSerial.h>

#include "sms.h"

SMSGSM sms;

void setup()
{
  Serial.begin(9600);
  Serial.println("GSM Testing to send SMS");
  if (gsm.begin(2400)){
    Serial.println("\nstatus=READY");
    started=true; 
  }
  else Serial.println("\nstatus=IDLE");
 
  if(started){
    if (sms.SendSMS("+919********8", "Arduino SMS"))// number to which you want to send the sms and the sms text//
    Serial.println("\nSMS sent OK");
  }
};
void loop()
{
};


Note: 
The GSM Library can be downloaded from the link below:
https://code.google.com/p/gsm-shield-arduino/downloads/list

Video Demo of the Project:


Credits:
Marco Martines and Boris Landoni for the GSM/GPRS Library for SIM900 GSM Module










58 comments:

NRK said...

Hello sir, my name is nitin i have looked at your video and the code. i have got few questions to ask you?
1)Can you plz upload the pin diagram of the sim 900 gsm module, and also the connection diagram related to the arduino uno r3 board.
2)in my project iam connecting a ultrasonic sensor hc sr04 placed on a servo motor, which is connected to a motor shield placed on uno board,so will there be a problem of overlapping of the pins if i connect a gsm module also?

Jayakarthigeyan said...

You can get the pin diagram and other details of the module with user manual in the link given below:
http://www.simcom.us/product_detail.php?cid=1&pid=37
Scroll to the bottom of the page to get the download link.

But I want to know weather you are using a module alone, or a ready made modem with UART converter or RS232 Converter. Then the connections will change accordingly. Let me know what product you are using, if you bought it online, comment the product link so that I can help you out.

And about servo shield on UNO board,
if you are not using the pins that you have defined as serial Rx and Tx for interfacing the GSM module for controlling the servo then there wont be any problem, if you write the program with two pins defined for different operations, then you will automatically get an error while compiling itself...

NRK said...

Actually my project is ultra sonic security system with sms notification ie; the ultrasonic sensor is rotated by the servo motor, and when an object is detected the arduino board sensds an sms to the user via the gsm module sim 900.
Components used:
1) ultrasonic sensor HC SR 04
2) servo motor
3) motor shield(not the arduino one, but prep in collg)
4) gsm module sim 900( i want to use the module what u have used)....so plz help me out

Jayakarthigeyan said...

Ok I understand your project, mail me the schematic of your motor shield that you have developed. And please understand the difference between a module and a modem... Do you have a sim card holder and pins for input supply and interfacing with arduino... Or just the module alone with which you have to connect the sim card holder and then make pin connections for level converters... From where did you buy the module or the modem... Because different modems have different pin connection...

NRK said...

Ok then i will email you the schematic of the motor shield iam using.
I didn't buy any modem or module still....plz post the link from which you bought your gsm modem which has an in bulit rs 232 converter....

Jayakarthigeyan said...

http://www.rhydolabz.com/index.php?main_page=product_info&products_id=1080
This is the link of the GSM Modem that I have used in the video. Arduino Uses TTL Logic, so for direct and easy interfacing with Arduino, this is the best one, don't confuse RS232 with TTL. Google about it and get clear information about it...

NRK said...

i emailed you the schematic of my motor shield...plz compare with the gsm shield and tell me if any of the pins are coinciding or not.....

NRK said...

Hey can u just tell me the connections for the arduino and gsm modem, its not clear in your video, plz tell me what all pins on gsm modem are connected to the arduino and other pins etc....

NRK said...

hey can plz tell me the connections between the arduino and the sm modem, beacuse its not clear in t video, plz tell me what all pins on arduino are connected to the gsm modem and other pin connections

Jayakarthigeyan said...

Which GSM modem have you bought. See the connection is simple, the Tx of GSM modem connected to Rx of Arduino and Rx of GSM modem connected to Tx of arduino. And the Vcc of GSM is connected to 5V and similary Gnd of GSM modem to Gnd of arduino. If you tell me which GSM modem you are using. I can help you out easily and clearly.

Jayakarthigeyan said...

with respect to conditional statements, if you want to send the sms, you can use the code below, that will send the sms when digital pin 13 reads a HIGH value:

Code:
int x=13;
void setup()
{
Serial.begin(2400); //Baud rate of the GSM/GPRS Module
Serial.print("\r");
delay(1000);
pinMode(x, INPUT);
}
void loop()
{
if(digitalRead(x) == HIGH)
{
Serial.print("AT+CMGF=1\r");
delay(1000);
Serial.print("AT+CMGS=\"+91944xxxxxx8\"\r"); //Number to which you want to send the sms
delay(1000);
Serial.print("Test SMS -Jay\r"); //The text of the message to be sent
delay(1000);
Serial.write(0x1A);
delay(1000);
}
else
{
Serial.print("AT\r");
}
}

Moothiringode said...

Yes,sir. I will try that. It looks short and sweet.
Thanks a lot.
Subramanian.M.N.

Moothiringode said...

Thank you. I will try that.
Subramanian.M.N

NRK said...

I have made the following connections with arduino uno r3 board and sim 900 ttl modem from rhydolabz..............gnd of modem is connected to gnd of the arduino ,rxd of modem to txd of arduino, txd of modem to rxd of arduino...and V interface of modem to 5v pin on arduino....now i also have to connect the gnd and vin(5v) pins on gsm modem..without which no leds blink on the modem...so now should i give a external power supply to these pins....if yes...will it be ok to give 9v external power supply...

Jayakarthigeyan said...

Yes, you can give 9Volt supply...

Unknown said...

hi sir,i have interfacing code for arduino uno and adxl345 acceleromter
and also i have interfacing code for arduino uno and gsm sim 900.i donow how to run as one full code.will u help me sir?

Jayakarthigeyan said...

priyanka vijayakumar, I'll try my level best to help you.. But I haven't worked with accelerometers yet... But I'll try to help you if you say, what project you want to make, give me some description about the project that your are making by integrating accelerometers and gsm modem... Mail me the codes that you want to integrate...

NRK said...

Iam having a small problem when implementing the code....on the serial monitor window ie; where u receive the outputs, iam just receiving one message " GSM testing to send sms"....i have waited for about min or 2...and i didnt receive any message from the gsm modem....so what shud i do...shud i change the baud rate in the gsm.begin function...plz tell me what to do...and also after uploading the code or before uploading the code what all changes did u make..??

Jayakarthigeyan said...

NRK... Did you try changing the baud rate... First tell me weather your sim card got connected to the network or not... It can be identified by the flickering of the blue light in the modem... Read the manual of the GSM Modem for more info...

Abhishek said...

Sir, Can I use arduino uno for SMS based moving message display on LED board(8x96 matrix)with 140 words scrolling capacity.

I have fargo 20 GSM modem(RS232 interface)

I am really very confused what to do. Which arduino to go for? also tell me If it can be done without arduino.

most importantly what kind of LED matrix to use.

Jayakarthigeyan said...

Abhishek, SMS based moving message display can be done using Arduino, but you will face some difficulties while doing it. I am also working on something similar, reading an SMS using GSM Modems has delay issues and SIM Storage problems, I am working one that, but many people are sending mails to me asking doubts in various domains, so it is a bit difficult for me to reply to everyone give detailed information from scratch. Do, some search in google, it will help you out and Fargo 20 is a RS232 interface so, you will need a RS232 to TTL Converter to interface it with Arduino. I'll get back to you on when I solve the delay problem, or when get solution from somewhere. All the best to do your project...

adrita said...

Hello sir,
my project is based on ultrasonic distance measurement sensor. I programmed the arduino to find the exact range of the subject at a distance.now i have to send the exact distance of the subject (output that i get in the serial monitor) as an sms to my mobile phone.

can you please help me out , how to do the same.can you please tell me step wise how to connect the arduino uno and the gsm module sim 900.

adrita said...

hello sir,
i am doing a project to find the exact distance of a subject. here i am using the ultrasonic distance measurement sensor. i already did the coding part in the arduino to fond the distance. now the output that i get in the serial monitor ( the distance), i need to send it as an sms to my mobile.

can you help us out how go about it.how to connect the arduino uno and gsm module sim 900?

adrita said...

also i have this doubt that how will i upload two codes( one is the code to find the distance using the sensor and the second code will be connecting gsm code)in the arduino uno board. very confused with the connections. please tell me step wise.. will be very grateful.

adrita said...

how to send the output that is displayed in the serial monitor as an sms.?

Unknown said...

Hello sir,
please i am doing a project on vehicle tracking system using arduino nano Atmega328 and Siemens GSM/Gprs Modem TMA- M39i which is a RS232 serial interface.
The problem i have is that i cannot send sms message message to my phone with the arduino code i have written but when i test the Gsm modem and arduino on hyper terminal they both work ok.
i have tried connecting a common ground from the RS232 to TTL converter to my the arduino nano and still did not get the message on my phone.
i have been advice by my supervisor to Hard-wire the RS232 from the modem to TTL converter but i dont know how to do this, could you pls advice me how i can achieve this task thanx!

Unknown said...

Hello sir,
please i am doing a project on vehicle tracking system using arduino nano Atmega328 and Siemens GSM/Gprs Modem TMA- M39i which is a RS232 serial interface.
The problem i have is that i cannot send sms message message to my phone with the arduino code i have written but when i test the Gsm modem and arduino on hyper terminal they both work ok.
i have tried connecting a common ground from the RS232 to TTL converter to my the arduino nano and still did not get the message on my phone.
i have been advice by my supervisor to Hard-wire the RS232 from the modem to TTL converter but i dont know how to do this, could you pls advice me how i can achieve this task thanx!

adrita said...

please tell me how to connect to a arduino if i am using GSM module sim 300 RS232 logic

Jayakarthigeyan said...

Mcmmanuel and adrita, to connect an RS232 based GSM Modem to Arduino, you have to buy a RS232 to TTL Converter which will give you Rx and Tx which you have to connect to the Arduino...

Unknown said...

Great thanks to you sir.... This is very helpful post for me. I am working on project of sms based farm watering system. If possible plz upload code for reading message when it receive.

Unknown said...

Hello sir, my partner and I are trying to send an sms just like you show at your blog yet we can't. we keep geting this: GSM Testing to send SMS
Trying to force the baud-rate to 9600

ERROR: SIM900 doesn't answer. Check power and serial pins in GSM.cpp

status=IDLE
we use a very similar shield:http://www.ebay.com/itm/261032737732?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649
can you please check it and tell what we are doing wrong? Thanks in advance

Jayakarthigeyan said...

Felipe Refender, did you try using baudrate 2400...

Technodict said...

i have one of the similar gsm modules.. can these be used for internet access on a laptop using the data plan on the sim card?

Unknown said...

Hi again,
Yes I tryed it exactly as you posted above, with the libraries and baud rate at "serial begin(2400). The "Trying to force baud rate to 9600" appears about a minute after "GSM testing to send SMS" appears in my serial monitor.

Subir Nath said...

Sir I have visited your blog and i have implemented the code without using library files using ardunio uno and sim 900 rs232 gsm modem. But after writing the code I am unable to send sms from gsm to any other number. Sir plz help me how to do this.

--
Subir Nath

Unknown said...

how to compile gsm.cpp??because i want to change pin of TX and RX to pin 0 and 1

Unknown said...

how to compile gsm.cpp??i want to change pin RX and TX to pin 0 and 1...

Unknown said...

hello bro...
can you give me the circuit for this project ?? thank you...

Unknown said...

can you give to me the circuit for this project ?? thank you..

Unknown said...

Hi , why do we need a RS232 converter for a ready made modem?

Unknown said...

Hi. Can you post the sms receiving code. I tried a lot on google but not able to find it. You are my last hope. Thank you.

Unknown said...

hi sir.. your code works like a charm.. thanks you very much..

i have another problem.. controlling digilat pins when the gsm modem recieves a certain message.. for ex.. when the gsm modem recieve a message ("light led") the led on digital pin 4,5 will light up..

hope you can help me.. thank you

Unknown said...

hi sir.. your code works like a charm. thank you..

Unknown said...

Hello Sir,
I am using arduio uno to measure the temperature from rtd (pt 100)for the project, i want to monitor it using sms based data logger and i am going to get the gsm module that you have suggested in the video. the problem is i want to get the temp. reading automatically with in the interval of 10 min. i wandering about the program for it because i am new in c++, sir, can you please help me sir?
Thank You.
kiran

Unknown said...

Will i able to control status of any pin with the help of received sms on arduino from any cell phone.

Unknown said...

HII DEAR,
i want to send URL with variabil for example
"http://maps.google.co.uk/maps?hl=en&ll= AND "

HOW CAN MAKE THIS THANK YOU

Unknown said...

hi sir..i want to know the concept of software serial in arduino..thnkz advance.

Unknown said...
This comment has been removed by a blog administrator.
Jayakarthigeyan said...

omar talal ,

Its simple, add the variables value with the string in the format you want and send the string as a text message...

Jayakarthigeyan said...

tanmay shinde,

Yes it is possible.

Unknown said...

Sir,
I am facing problem in sending sms to my mobile no. using gsm module of simcom sim900 series using arduino uno.I have connected tx of gsm to Rx of arduino, Rx of gsm to Tx of arduino.I am taking +5v an gnd of gsm from arduino. I have connected 9V battery to gsm.Sir please suggest me a code for sending sms to my mobile no. and tell me if there is any problem in the connection..please help asap.

Jayakarthigeyan said...

Try powering your modem with a 9V, 1A power supply adapter.

Unknown said...

Sir,
Thanks for the help.My gsm started working.But I am facing problem in interfacing LCD (JHD 162a) with arduino uno.My connection is-
-Pin 1(LCD) to GND.
-Pin 2(LCD) to +5V
-Pin 3(LCD) to potentiometer(10k)
-Pin 4(LCD) to arduino PIN 12
-Pin 5(LCD) to GND
-Pin 6(LCD) to arduino PIN11
-Pin 11(LCD) to arduino PIN5
-Pin 12(LCD) to arduino PIN4
-Pin 13(LCD) to arduino PIN3
-Pin 14(LCD) to arduino PIN2
-Pin 15(LCD) to +5v through 220 ohm resistor
-Pin 16(LCD) to GND
Nothing appears in the second row of my LCD and black boxes appears in the first row.Please help.

Unknown said...

Sir,
I am trying to send sms from my simcom gsm sim900 module. I burned the same program (without using library file) as you mentioned above.But I am able to receive any sms to my cell no..My gsm is catching signal strength properly.Sir please help me out.

Jayakarthigeyan said...

Aditya Kumar Giri

First check your LCD with Arduino with the help of Arduino with LCD tutorial available at Arduino Website...

Joe said...

hi sir, im using the coding without library. I am trying to send two consecutive sms's by duplicating some of the command. I want the sms to be sent to two different numbers, but it failed, it only was only sent to the first number. any idea how sir? thanks..

Jayakarthigeyan said...

+Joe , try giving a delay of 5 to 10 seconds after sending the first message, then start executing the commands for the second sms...

Code is, just add a line of delay(5000); or delay(10000); between the command sets for sending sms...

Aashijit and Biswapriya said...

Hello Sir,
I am Aashijit. I loved this tutorial. It was really helpful.