In this article, we are going to see how to interface the GSM Module with Arduino. There are different kinds of GSM modules available on the market. We are using the most popular module based on Simcom SIM900 and Arduino Uno for this tutorial. Interfacing a GSM module to Arduino is pretty simple. You only need to make 3 connections between the gsm module and Arduino. So let’s get to business!
A GSM Module is basically a GSM Modem (like SIM 900) connected to a PCB with different types of output taken from the board – say TTL Output (for Arduino, 8051 and other microcontrollers) and RS232 Output to interface directly with a PC (personal computer). The board will also have pins or provisions to attach the mic and speaker, to take out +5V or other values of power and ground connections. These types of provisions vary with different modules.
Lots of varieties of GSM modems and GSM Modules are available in the market to choose from. For our project of connecting a gsm modem or module to Arduino and hence sending and receiving SMS using Arduino – it’s always good to choose an Arduino compatible GSM Module – that is a GSM module with TTL Output provisions.
Do you like to do a beginners course on Arduino with 12+ Projects?
We have published an exciting course on Arduino named “Arduino Course [Zero to Hero] – Learn By Doing Projects”. The course is published in partnership with Udemy – the world’s best online education platform. If you are looking to master Arduino and develop a couple of really exciting projects using the Arduino platform, enrolling in this course would be the best decision you can make to achieve your dreams. So let’s take a quick look at what you will learn in this course.
Our course “Arduino Course [Zero to Hero]” follows a complete learn by doing approach, where you will be learning each and every concept by doing a project. The course is designed with 12+ projects ranging from easy, medium, and advanced projects. The course begins by introducing basic concepts and simple led based projects, and then moves on to explain mid-level concepts like sensor interfacing, sensor-based projects, and finally, the course teaches you how to do advanced projects and IoT (Internet of Things) based projects using the Arduino platform.
You will do the following projects in this full video course:
- Automatic Hand Sanitizer/Soap Dispenser
- Automatic Light Control using LDR
- Generating Patterns with LEDs
- Smart Door Lock using Keypads (Digital Code Lock)
- Home Security System (Protect against Fire accidents, Gas leakage,)
- Weather Monitoring System (Measure Temperature & Humidity)
- Home Automation using Smartphone & TV Remote Control
- Line Follower Robot (the basics to build robots)
- Obstacle Avoidance Robot (learn to build intelligence in robots)
- Mobile Phone controlled Robot Car (wireless controlled robots)
- Smart Irrigation System
- IoT based Weather Station (Display weather data on website/web application)
Notes on GSM Module
1. We use SIM900 GSM Module – This means the module supports communication in the 900MHz band. We are from India and most of the mobile network providers in this country operate in the 900Mhz band. If you are from another country, you have to check the mobile network band in your area. A majority of United States mobile networks operate in the 850Mhz band (the band is either 850Mhz or 1900Mhz). Canada operates primarily on the 1900 Mhz band. Please read this wiki entry on GSM Frequency Bands around the World.
2. Check the power requirements of the GSM module – GSM modules are manufactured by different companies. They all have different input power supply specs. You need to double-check your GSM module’s power requirements. In this tutorial, our gsm module requires a 12 volts input. So we feed it using a 12V,1A DC power supply. I have seen gsm modules that require 15 volts and some other types which need only 5 volts input. They differ with manufacturers. If you are having a 5V module, you can power it directly from Arduino’s 5V out.
Note:- GSM Modules are manufactured by connecting a particular GSM modem to a PCB and then giving provisions for RS232 outputs, TTL outputs, Mic and Speaker interfacing provisions etc. The most popular modem under use is SIM 900 gsm modem from the manufacturer SIMCom. They also manufacture GSM Modems in bands 850, 300 and other frequency bands.
3. Check for TTL Output Pins in the module – You can feed the data from the gsm module directly to Arduino only if the module is enabled with TTL output pins. Otherwise, you have to convert the RS232 data to TTL using MAX232 IC and feed it to Arduino. Most of the gsm modules on market are equipped with TTL output pins. Just ensure you are buying the right one.
So that’s all about the gsm module basics. Now let’s power it up!
GSM Module – Buyers Guide – are you looking to buy a GSM module? There are a handful of product variants for GSM module – like SIM900, SIM300, SIM800 etc. We have created this buyers guide to help you select the right GSM module for your project needs.
Booting the GSM Module!
1. Insert the SIM card into the GSM module and lock it.
2. Connect the adapter to the GSM module and turn it ON!
3. Now wait for some time (say 1 minute) and see the blinking rate of ‘status LED’ or ‘network LED’ (GSM module will take some time to establish a connection with mobile network)
4. Once the connection is established successfully, the status/network LED will blink continuously every 3 seconds. You may try making a call to the mobile number of the sim card inside the GSM module. If you hear a ring back, the gsm module has successfully established a network connection.
Okay! Now let’s see how to connect a gsm module to Arduino!
Connecting GSM Module to Arduino
There are two ways of connecting the GSM module to Arduino. In any case, the communication between Arduino and GSM modules is serial.
1. Without SoftwareSerial Library
2. With SoftwareSerial Library
Method 1
If you are going with the first method, you have to connect the Tx pin of the GSM module to the Rx pin of Arduino and the Rx pin of the GSM module to the Tx pin of Arduino. You read it right? GSM Tx –> Arduino Rx and GSM Rx –> Arduino Tx.
Now connect the ground pin of Arduino to the ground pin of the gsm module!
So that’s all! You made all three connections and the wiring is over! Now you can load different programs to communicate with the gsm module and make it work.
Note:- The problem with this connection is that, while programming Arduino uses serial ports to load programs from the Arduino IDE. If these pins are used in wiring, the program will not be loaded successfully to Arduino. So you have to disconnect wiring in Rx and Tx each time you burn the program to Arduino. Once the program is loaded successfully, you can reconnect these pins and have the system working!
Circuit diagram of interfacing GSM module with Arduino(without using the library)
Arduino code for Circuit diagram of interfacing GSM module with Arduino(without using the library)
void setup()
{
Serial.begin(9600);
delay(100);
}
void loop()
{
if (Serial.available()>0)
switch(Serial.read())
{
case 's':
SendMessage();
break;
case 'r':
RecieveMessage();
break;
}
if (mySerial.available()>0)
Serial.write(mySerial.read());
}
void SendMessage()
{
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // Replace x with mobile number
delay(1000);
mySerial.println("I am SMS from GSM Module");// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void RecieveMessage()
{
mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
delay(1000);
}
Method 2
To avoid the difficulty mentioned above, I am using an alternate method in which two digital pins of Arduino are used for serial communication. We need to select two PWM enabled pins of Arduino for this method. So I choose pins 9 and 10 (which are PWM enabled pins). This method is made possible with the SoftwareSerial Library of Ardunio. SoftwareSerial is a library of Arduino which enables serial data communication through other digital pins of Arduino. The library replicates hardware functions and handles the task of serial communication.
I hope you understood so far! Let’s get to the circuit diagram! So given below is the circuit diagram to connect the gsm module to Arduino – and hence use the circuit to send SMS and receive SMS using Arduino and gsm modem.
Circuit diagram of interfacing GSM module with Arduino(without library)
Arduino code for Circuit diagram of interfacing GSM module with Arduino(with using the library)
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 10);
void setup()
{
mySerial.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':
SendMessage();
break;
case 'r':
RecieveMessage();
break;
}
if (mySerial.available()>0)
Serial.write(mySerial.read());
}
void SendMessage()
{
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // Replace x with mobile number
delay(1000);
mySerial.println("I am SMS from GSM Module");// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void RecieveMessage()
{
mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
delay(1000);
}
The program has two objectives as described below:-
1) Send SMS using Arduino and GSM Module – to a specified mobile number inside the program
2) Receive SMS using Arduino and GSM Module – to the SIM card loaded in the GSM Module.
so that’s the program/code to make Arduino send SMS and receive SMS using the gsm module! Let’s get to the explanation of the program!
The Program Explanation
We begin by including the SoftwareSerial library into the program. In the next line, we create a constructor of SoftwareSerial with the name mySerial and we pass the digital pin numbers as parameters. The actual format is like SoftwareSerial mySerial (Rx, Tx);
So in our code, pin number 9 will act as Rx of Arduino and 10 will act as Tx of Arduino. Let’s get to the configuration part of the program inside setup. The first task is to set baud rates of the SoftwareSerial library to communicate with the GSM module. We achieve this by invoking mySerial.begin function. Our second task is to set the baud rate of Arduino IDE’s Serial Monitor. We do this by invoking the Serial. begin() function. Both should be set at the same baud rate and we use 9600 bits/second here in our tutorial. The configuration part is over with setting baud rates and it’s good to give a small delay of 100 milliseconds.
Now let’s get to the actual program inside the loop(). To make things simpler, I have developed a user input based program. The program seeks user input via the serial monitor of Arduino. If the input is ‘s’ the program will invoke a function to send an SMS from the GSM module. If the user input is ‘r’, the program will invoke the function to receive a live SMS from the GSM module and display it on the serial monitor of Arduino. The whole program is as simple as that!
Serial. available() – checks for any data coming through the serial port of Arduino. The function returns the number of bytes available to read from the serial buffer. If there is no data available, it returns a -1 (value less than zero).
Serial. read() – Reads all the data available on serial buffer (or incoming serial data if put otherwise). Returns the first byte of incoming serial data.
mySerial.available() – checks for any data coming from the GSM module through the SoftwareSerial pins 9 and 10. Returns the number of bytes available to read from the software serial port. Returns a -1 if no data is available to read.
mySerial.read() – Reads the incoming data through a software serial port.
Serial.write() – Prints data to serial monitor of arduino. So the function Serial.write(mySerial.read()) – prints the data collected from software serial port to serial monitor of arduino.
Lets get the functions SendMessage() and RecieveMessage()
These are the functions in which we actually send commands to the GSM module from Arduino. These commands to communicate with the GSM module are called AT Commands. There are different commands to perform different tasks using the GSM module. You can read the complete AT Commands Library to understand all that is possible with the GSM module.
SendMessage() – is the function we created in our Arduino sketch to send an SMS. To send an SMS, we should set our GSM module to Text mode first. This is achieved by sending an AT Command “AT+CMGF=1” We send this command by writing this to the SoftwareSerial port. To achieve this we use the mySerial.println() function. mySerial.println writes data to the software serial port (the Tx pin of our Software Serial – that is pin 10) and this will be captured by the GSM module (through its Rx pin). After setting the GSM module to Text mode, we should the mobile number to which we shall send the SMS. This is achieved with AT command “AT+CMGS=\”+91xxxxxxxxxx\”\r” – where you may replace all x with the mobile number.
In the next step, we should send the actual content of the SMS. The end of SMS content is identified with the CTRL+Z symbol. The ASCII value of this CTRL+Z is 26. So we send a char(26) to the GSM module using the line mySerial.println((char)26); Each and every AT command may be followed by a 1-second delay. We must give some time for the GSM module to respond properly. Once these commands are sent to the GSM module, you shall receive an SMS in the set mobile number.
RecieveMessage() – is the function to receive an SMS (a live SMS). The AT command to receive a live SMS is “AT+CNMI=2,2,0,0,0” – we just need to send this command to the GSM module and apply a 1-second delay. Once you send this command, try sending an SMS to the SIM card number put inside the GSM module. You will see the SMS you had sent displayed on your Arduino serial monitor.
There are different AT commands for different tasks. If you want to read all SMSs stored in your SIM card, send the following AT Command to the gsm module – “AT+CMGL=\”ALL\”\r”
Okay! That’s all and you are done. And you have learnt how to use Arduino to send SMS and receive SMS messages with an example code.
I shall summarize this tutorial on how to send/receive a text message using Arduino and gsm module with the following notes:-
AT Commands to Send SMS using Arduino and GSM Module
AT+CMGF=1 // Set the GSM module in text mode AT+CMGS=\"+YYxxxxxxxxxx\"\r // Input the mobile number| YY is country code “the message” with stopping character (char)26 // ASCII of ctrl+z
AT Commands to Receive SMS using Arduino and GSM Module
AT+CMGF=1 // Set the GSM Module in text mode AT+CNMI=2,2,0,0,0 // AT Command to receive live sms
Read the AT commands library and start playing with your GSM module and Arduino! If you have any doubts please ask in the comments.
So that’s all about interfacing the GSM module with Arduino. If you’ve any doubts, feel free to comment.
168 Comments
Hi, pls i’ve been working on a sim800 project and been having some issues, would be glad if you could help out. The sim module sends sms normally using the example code, but for my project, it is meant to send a message to a number when the heart rate sensor detects an abnormality in the heart beat. the serial monitor shows the reading but when it is meant to send the message, it shows error CMGF. Pls i need help urgently.
sir i want to use this code to send a message,its a part of my drunk driver detection project.My target is to send a sms to registered number that the driver is drunk.Do i have to change anything from this code?IF i want to register a number number how will I do that.Please i need your help
Hiiii sir,
I am Akshay from India…….we tried ur code..but when we want to send sms we go through ‘s’ case……then on my mobile its shows <>
whats the problem sir……..
While msgs of receiving successfully done……
Connections are also correct…….
Whats the problem?????
Plzz convey solution as soon as possible
Hi sir good day. I would like to ask for help. I was able to send text messages using the above code. But my arduino uno module resets after the mySerial.println((char)26); line, prompting other codes after that line not executed. Please kindly help assess and advise.Thanks in advance.
Hi sir good day. I would like to ask for help. I was able to send text messages using the above code but my Arduino Uno module resets after executing the line mySerial.println((char)26); prompting the code to reset as well. The following codes after that line resulted to not being executed. Please kindly help assess. Thank you in advance.
Hi, how to do a code that it will not be needing user input. If someone send a text message to the module it will be automatically displayed on the serial monitor? Thanks a lot. And is someone will call, it will automatically hangup and send a message like “This is a machine”
Sir how about changing the number w/out touching the code or shall we say it has UI (application) that can change the number into a new one. Is it possible? Do you have any similar project w/ that? Badly need your thoughts for our project. 🙁
hello sir i am trying to make 360 servo motor to run continously using GSM module can you help me for that program?
hii,
good day sir! i tried to display the text that the GSM shield sends out on the serial monitor. the output was this
+CMT: “+639XXXXXXXX”,””,”16/03/02,8:31:09:+32″
hello world
but i want display only “hello world” and skip other content then what should i do ?
good day sir! i tried to display the text that the GSM shield sends out on the serial monitor. the output was this
hello world
I want to display only “hello world” and skip this >>>>
“+CMT: “+639XXXXXXXX”,””,”16/03/02,8:31:09:+32″”
what code should i use???
if i live in Cambodia, me should use how many gsm frequency rang ?
Sir,
I want to send this message to multiple recipients … can you help me in the code?
if the same message has to be sent for every 10 minutes what has to be done?
will the same work for SIM800A?
hello sir i want help for a program the led will turn on when the recieved message is ON,then led will turn off when the recieved message is OFF, please help me for this program.
Good day sir,
Can you send me email of takudzwa muswaka who had same doubt as mine. I want to contact with him for this problem. He contacted you at 16 Feb 2016.
Please sir help me for my project pls pls pls help
problem was
am trying to make a system that responds to any user who sends an sms command to the sim900 module using the exact step that you had provided ,but using mySerial.println(“AT+CMGS=\”+91xxxxxxxxxx\”\r”); will only allow the system to send a response to one number , how can i implement a system that responds to multiple phone numbers wich send a command to the sim900 or a function that Retrieves the phone number an from an incoming SMS message and stores it in a named array , just like the function “remoteNumber()” wich is present in the aduino “GSM.h” library .
hello sir i am working on the program to turn on the led when the recieved message is ON,and turn off the led when the recieved message is OFF.but its faling every time i tried please help me
The article is very useful with all details about connections and software.
I have followed exactly still My sim 900 a is not sending messages. kindly help where
I have gone wrong?
how can i continuously receive sms for gsm module (sim900) on my arduino uno and display it as output on led matrix
Hi sir
I am making a project in which the gsm operates the relay and by the reading of the soil moisture output the relay is turned off would you help me with the program
Hi sir
I am making a project in which the gsm is use to turn on the relay and the output reading of soil moisture the relay should turn off would you help me with the program
Hi sir,
I’m doing a project using arduino,gsm and gps.i have programmed the arduino.
But i’m confused how to include lacation information(lattitude & longitude) information in my sms along with AT command.Can you help me out please..
Sir,your way of teaching is very nice. I tried to call to the SIM inside GSM module ,I got ring back.so,its working perfectly but when I compiled, got an error (stray/242).so, could you please recorrect the code and send.
I am not receiving sms to my gsm module number it read the message which we are sending so pls me,thank u
Hello,
I am not able to receive sms on GSM module, although I am able to send a message.
When I tried on Putty, I was able to receive message from GSM modem.
Here is the code which I used.
#include
SoftwareSerial mySerial(6,7);
void setup()
{
mySerial.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’:
SendMessage();
break;
case ‘r’:
RecieveMessage();
break;
}
if (mySerial.available()>0)
Serial.write(mySerial.read());
}
void SendMessage()
{
mySerial.println(“AT+CMGF=1”); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println(“AT+CMGS=\”+919845340671\”\r”); // Replace x with mobile number
delay(1000);
mySerial.println(“I am SMS from GSM Module”);// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void RecieveMessage()
{
mySerial.println(“AT+CMGF=1”); //Sets the GSM Module in Text Mode
mySerial.println(“AT+CNMI=2,2,0,0,0”); // AT Command to receive a live SMS
delay(1000);
}
In your code where is gsm hearder file?
hiii there, your sms sending code works well but your sms receiving code doesn’t displaying any thing to the serial port could u help me out. thnakyou
I do have a question, hope you answer me. I am confused with the Arduino. Why do we need that if we can manipulate the GSM module (SIM 900) directly connected to the computer using AT commands?
i have installed my GSM module in a remote place. send me acord to automaticaly reset the gsm module when it is possible
Hello Sir.
First of all a thank you for your brilliant description.
Then to my problem. I am sitting in Sweden (not the problem…) but the sim cards here are. I’ve used simcards from Telenor on several modules also the sim900 but I cannot get any connection to the GSM net??? I am sitting close to the center in Stockholm, so connection should not be an issue, besides it worked on the A6 module. The funny part is that it sometimes work on the A6, sometimes not. On the sim900 it never worked so far. This issue is driving me mad. Any suggestions. In advance thank you.
sir the program given is working perfectly.
I want a program where i can receive a immediate reply from the GSM as soon as someone send any text to the GSM SIM.plz Help me to get this program
Thank u for all the above information,it all worked well for me.But now i wand my GSM to send a replay back whenever a particular message is being encountered.
for example;Whenever i send “hello” to my GSM it should automatically replay back with “Hi”.
Plz help me out to slove this problem.
I. have uploaded the cod3? What will I do next?
i get the receiving sms from gsm.but i didnt get sms from mobile phone to gsm..what is the p roblem and plz advice me
sir i need code for receiving message using gsm sim900+arduino uno
thanks
i use the code as above but nothing happen it just display s in serial monitor but does not send the message
can i use arduino mega in place of arduino uno
how to receive sms on lcd 16×2
Hi there. I’m using arduino uno with sim900, followed each step you mentioned, but still no results displayed. I’ve entered the serial monitor, enter s or r for messaging but nothing showed up. I can use smartphone to call the sim card in the gsm shield though. Not sure what happened. I’m new to these stuffs.
i need to get the message from gsm module when we snd message to gsm module
“”AT+CMGF=1
OK
ŠiêUÒåNL¢’‚¢‚²ºšþ0”
>
> EMERGENCY // message written in the code
>
+CMGS: 59
OK
“”
the message is showing in the serial port but a blank message received in the given mobile no.
Hi. I need to send sms for multiple users using the same program…?
Kindly give me a solution as soon as possible
@ sanjeevi – Save mobile numbers of users into an array. Execute the AT Commands to send SMS in a loop and call mobile numbers from array via loop iteration.
HI sir:
je voudrais d’envoyer un sms via gsm SIM800L contient la température et les coordonnées GPS(latitude et longitude, la vitesse), si tu peux m’aider monsieur dans l’établissement d’un code,
les équipements utilisés sont:
arduino uno
capteur de température LM35
sim800l
gps ne06mv2
afficheur 16*2
un buzzer
si la temperature est superieur à 12°C uue sonnette d’un buzzer sera établie, si elle supérieur de 15°C une alarme via SMS sera transmis via réseau GSM.
Hello Sir,
I want need help for doing program to getting only text contain from my sms .
for that i have choose algorithm which is only taking a part of text contain which is in between of * and # symbol.for that i am create this code but its not getting any result.
I am using GSM 300 module and interface done with ARDUINO UNO.
Plz give me help for my project work
#include
#include
#include
SoftwareSerial mySerial(2, 3);
LiquidCrystal lcd(3,4,5,6,7,8);
int temp4=0;
int lenth,lenth1,i=0,temp=0;
String str=””;
String name=””;
String number=””;
String datam=””;
void setup()
{
lcd.begin(16,2);
Serial.begin(9600);
mySerial.begin(9600);
lcd.print(“WEL COME”);
pinMode(13,OUTPUT);
digitalWrite(13,HIGH);
vw_set_tx_pin(19);
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000);
delay(3000);
Serial.println(“ATE0\r\n”);
delay(10);
Serial.println(“AT+CNMI=2,2,0,0,0”);
Serial.println(“AT+CMGF=1”);
delay(500);
}
void loop()
{
gsmmsgRead();
}
void gsmmsgRead()
{
while(temp!=0)
{
i=0;
while(i<lenth)
{
if(str[i]=='"')
{
temp4++;
}
if(temp4==1)
{
for(int j=0;j<15;j++)
{
number+=str[i];
i++;
}
temp4=2;
}
if(str[i]=='*')
{
i++;
lcd.clear();
while(str[i]!='#')
{
name+=str[i];
lcd.print(str[i]);
i++;
}
datam=str;
}
i++;
}
delay(2000);
temp=0;
temp4=0;
name="";
lenth=0;
str="";
number="";
delay(1000);
}
serialEvent();
delay(100);
}
void serialEvent()
{
while (Serial.available())
{
char inChar = (char)Serial.read();
str+=inChar;
lenth++;
if (inChar == '\n')
{ temp=1;
inChar=0;
}
}
}
char phone_no[]=”03117070917″;
void setup()
{
Serial.begin(9600);
delay(2000);
Serial.println(“AT”);
Serial.print(“ATD”);
Serial.print(phone_no);
Serial.println(“;”);
delay(3000);
Serial.println(“ATH”);
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
This code is not working
#include
#include
#include
SoftwareSerial Sim900Serial(9,10);
byte buffer[64]; // buffer array for data recieve over serial port
int count=0; // counter for buffer array
SoftwareSerial GPS(11,12);
TinyGPS gps;
unsigned long fix_age;
long lat, lon;
float LAT, LON;
void gpsdump(TinyGPS &gps);
bool feedgps();
void getGPS();
void setup()
{
Sim900Serial.begin(19200); // the SIM900 baud rate
GPS.begin(9600); // GPS module baud rate
Serial.begin(9600); // the Serial port of Arduino baud rate.
delay(500);
Sim900_Inti();
}
void loop()
{
Sim900Serial.listen();
if (Sim900Serial.available()) // If date is comming from from GSM shield)
{
while(Sim900Serial.available()) // reading data into char array
{
buffer[count ]=Sim900Serial.read(); // writing data into array
if(count == 64)break;
}
Serial.write(buffer,count); // if no data transmission ends, write buffer to hardware serial port
Cmd_Read_Act(); //Read the ‘COMMAND’ sent to SIM900 through SMS
clearBufferArray(); // call clearBufferArray function to clear the storaged data from the array
count = 0; // set counter of while loop to zero
}
if (Serial.available()) // if data is available on hardwareserial port ==> data is comming from PC or notebook
Sim900Serial.println(Serial.read()); // write it to the GPRS shield
}
void clearBufferArray() // function to clear buffer array
{
for (int i=0; i<count;i )
{ buffer[i];} // clear all index of array with command NULL
}
void Sim900_Inti(void)
{
Sim900Serial.println("AT+CMGF=1"); // Set GSM shield to sms mode
Serial.println("AT+CMGF=1");
delay(500);
Sim900Serial.println("AT+CNMI=2,2,0,0,0");
Serial.println("AT+CMGF=1");
delay(500);
}
void Cmd_Read_Act(void) //Function reads the SMS sent to SIM900 shield.
{
char buffer2[64];
for (int i=0; i<count;i )
{ buffer2[i]=char(buffer[i]);}
if (strstr(buffer2,"GNRK")) //Comparing password entered with password stored in program
{
Serial.println("Password Authenticated.");
Serial.println("Sending reply SMS. ");
SendTextMessage();
}
}
void SendTextMessage()
{
Sim900Serial.print("AT+CMGF=1\r"); //Sending the SMS in text mode
delay(100);
Sim900Serial.println("AT+CMGS = \"+919868590006\"");//The predefined phone number
delay(100);
Sim900Serial.println("Please wait while Module calculates position");//the content of the message
delay(100);
Sim900Serial.println((char)26);//the ASCII code of the ctrl z is 26
delay(100);
Sim900Serial.println();
int counter=0;
GPS.listen();
for (;;)
{
long lat, lon;
unsigned long fix_age, time, date, speed, course;
unsigned long chars;
unsigned short sentences, failed_checksum;
long Latitude, Longitude;
// retrieves /- lat/long in 100000ths of a degree
gps.get_position(&lat, &lon, &fix_age);
getGPS();
Serial.print("Latitude : ");
Serial.print(LAT/1000000,7);
Serial.print(" :: Longitude : ");
Serial.println(LON/1000000,7);
if (LAT == 0 && LON == 0)
{
continue;
}
counter ;
if (counter<30)
{
continue;
}
Sim900Serial.print("AT+CMGF=1\r"); //Sending the SMS in text mode
delay(100);
Sim900Serial.println("AT+CMGS = \"+919868590006\"");//The predefined phone number
delay(100);
Sim900Serial.print("Latitude : ");
Sim900Serial.print(LAT/1000000,7);
Sim900Serial.print(" :: Longitude : ");
Sim900Serial.println(LON/1000000,7);//the content of the message
delay(100);
Sim900Serial.println((char)26);//the ASCII code of the ctrl z is 26
delay(100);
Sim900Serial.println();
counter=0;
break;
}
}
void getGPS()
{
bool newdata = false;
unsigned long start = millis();
while (millis() – start < 1000)
{
if (feedgps ())
{
newdata = true;
}
}
if (newdata)
{
gpsdump(gps);
}
}
bool feedgps()
{
while (GPS.available())
{
if (gps.encode(GPS.read()))
return true;
}return 0;
}
void gpsdump(TinyGPS &gps)
{
gps.get_position(&lat, &lon);
LAT = lat;
LON = lon;
{
feedgps();
}
}
Hi, all commands works….send message, receive message, send call, disconnect call
but what the output should be displayed when the module is supposed to receive call because my serial monitor is showing ERROR for receive call command.
Can I interface single gsm module to 2 Arduino boards
I have implemented the code but while running the program with my arduino UNO and GSM module SIM900A, no message is received in the provided mobile number. The serial monitor shows error in sending the message. Kindly suggest the possible cause for this error.
please tell me how to solve this problem
Is it possible to connect the GSM to 3,2 and load the program to the arduino?
how can i send and receive message as string?
hello,
I am making the same project but I found some trouble, my serial shows “ÿÿÿÿ” if I type “hi” on my serial monitor and also it’s not sending the message to provided number.
plz help me
New to Arduino but in the field or mobile repairs, will just be asking you everything.
I need a Uno or Uno R3?
Gsm shield 900a(5v dc)
Pir sensor
And what else?
I don’t want sms notifications. I want calling feature. And also tell me the code to stop the alarm.
Regards
Himanshu Bansal
Hi, how to make the sending of msg to be automatic instead of the need to click ‘s’ and enter?
Hi, i tried the code with SIM5320E, its not working. pls help.
for the AT+CMGS=\”+YYxxxxxxxxxx\”\r // Input the mobile number| YY is country code,
the mobile number is the sim card’s number on the shield or the number we want to sent the message to?
how can i tried it out with the serial monitor?
Thanks for ur help!!!
Hey i have used arduino uno for object detection sensor. i want to receive the messege whenever there is object in front of sensor. How to put code to receive msg from gsm module which is to be interface with arduino uno. help me to put gsm code in my program.
my code for sensor is as follows ..
int slottwo=9;
int slotone = 8;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(slotone, INPUT);
pinMode(slottwo, INPUT);
}
void loop() {
int slot1_val = digitalRead(slotone);
int slot2_val = digitalRead(slottwo);
//Serial.println(slot1_val);
//Serial.println(slot2_val);
delay(1000);
int state1val = digitalRead(slotone);
int state2val = digitalRead(slottwo);
if((state1val == 0)&(state2val == 0))
{Serial.println(“all slots are full”);}
else if((state1val == 0)&(state2val == 1))
{Serial.println(“slot2 is empty”);}
else if((state1val == 1)&(state2val == 0))
{ Serial.println(“slot1 is empty”);}
else if((state1val == 1)&(state2val == 1))
{Serial.println(“all slots are empty”);}
// put your main code here, to run repeatedly:
}
Hi!..
Thanks for the source code…but the receive SMS part is not working…I use exactly the same code…I’m using arduino mega 2560…
hello, i cant get any words shown in the serial monitor, am using arduino mega. and whenever i call the number i can hear the ringback, but i dont have display from my serial monitor. please help me what to do
Hi,
I need to store the value sent through gsm to a variable in the arduino. What should be my coding.
If find gsm monitering system of battery & load input & output Dc voltage & current with sensor how to use microcontroller board & their codings
hello sir, im trying to use GSM sim900A in malaysia with using the exact step that you had provide. but the GSM still does not sending any text or receive text. but when im trying to establish the network connection of GSM, i had heard the ringing. so what is the problem ? can you help sir ? its important to me. thank you????
It’s working!
I was trying to turn on/off led’s by sending a message to gsm modoule (sim900A+arduino uno).
But i get stuck at the point when the gsm receives the message. It receives the first message and displays on the serial monitor but after that it doesn’t shows other msg that are being received.
And on trying to read those messages using serial monitor manually i get different situations:
1). Sometimes it doesn’t shows messages next to first msg.
2). Sometimes the list of the messages suddenly appears at the same time in spite of being sent at different times.
3). Sometimes the msg gets displayed after 5-8min of entering the command to display received msgs. And some of these msgs have no data to display.
how to send multiple sms at a same time
Hello Sir,
I want a button(keypad) connected with Aurdino to send AT commands. Please help how to do this?
sir we tried this code,it is compiling but the message is not received by the given number.Could you please help us.thanks in advance
hello sir i am making automation system in which i have to receive message
if message is from one particular number than i have check the number and text
and if it match with the predefined string than i have to make any one of the pin of arduino high
can u sir please provide the code for this i am from the mechanical department and don’t have enough programming skills
Can you please help us to make our gsm works well? We have a problem in sending and receiving sms. We have a lot of codes but none of them were working.
Can you help us send codes about the said problems/? Thankyou!
I have tried several public domain arduino sketches with a SIM900 shield. The led on the shield flashes slowly showing connection established. However, I cannot send AT commands to it from my computer, and not able to send any sms messagrs to my cellphone. It worked a few months ago, but now nothing. Puzzeled about where to look. Any help would be appreciated. Thanks.
Can someone help me? This is my code.
#include
#include “SIM900.h”
#include “sms.h”
#include
//#include
#include
SMSGSM sms;
boolean started = false;
char buffer[160];
char smsbuffer[160];
char n[20];
//LiquidCrystal lcd(4,2,3,7,8,9);
int buttonState;
int lastButtonState = LOW;
long lastDebounceTime = 0;
long debounceDelay = 50;
boolean st = false;
int buzzer = 12;
void setup() {
//lcd.begin(16, 2);
Serial.begin(9600);
if (gsm.begin(2400))
{
started = true;
}
if (started)
{
delsms();
}
sms.SendSMS(“+60142646978” , “Gas Sensor and GSM module activated”);
}
void loop() {
//lcd.setCursor(0, 0);
//lcd.print(“Detektor Gas SMS”);
int val = analogRead(A0);
val = map(val, 0, 1023, 0, 100);
//lcd.setCursor(0,1);
//lcd.print(“Kadar: “);
//lcd.print(val);
//lcd.print(“% “);
//code using sensor detection
if (val > 10) {
tone(buzzer,800,500);
delay(1000);
st = true;
}
else st = false;
if (st != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() – lastDebounceTime) > debounceDelay) {
if (st != buttonState) {
buttonState = st;
if (buttonState == HIGH) {
PString str(buffer, sizeof(buffer));
str.begin();
str.print(“Gas Detected! Gas leakage at “);
str.print(val);
str.print(“%”);
//String a=str;
sms.SendSMS(“+60142646978”, buffer);
}
}
}
//code using sms lapor.
lastButtonState = st;
int pos = 0;
if (started)
{
pos = sms.IsSMSPresent(SMS_ALL);
if (pos)
{
sms.GetSMS(pos, n, smsbuffer, 100);
delay(2000);
if (!strcmp(smsbuffer, “lapor”))
{
PString str(buffer, sizeof(buffer));
str.begin();
str.print(“Rate of gas leakage currently at “);
str.print(val);
str.print(“%”);
//String a=str;
sms.SendSMS(“+60142646978”, buffer);
}
delsms();
}
}
}
//delete sms yang dihantar
void delsms()
{
for (int i = 0; i < 10; i++)
{
int pos = sms.IsSMSPresent(SMS_ALL);
if (pos != 0)
{
if (sms.DeleteSMS(pos) == 1) {} else {}
}
}
}
I'm using arduino uno, sim900 module, mq2 gas sensor and buzzer to create a gas sensor detector based on sms.
I have to 2 option :
1. The mq2 gas sensor detects and send the result via sms to the number set in the code.
2. We can send a specific string to know the surrounding gas percentage and send the result to the specific number set in the code.
But I want to change the second option to be auto reply to any incoming number. What should I do?
received signal from the GSM is how to read in ardiuno?
Hello. Your code works perfectly, although I have a question. When I receive the text message, it is displayed on the serial monitor as it should. Is there any way to save that message and do with I as I wish? For example, if a text says “STOP”, I want to turn an LED off (using a relay). Thanks in advance.
only the sending sms part works well but with the receiving part it doesn’t. my serial port doesnt show anything in it, its a plain blank space.
Hi,
Thanks for the tutorial and program. I have implemented your code but while running the program with my arduino UNO and GSM module SIM900A, no message is received in the provided mobile number. The serial monitor shows error in sending the message. Kindly suggest the possible cause for this error.
I have also implemented the above code with arduino uno & Sim 800c. Receiving part works well. But in sending part, I have received error message and the message didn’t come to my mobile. can u find the solution of above problem?
Hello, your code is not working on my device. Any suggestions for elementary mistakes I may be making? I’ve connected UNO to the gsm board with rx tx and the nwk led is blinking once in 3 seconds. There doesn’t seem to be anything wrong but nothing is happeneing. what could it be./
Hi. I’ve inserted the SIM card into the gsm module and the NWK lED is blinking once in 3 secs. But if I try to make a call to the number, it says “not reachable”. As specified, I’ve connected the RX TX of the gsm module to ppins 9 and 10 on the arduino uno. The SMS program also isn’t working. Help please…
my serial monitors notifies me when a msg is received but doesnt show what the msg is?
Thanks a lot for this useful project, sir, can I use SIM800l for this project instead of Sim900?
Dear sir, thanks for this beautiful program, please can I use sim800l for this purpose instead of Sim900?
And I tried with different codes and SIM 900A also working good sir(If I make a call I am hearing ringing sound),what is the problem I don’t sir.
sir,I connected all the connections what you told that and code also same but I got 10 times message and didn’t get received message on serial monitor.Now I am not getting send and received message.I am using SIM 900A,Arduino AT Mega 2560.Please help me sir.
Hi thanks for the code the send message works perfectly but the receive message does not work the receive message does not appear on the serial monitor
hi .. i have made all the connections,same as explained above but no message is being received on the number i have mentioned in the code, the code uploads correctly but no message is received.. im using GSM SIM900A miniv3.8.2 and arduino UNO.. please help
Sir,I have been trying to interface arduino(ARDUINO UNO) with gsm module(SIM900A) to receive a message.Nothing is shown in the COM monitor of ardino .i used the programme which you provided above.please help me.I dont want to sent message.can you please give me the programme .I want to complete my project with in 30 days.so help me please
my email id is “anuraajcp333@gmail.com”
I am doing project “WIRELESS WEATHER MONITORING SYSTEM”using arduino uno, GSM sim900a, LCD 16×2, temperature and humidity sensor dht11…now I request yourgood self to please provide me a program that will display current temperature and humidity on LCD. also if we send SMS from any mobile number to a mobile number of simcard that is in GSM to send current temperature or humidity it must send back SMS to the mobile number from which it received SMS with current temperature or humidity..
THANK’S BEFORE,I WANT TO DESIGN ARDUINO BASED REMOTE PATEINT MONITORING SYSTEM BY USING GSM ,PLEASE WOULD YOU HELP BY PROGRAMMING C CODES FOR RECEIVER AND TRANSMITER CIRCUIT WITH CIRCUIT DIAGRAM
I WANT TO DESIGN ARDUINO BASED REMOTE PATEINT MONITORING SYSTEM BY USING GSM ,PLEASE WOULD YOU HELP BY PROGRAMMING C CODES FOR RECEIVER CIRCUIT
sir i want to interface rain sensor with gsm module ie it shoul detect rainfall and send sms could please help me out?
I tried using your code can you verify below code:-
#include
SoftwareSerial mySerial(9,10);
int nRainIn = A1;
int nRainDigitalIn = 2;
int nRainVal;
int gsm=12;
boolean bIsRaining = false;
String strRaining;
void setup() {
mySerial.begin(9600);
Serial.begin(9600);
pinMode(2,INPUT);
pinMode(gsm,OUTPUT);
}
void loop() {
nRainVal = analogRead(nRainIn);
bIsRaining = !(digitalRead(nRainDigitalIn));
if(bIsRaining){
strRaining = “YES”;
digitalWrite(gsm,HIGH);
}
else{
strRaining = “NO”;
digitalWrite(gsm,LOW);
}
Serial.print(“Raining?: “);
Serial.print(strRaining);
Serial.print(“\t Moisture Level: “);
Serial.println(nRainVal);
delay(200);
if (digitalRead(12) == HIGH){
mySerial.println(“AT+cmgf=1”);
delay(1000);
mySerial.println(“AT+cmgs=\”+91xxxxxxxx\”\r”);
delay(1000);
mySerial.println(“leak detected”);
delay(100);
mySerial.println((char)26);
delay(1000);
}}
Sir i am using your code to receive sms but i have found that the code is not working , i have changed mySerial to Serial3 as i am using mega , plzzz help me out with it
***the code****
//#include
//SoftwareSerial mySerial(9, 10);
void setup()
{
Serial3.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’:
SendMessage();
break;
case ‘r’:
RecieveMessage();
break;
}
if (Serial3.available()>0)
Serial.write(Serial3.read());
}
void SendMessage()
{
Serial3.println(“AT+CMGF=1”); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
Serial3.println(“AT+CMGS=\”+91xxxxxxxxxx\”\r”); // Replace x with mobile number
delay(1000);
Serial3.println(“I am SMS from GSM Module”);// The SMS text you want to send
delay(100);
Serial3.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void RecieveMessage()
{
Serial3.println(“AT+CMGF=1”);
delay(1000);
Serial3.println(“AT+CNMI=2,2,0,0,0”); // AT Command to receive a live SMS
Serial.println(“AT+CMGL=\”ALL\”\r”);
delay(1000);
if (Serial3.available())
Serial.println(Serial3.read());
delay(1000);
}
I have a question:
Is it possible to program the code in such a way that gsm module could be used to send sms to a preset number as well as manually entered numbers simultaneously using arduino?
hii…sir
can I use gsm 300 insted of gsm 900
pls reply to my mail
hi my sim has a pin number , how do i add that in the program.
Thanks
hello sir.
i am not able to receive sms. i cannot figure out the problem. to select ‘s’ or ‘r’ this should be send through serial monitor?
Hi,
Please help me how to send SMS to Mobile Number Stored in Variable.
ie
please edit SendMessage function as-
SendMessage(String no){
//help me with the code
}
Hello Sir,
Thanks for the tutorial. I have a query:
I want to read the mobile number from an SMS sent to the GSM Module and then send msg from GSM module to the mobile number received. Can you please help me out with this?
we have used this code:
char phone_no[]=”9062261355″;
void setup()
{
Serial.begin(9600);
delay(2000);
Serial.println(“AT”);
Serial.print(“ATD”);
Serial.print(phone_no);
Serial.println(“;”);
delay(50000);
Serial.println(“ATH”);
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
__________________________________________________________________________
In serial monitor the following characters are printed
AT
ATD9062261355;
ATH
But no phone calls are forwarded to the phone number 9062261355
Please help in this matter
Please try adding country code. Also the delay seems to be very high. Just a 1 second or 2 second delay is enough.
I have just used country code(India +91)
I have reduced the delay before ATH to 2000 (2 second) as well as 10000 (10 second)
every time, only the text is printed in serial monitor, but no call is forwarded to the phone number
9062261355
I am using Arduino Uno version 1.7.8
Please reply soon
Use mySerial instead of Serial !
i don’t know for sure but you need an interface to connect your gsm to arduino. “Serial”gives connection just to monitor not GSM,Use”SoftwareSerial” to interface both.May be this helps..
try this code/*
Make Voice Call
This sketch, for the Arduino GSM shield, puts a voice call to
a remote phone number that you enter through the serial monitor.
To make it work, open the serial monitor, and when you see the
READY message, type a phone number. Make sure the serial monitor
is set to send a just newline when you press return.
Circuit:
* GSM shield
* Voice circuit.
With no voice circuit the call will send nor receive any sound
created Mar 2012
by Javier Zorzano
This example is in the public domain.
*/
// libraries
#include
// PIN Number
#define PINNUMBER “”
// initialize the library instance
GSM gsmAccess; // include a ‘true’ parameter for debug enabled
GSMVoiceCall vcs;
String remoteNumber = “9xxxxxxxxx”; // the number you will call
char charbuffer[20];
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println(“Make Voice Call”);
// connection state
boolean notConnected = true;
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while (notConnected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
notConnected = false;
} else {
Serial.println(“Not connected”);
delay(1000);
}
}
Serial.println(“GSM initialized.”);
Serial.println(“Enter phone number to call.”);
}
void loop() {
// add any incoming characters to the String:
while (Serial.available() > 0) {
char inChar = Serial.read();
// if it’s a newline, that means you should make the call:
if (inChar == ‘\n’) {
// make sure the phone number is not too long:
if (remoteNumber.length() < 20) {
// let the user know you're calling:
Serial.print("Calling to : ");
Serial.println(remoteNumber);
Serial.println();
// Call the remote number
remoteNumber.toCharArray(charbuffer, 20);
// Check if the receiving end has picked up the call
if (vcs.voiceCall(charbuffer)) {
Serial.println("Call Established. Enter line to end");
// Wait for some input from the line
while (Serial.read() != '\n' && (vcs.getvoiceCallStatus() == TALKING));
// And hang up
vcs.hangCall();
}
Serial.println("Call Finished");
remoteNumber = "9xxxxxxxxx";
Serial.println("Enter phone number to call.");
} else {
Serial.println("That's too long for a phone number. I'm forgetting it");
remoteNumber = "9xxxxxxxxx";
}
} else {
// add the latest character to the message to send:
if (inChar != '\r') {
remoteNumber += inChar;
}
}
}
}
you need to put in command “ATD 98xxxxxxxxxx;”
do not print semicolon (;) after no..
instead of this print \r\n
Hello sir , I have a querry what should i do if i wanted to replace the number in
mySerial.println(“AT+CMGS=\+YYxxxxxxxxx\”\r”);
with a variable which can store the number , For example
num=+xxxxxxxxxxx;
mySerial.println(“AT+CMGS=\num\”\r”);
char num[14]=”+91xxxxxxxxxx”;
mySerial.print(“AT+CMGS=\”);
mySerial.print(num);
mySerial.println(“\”\r”);
hai, your code is working perfectly with my arduino mega. but I need to send GPS coordinates via SMS. how can I do that cos softwareserial can’t be used two times at a time. Can you advise on this?? when I use hardware serial for GPS delay was not taken.
if u r trying to communicate the modules one at a time, u can use 4066 switch. check if it is suitable for ur project.
Sir,im doing a project including arduino and gsm.i need the code for entering the phone number manually using keypad and send sms to it.will you please help me…..
When i upload and try to run the program… nothing display on my serial monitor why is that?
Hay sir,
I already tested your code. it works perfectly.
But, i want to modify to turn on/off the LED and not success.
Could you help me, for this problem?
Just simple, i want turn on LED 13, after recieve sms “on”.
thank you,
@albert – It is very simple. I assume you want to turn an LED at pin 13 ‘ON’ after receiving an sms. First assign a variable name to pin 13 with command – const int LED = 13; In the next step configure pin as OUTPUT. Inside void setup() – write command – PinMode(LED,OUTPUT). Now write the following command inside RecieveMessage() method after delay(1000); – command – digitalWrite(LED,HIGH); delay(1000); For more details – refer – https://www.circuitstoday.com/blink-led-with-arduino
Dear Sir,
I already know how to control on/off the LED in arduino. The problem is, if i want to turn on the LED by send sms “ON_LED” and then send sms “OFF_LED” to turn off the LED.
This my code, still not working for turn on/off the LED.
char inchar;
void RecieveMessage()
{
SIM900.println(“AT+CNMI=2,2,0,0,0”); // AT Command to receive a live SMS
delay(1000);
if (inchar==’ON_LED’)
{
digitalWrite(led, HIGH);
}
else if (inchar==’OFF_LED’)
{
digitalWrite(led, LOW);
}
delay(1000);
}
whats the problem?
thank you
inchar will read each character one by one serially. You cannot just compare inchar with a string. Do Serial.read everytime for all the letters in your input (ON_LED). Like do Serial.read, compare inchar with ‘O’, then Serial.read, compare with ‘N’, Serial..read etc….
Have you managed to get your program working.
I am trying to do the same but cannot get the LED to flash on receiving a text message
please can any one help me with program code without switch case i want to impliment the circuit with a battery supply.
hi sir …..
i am gud with ur program…i need some help in creating a new program in which i am using ultrasonic sensor hc sr-04 and interfacing sim900…arduino should send the mesg to the no. when the distance from the ultrasonic sensor reaches 15cms…can u please send me the code for that
@hemanth – It is very simple. You may refer our arduino projects like – https://www.circuitstoday.com/burglar-alarm-using-arduino-and-pir-sensor , https://www.circuitstoday.com/gas-leakage-detector-using-arduino-with-sms-alert
The same logic and methods can be used to develop your application idea.
Hi sir!
I am developing a project in which I also use an ultrasonic sensor and a shield gsm in order to send a message with the information about the measurements done by the sensor.
I realized that you sent a message asking for help about this topic some months ago and I wonder if you have already got the code and if you could share it because I’m a bit blocked.
Thanks in advance!
My gsm module responds to first received message but not for the second one. what exactly is the problem ?
@siva – the program we have written is an example for interfacing GSM Module to Arduino. The program is written in such a way that it scans any input from serial monitor of arduino continuously. Once you press ‘r’ on serial monitor, the program will call method to receive message from GSM module. This message is then written to serial monitor of arduino for display. Once that process is over, program again scans for a command (‘s’ or ‘r’) from serial monitor. So if you want to receive second message from gsm module, press ‘r’ again on serial monitor. If you to receive 3rd message, press ‘r’ again (after second message is displayed on serial monitor)
Note:- You need to alter this program to receive messages continuously.
we are doing project on smart sensor for agricultural field using GSM with AURDINO interfacing . according to different conditions of motor turn on and off for this how i have to write code for sending and receiving different messages. plz …..reply soon ….as soon as possible….
hai, i am from SriLanka. new to this field. I have tried this but this is not working for me. I am using Arduino Mega and SIM900A GSM/GPRS module which is shown in this link http://arduino.stackexchange.com/questions/21499/connecting-sim900a-gsm-gprs-module-arduino-mega/21552#21552
Please can you help me on this??
I have seen your GSM Module image here – http://i.stack.imgur.com/AxKag.jpg
Here are my thoughts!
1. You should connect it to TTL pins Rx, Tx and Ground. GSM Rx to Arduino Tx and GSM Tx to Arduino Rx. GSM Gnd to Arduino Gnd.
2. Dont worry about other jumper pins. Just make the connection.
3. After inserting SIM Card, Press and Hold Power button. Notice the Network Status LED marked as NET_STA on your GSM board. This LED should blink in 3 seconds delay continuously.
4. Make a call to the sim card number inside GSM module. If you hear ringing sound on your phone,the interfacing of GSM module to Arduino is perfect.
Hi again,
I have followed your way already and I was able to hear ring back tone. But when try the code, Serial.available was not read in serial monitor. I don’t know what is wrong. Can you guess what will be the reason for this? but my Arduino serial ports are working properly.
Which pins are you using ? If you are using SoftwareSerial library for communicating with Arduino, then select any 2 PWM enabled pins instead of Rx and Tx of Arduino (like pins 9 and 10 in Arduino uno)
Thank you for your information. i have tried but there is no response yet. could you please tell me that do i need to edit coding rather than change the pin (in mega2560 PWM pins can be 4-12) and the destination mobile number??
Note these points.
Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).
Refer – https://www.arduino.cc/en/Reference.SoftwareSerial
1.Make sure pins are configured in software correctly.
2. Try changing the delay given in program (inside SendMessage() method)
3. Make sure your country code is given correctly in mobile number. +91 – is country code of India. Change it to your country.
Hi Sir, there is improvement in sending a SMS. I have used 50,51 pins and my no is given correctly. How can I use Mega Rx,Tx directly to interface SIM900A with Arduino?? Could you please explain??
Hi Sir, there is no improvement in sending a SMS. I have used 50,51 pins and my no is given correctly. How can I use Mega Rx,Tx directly to interface SIM900A with Arduino?? Could you please explain??
Hello sir,
your code works perfectly. really really thanks for guiding me. there is one more change that i wanted to do to get successful. finally works with pin 11 and 12.
Hey sir , i am also using a mega 2560 but still not working can you give me your all connection whether you used rs232 or not
Kindly explain how to send this ‘s’ and ‘r’ variables as input in order to call receive or send message function.
@nismi – Open the “Serial Monitor”of Arduino. Type s and hit enter. Once you are finished with sending message, type r and press enter button.
Are all GSM Modules the same?
I am not getting serial commends for this program? what to do for getting
@suraj – What is the problem you are facing ? Serial commands are written in the program. To send ‘s’ and ‘r’ commands serially, open the serial monitor of Arduino.
In my project I am out off all digital pin except Rx and Tx. Can I use the software serial library for Rx and Tx. Like instead of mentioning Softwareserial myserial (9,10) , can I mention Softwareserial myserial (Rx,Tx)?
If not can you send the code for Rx,Tx.
@chandar – Software Serial actually makes use of the Rx and Tx hardware internally. You better connect directly to Rx and Tx and use the serial communication commands of Arduino. Refer – https://www.arduino.cc/en/Reference/Serial
hi sir
do we require any converter from rs232 to ttl in between the microcontroller and the sim900 modem
@chandra mouli – Check if your GSM module has TTL output provision. Most of the GSM modules available in market has TTL output provisions. If the module has only RS232 output provision, you need to use an RS232 to TTL converter to interface that particular module with Arduino.
hi iam trying your program but it not working
the message not send automatically…..
what can I do now
@Karthikeyan – We have tested this code many times repeatedly and it was working 100% all the time. Your issue may not be with the code. Double check hardware connections! Also check if you have input the mobile number correctly!
Good day sir,
Please can you explain how can we send the input reading through GSM modem. For example i want ardinuo to take input reading and then send it through sms. How can we implement this please?
@Ali – Its very simple. Save the input to a variable or array. Now write the variable values one by one serially to GSM module using Serial.println() command. In our example we are using Software Serial method, so we use mySerial.println() method. If input variable is val_input, then write the following to GSM module – mySerial.println(val_input);
sir we have to perform operation based on sms coming to that no
eg: if on is come then blow a light
otherwise off the light
plzzz help me out for this
@Abdul Malik – Its actually simple. You first learn AT Commands to receive an SMS. Once you receive the SMS, save its content to a variable or array. Scan the array to check for required number/digit/character.
How can i save the data to array or variable, can you give me the code.
good day sir! i tried to display the text that the GSM shield sends out on the serial monitor. the output was this
+CMT: “+639XXXXXXXX”,””,”16/03/02,8:31:09:+32″
hello world
what does +32 mean? and where is it from?
@wooja – I don’t have a good idea of the +32. It could be some number of characters sent or something like that. Refer AT Commands Datasheet.
can you please help me with a simple example of how the aduino can respond to any remote number from a mobile phone using the sim 900 module without specifying any number
I did not understand your question. Please explain it again.
am trying to make a system that responds to any user who sends an sms command to the sim900 module using the exact step that you had provided ,but using mySerial.println(“AT+CMGS=\”+91xxxxxxxxxx\”\r”); will only allow the system to send a response to one number , how can i implement a system that responds to multiple phone numbers wich send a command to the sim900 or a function that Retrieves the phone number an from an incoming SMS message and stores it in a named array , just like the function “remoteNumber()” wich is present in the aduino “GSM.h” library .
Hi – read the AT commands list – http://www.espruino.com/datasheets/SIM900_AT.pdf
I think your idea can be implemented with help of arduino GSM library. I am in the middle of another project, so can’t work on your idea now. Will definitely check this later.
ok thanks
hello sir, im trying to use GSM sim900A in malaysia with using the exact step that you had provide. but the GSM still does not sending any text or receive text. but when im trying to establish the network connection of GSM, i had heard the ringing. so what is the problem ? can you help sir ? its important to me. thank you
@aiman – It can be an error with your program. Double check the program.
thanks, it is working fine!!
We are using ” \” in “AT+CMGS=\”+91xxxxxxxxxx\”\r” to differentiate mobile no & AT command Stringset. I want to know how arduino reads this code?
Could you please specify the syntax for call commands. I tried different combinations but I am unable to figure it out and Thank you for this SMS information, it worked perfect
please i need the pdf format of this project. i will be very glad if you can send it through my e-mail address above. thanks
Yea thanks for this. I found out that output of the gsm module is static, i mean is only what we have input is what is doing. Is there no way it could check for out box messages and be able to re-send any in it to the controller. Maybe some other dynamic functions too.
@Victor Its possible to read inbox and many other functions using GSM module. Learn AT Commands thoroughly for that.
Hi,
Thank you very much. The information about software serial was very helpful.
Hi.. Frnds..can anyone say, the Tx, Rx terminals of arduino should connected to which port in GSM Module either Serial port or Rs485..?