How to Receive SMS Using GSM Modem

In this post we are going to learn through a comprehensive tutorial, how to receive SMS using GSM modem, and Arduino.

By: Girish Radhakrishnan

In one the previous post we learned how to send a text message using GSM modem and also discussed the basics the GSM modem. If you haven’t checked it out yet, here is the link:

How to Send SMS Using GSM Modem and Arduino

In this post we will discuss regarding how to receive SMS via serial monitor of the arduino IDE. We are not only going to receive SMS but, also send text message by pressing different keys. For an instant, pressing “s” will send pre-enter text message, pressing “r” will receive real time SMS.

Here is author’s prototype:


How it Works



The circuit for receiving SMS using a GSM moden is very simple, you just need 3 male to female header pins. The TX of GSM modem is connected to pin #9 of arduino and RX of GSM modem is connected to pin #8 of arduino and the ground to ground connection is also given between GSM and arduino.

Always use external power supply for GSM modem, don’t connect 5Vcc from arduino to GSM modem, as there is good chance of overloading the voltage regulator of arduino.

Don’t forget to implement SMS rate cutter or something similar on your SMS subscription for reduction on your SMS expenses.

Otherwise you will end up empty account balance after sending several SMS, since there won’t be any acknowledgement from your cellular provider after every sent SMS, as the SIM card is in the GSM modem.

The only acknowledgement you get is warning SMS, regarding your empty account, so be cautious about you expenses. Now let’s move to coding part this project.

Program:


//-----------------Program developed by R.Girish-------------//
#include <SoftwareSerial.h>
SoftwareSerial gsm(9,8);
void setup()
{
gsm.begin(9600);   // Setting the baud rate of GSM Module
Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
delay(100);
}
void loop()
{
if (Serial.available()>0)
switch(Serial.read())
{
case 's':
Send();
break;
case 'r':
Recieve();
break;
case 'S':
Send();
break;
case 'R':
Recieve();
break;
}
if (gsm.available()>0)
Serial.write(gsm.read());
}
void Send()
{
gsm.println("AT+CMGF=1");
delay(1000);
gsm.println("AT+CMGS="+91xxxxxxxxxx"r"); // Replace x with mobile number
delay(1000);
gsm.println("Hello I am GSM modem!!!");// The SMS text you want to send
delay(100);
gsm.println((char)26); // ASCII code of CTRL+Z
delay(1000);
}
void Recieve()
{
gsm.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
delay(1000);
}
//-----------------Program developed by R.Girish-------------//



Entering the Phone Numbers




Enter the recipient phone number on “xxxxxxxxxxx” in the program with your country code at the beginning.

Enter the text that you want to send in the program within the quotation mark:  gsm.println("Hello I am GSM modem!!!"); // The SMS text you want to send

Compile the program and upload to arduino.


Insert the SIM card and power the GSM modem with external power supply and press the power button for 3 seconds (depending the model), wait for 10 to 20 seconds to establish mobile network, the network LED should blink once in every 3 seconds. If everything is stated above is done, we are ready to go for next step.

Now open serial monitor and press “r” the GSM modem is ready to receive SMS. Now send a text message from any mobile phone to number of the SIM which is inserted on GSM modem.
The text message should pop up on the serial monitor, something similar to illustrated below:




The “Hello world” is the message sent to GSM modem and the number from which the text message is sent also displayed.

Now, let send SMS to the pre-entered number in the program with pre-entered message. Press “s” and you will see something similar illustrated below: The sent SMS is “Hello I am GSM modem”.



Now, you know how to send and how to receive SMS using GSM modem.

Need Help? Please send your queries through Comments for quick replies! And please Bookmark my site :)




Comments

Sharoj Al Hasan said…
Sir
I want to drive a FM transmitter circuit wich required 3-5 v to drive this circuit. But Sir my power supply is 9v battery. Sir please help me to use this circuit from my 9v battery.
Swagatam said…
Sharoj, you can use a 7805 IC and a series 1N4007 diode at its output to drop the 9V to the desired limit....
Sharoj Al Hasan said…
Sir give me the diagram please............
Swagatam said…
please refer to IC 7805 datasheet...
sathya said…
hello sir a small doubt sir
what is the difference between the project that you have shown here and the existing system sir..?????
may i know it sir..please!!!!!!!!!
Swag said…
Hello Sathya, which existing system are you referring to? The previous system was actually regarding the transmitter, while this is regarding the receiver....
Sathya said…
I would like to know the info about first developed system based on arduino and the system u have explained here Sir..!!
Like we will be going for new system if one system fails so...in the same way the project that u have brought up here must be having any modifications in the previous system..and that's what im asking for..Sir!!
Swag said…
You mean to say if something upgrades in future or becomes obsolete how would you be able to tackle those situations?....Mr.Girish will be able to answer this better, I'll forward this question to him.
Crash said…
Hi, tried and worked on a SIM808 module. Had to make a small change in code
Original:
gsm.println("AT+CMGS="+91xxxxxxxxxx"r"); // Replace x with mobile number

modified:
gms.printIn("AT+CMGS=\"+91xxxxxxxxxx\"\r";// Replace x......
Swag said…
Thanks Crash, for updating the modification, appreciate it a lot!

Contact me for Customized Circuits

Name

Email *

Message *


 Follow on G+  Follow on Facebook   Follow on Tweeter  Follow on G+  Follow on G+

Follow Homemade Circuits