GSM Module:
GSM module is used in many communication and IoT devices which are based on GSM (Global System for Mobile Communications) technology. It is used to interact with the GSM network using a computer.
How we can use it:
GSM modules have a special command language called AT commands(AT=Attention)
when we send “AT” if GSM responds OK then it is working well
as an example:-
- ATA to answer a call
- ATD to dial a call
- ATH declines a call
- AT+CMGR to read the message
- AT+CMGS to send the SMS, etc.
- “AT+CMGS\r”. We can use the GSM module using these commands:
if it responds with “ERROR” or null value
you have to check the GSM module LED Indicator
👉if LED
Blink every 1s
👉The module is running but the GSM module is not connected to the GSM network
Blink every 2s
👉GPRS data connection is active
Blink every 3s
👉The module is connected to the cellular network (can send/receive voice and SMS)
Here is the Arduino code:
you can use these code lines To take a call
String number = "+123xxxxxxx"; // enter mobile number with the country code
void callNumber() {
sim.print (F("ATD"));
sim.print (number);
sim.print (F(";\r\n"));
}
To send an SMS you can use these code lines
void SendMessage(){
sim.println("AT+CMGF=1");
delay(1000);
sim.println("AT+CMGS=\"" + number + "\"\r");
delay(1000);
String SMS = "Hellow"; //type here the message what you want
sim.println(SMS);
delay(100);
sim.println((char)26);
delay(1000);}
To Read an SMS you can use these code lines
void ReadMessage(){
sim.println("AT"); // Sends an ATTENTION command, reply should be OK
sim.println("AT+CMGF=1"); // Configuration for sending SMS
sim.println("AT+CNMI=1,2,0,0,0");}// Configuration for receiving SMS
Here is the full code you can try it and get some idea about the GSM module
#include <SoftwareSerial.h>
SoftwareSerial sim(10,11);
String number = "+123xxxxx"; // enter the number with country code
String cmd = "";
void setup() {
Serial.begin(9600);
Serial. println("Wait a few seconds...");
delay(5000);
Serial.println("System Started..");
sim.begin(9600);
delay(1000);
Serial. println("Enter c to make a call and s to send text");
}
void loop() {
if (Serial.available() > 0)
switch (Serial.read())
{
case 'c':
callNumber();
break;
case 's':
SendMessage();
break;
case 'r':
ReadMessage();
break;
}
if (sim.available() > 0)
Serial.write(sim.read());
}
void SendMessage()
{
sim.println("AT+CMGF=1");
delay(1000);
sim.println("AT+CMGS=\"" + number + "\"\r");
delay(1000);
String SMS = "Hellow";
sim.println(SMS);
delay(100);
sim.println((char)26);
delay(1000);}
void ReadMessage(){
sim.println("AT"); // Sends an ATTENTION command, reply should be OK
sim.println("AT+CMGF=1"); // Configuration for sending SMS
sim.println("AT+CNMI=1,2,0,0,0");}// Configuration for receiving SMS
void callNumber() {
sim.print (F("ATD"));
sim.print (number);
sim.print (F(";\r\n"));
}