GSM900 Module With Arduino Mega

Introduction

 
Before reading this article, I highly recommend reading my previous articles:
In this article, I'll show you how can we use the GSM900 module using the Arduino Mega GSM-Global System For Mobile. The GSM module supports communication in the 900MHZ band. In India, most of the mobile network providers operate in the 900MHZ band. In the majority of the United States, the bandwidth provider is around (850-1900MHZ).
 
Requirements
  • Arduino Mega
  • Bread Board
  • GSM900 Module
  • Led
  • Some Jumper Wires
 
Figure 1: Arduino Mega
 
 
Figure 2: Bread Board
 
Checking the GSM module before we use
 
Step 1: Connect the Adapter to the GSM and Turn it ON.
 
Step 2: Insert the sim card to the GSM Module.
 
Step 3: Wait for some seconds and see the blinking rate of the status LED once the connection is established the led will blink continuously every three seconds.
 
Connection
  • RX Pin to Arduino Mega 15
  • TX Pin to Arduino Mega 16
  • Gnd to Gnd
  • Led Anode Pin to 13
  • Cathode Pin to Gnd
Programming
  1. #include<SoftwareSerial.h>      
  2. SoftwareSerial firstSerial(15,16);  RX/TX    
  3. int led=13;    
  4. void setup()      
  5. {      
  6.   pinMode(led,OUTPUT);    
  7.   firstSerial.begin(9600);      
  8.   Serial.begin(9600);      
  9.   delay(100);      
  10. }      
  11. void loop()      
  12. {      
  13.   if(Serial.available()>0)    
  14.   digitalWrite(led,HIGH);      
  15.   switch(Serial.read());      
  16. }      
  17. void sndmsg()      
  18. {      
  19.   firstSerial.println("AT+CMGF=1");      
  20.   delay(1000);      
  21.   firstSerial.println("AT+CMGS=\"+xxxxxxxxxx\"\r");  //Enter Your Mobile Number instead XXXX while Testing    
  22.   delay(1000);      
  23.   firstSerial.println("Hello C# Corner Iam Sending SMS Through GSM");      
  24.   delay(100);      
  25.   firstSerial.println((char)23);      
  26.   delay(1000);      
  27. }     
Explanation
 
We start with softwareserial.h library into the program in the next line creates the constructor for the serial port such as RX and the TX. In the Arduino Mega board 15 pin act as RX pin and 16 pin act as the TX pin while using the Arduino Uno "0" pin as TX "1st" pin as RX .void setup() In the setup() function we want to set the baud rate for the GSM because we want to communicate with the device to the Serial Monitor so we want to set the BaudRate as (9600) and set the delay time as 1000 I,e 1Sec and Now let's move to actual program void loop() is the one type of the condition function based upon our condition our GSM will work first we check the availability of the serial ports.
 
Serial.available()
  1. if(Serial.available()>0)   
To check any data that are coming to the serial port of the Arduino if it is available means the led will be on, else it will not be on Serial.read().
 
It reads all data available on the serial buffer.
 
And let's move to the function called void sndmsg():
 
It is the one type of the function we created in the Arduino Mega to send the SMS. First we want to set the GSM to the text mode; this can done through the "AT" commands AT means Attention we can send the sms through the serial port while writing ("AT+CMGF") and ("AT+CMGS=\"XXXXXXXXXX"\"\r") and set some delay time then upload the program to the Arduino mega board and open the serial monitor windows type "Hello C# Corner Iam Sending SMS Through GSM" and click send button. The SMS will send to the concert mobile number that you have been given in the code.
  1. firstSerial.println("AT+CMGF=1");        
  2. delay(1000);        
  3. firstSerial.println("AT+CMGS=\"+xxxxxxxxxx\"\r");      
  4. delay(1000);        
  5. firstSerial.println("Hello C# Corner Iam Sending SMS Through GSM");        
  6. delay(100);        
  7. firstSerial.println((char)23);        
  8. delay(1000);    
AT Command
 
AT Command is used to check the connection between the module and the computer.
 
CMGF: The Command is used to set the SMS mode.
 
E.g: ("AT+CMGF=<mode>" )
 
CMGS: The Command is used to send the SMS from the module to the device.
 
E.g: ("AT+CMGS=\"<mode>\">
 
Types of the "AT" Commands:
 
 
Figure 3: AT Commands Classification
 
Test: It is used to check whether the command is supported to Modem or Not.
 
Syntax: AT<Command name>=?
 
Read: The Read Command is used to get the mobile phone number.
 
Syntax:
AT<Command name>?
 
Set: The Set command is used to modify the mobile phone settings.
 
Syntax:
AT<Command name>=value1...value N
 
Execution command
 
The execution command is used to make some operations.
 
Syntax: AT<Command name>=parameter1,....parameterN
 
Some Commonly used AT Commands for SMS Text Mode are:
 
AT Command SMS Text Mode
AT+CMGS Send Message
AT+CMGR Read Message
AT+CMGD Delete Message
AT+CMGL List Message
AT+CSAS Save Settings
AT+CRES Restore Settings
 
"AT" Commands used in the following services:
  • SMS Service
  • MMS Service
  • Fax Service
  • Information and configuration pertaining to the mobile device.
  • Data and voice link communication over to the mobile network.
Read more articles on the Internet of Things: