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
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
Programming
- #include<SoftwareSerial.h>
- SoftwareSerial firstSerial(15,16); RX/TX
- int led=13;
- void setup()
- {
- pinMode(led,OUTPUT);
- firstSerial.begin(9600);
- Serial.begin(9600);
- delay(100);
- }
- void loop()
- {
- if(Serial.available()>0)
- digitalWrite(led,HIGH);
- switch(Serial.read());
- }
- void sndmsg()
- {
- firstSerial.println("AT+CMGF=1");
- delay(1000);
- firstSerial.println("AT+CMGS=\"+xxxxxxxxxx\"\r");
- delay(1000);
- firstSerial.println("Hello C# Corner Iam Sending SMS Through GSM");
- delay(100);
- firstSerial.println((char)23);
- delay(1000);
- }
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.
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.
- firstSerial.println("AT+CMGF=1");
- delay(1000);
- firstSerial.println("AT+CMGS=\"+xxxxxxxxxx\"\r");
- delay(1000);
- firstSerial.println("Hello C# Corner Iam Sending SMS Through GSM");
- delay(100);
- firstSerial.println((char)23);
- 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
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: