Categories

Sim800L interfacing with Arduino


Hello Guys, thank you for visiting this blog. In this blog, we are going to play with the sim800l GSM module. After completing this blog, you will be knowing what is sim800l, how to play with it and a few more interesting stuff about SIM800l So let’s begin. 

 Today we are living in the world of IoT, remotely controlling an object has become a craze and time saving for many processes. IoT is playing a very important role in many sectors like industry, public sector and private sectors. In this section, I am going to put a small part of this huge IoT in front of you and for this, we are using an Arduino, Sim800l module and some Du-Pont cables. 

But do you know what is sim800l? 

      This is the GSM module similar to the one which is on your phone. And I can assume that every one of you knows the application of GSM module. Speaking of Sim800l module, it is a small chip that uses serial-communication to communicate with any microcontroller or microprocessor. It has an in-built onboard antenna and an onboard SIM slot for SIM insertion purposes. 

The Sim800l module has 12 total pins that are used to establish connections with the microcontroller. For your simplicity, here I have shared a detailed pinout of the SIM800l and a function of each pin. 

Sim800L PinOut:

  •  Ring:-

                     As the name itself suggests, this pin is used for indication purpose. This pin produces an interrupt signal when we receive an SMS or a phone call. 

  • DTR:- 

                     We can call this pin an enable pin. This pin plays an important role in saving electricity. If you make this pin high, the module enters sleep mode by disabling serial communication and if you make it low, the module turns on. In the case, if sim800l is not working, it may be the reason that you are accidentally making this pin high. 

  • Mic+, Mic-, SPK+ & SPK-    These are the pins where you can connect the microphone and speaker.  
  • NET-    Here you can attach that helical shape antenna. 
  • RST-     This pin is used to reset the sim800l module. If your module is not responding to the AT command, possibly due to a baud rate problem, you can make this pin high for 100ms to reset the SIM800L. 
  • VCC and GND-    You can power SIM800l using these pins but the voltage should not be more than 3.3V and Current should not be less than 1A. 
  • RX and TX-    These pins are used for Serial communication Rx for receiving commands from the controller and TX for sending out the data. 

This was the introduction part of Sim800l Module if you want to know more about this you can mail us at info@robu.in

Next, we are going to learn about setting the baud rate, Network Scan, Sending and receiving SMS and Answering and Dialling the call. 

Components you will need 

Hardware Part:     

  •  Arduino Uno 
  •  SIM800l module 
  •  Connecting cables 
  •  2G Sim card (Please note SIM800l is a 2g GSM module, this means that the 4G sim card will not work with this module. If you are looking for 4G GSM module then click on this link) 

 Note-    If you are using an Arduino as a microcontroller and not using a resistor divider Ckt then you will damage the Sim800l module. 

Software Part: 

This is the part list you will need when working on a SIM800l module. Now, we’ve got all the things that will help us to play with sim800l module. Now it’s time to hook up this module with the microcontroller. Here we are using Arduino UNO as a microcontroller. To demonstrate it I have shared the interfacing diagram please take a look

SIM800L

Fig. Interfacing Diagram

 

 

 SIM800l interfacing with Arduino Uno-

Now you are all set to play with Sim800l. After interfacing, when you power this module, you will see that the onboard LED is on and blinking in different patterns. This blinking pattern of the onboard LED tells us the working status of the SIM800l module. 

Scanning network

Searching network

Sim800l Connection Established

Connection Established

SIM800L GPRS connection

GPRS Enabled

 

Pattern1: LED is blinking after each 1s this means that SIM800l is turned ‘ON’ but not established the connection. 

Pattern2: LED is blinking after each 3S. It means sim800l has successfully established the connection. 

Pattern3: LED is blinking after each 2S. It means the GPRS feature is turned on. 

 

Troubleshooting SIM800l Module- 

In the above section, we have learned about the blinking pattern of the onboard LED and by analyzing this factor, we can find out if the module is working or not but it is not enough if the problem is in the UART port. To test the functionality of the port and SIM we can shoot some AT commands and for this, we can use the following troubleshooting AT commands. 

Using At Commands to test the sim800l Module-

To test the module, connect the SIM800l module to your system with the help of Arduino ==> Open Arduino IDE after this select the com port ==> Open the serial monitor ==> Enter the following AT commands. 

AT:  If the Sim800l module is functioning properly then Sim800l will reply OK after receiving this module. 

AT+CBC-  This command is used 

AT+ CSQ– Sim800l module tells the strength of the signal after receiving this AT command 

AT+CREG– You can use this AT command to register the network if your SIM800l module is abruptly losing network and taking a long time to scan the network. 

AT+COPS?– If you put this command, SIM800l will tell you about its network status.

AT+COPS=? – Sim800l tell us the networks available after receiving this AT command. 

SIM800l AT commands

Network Status Check

 

Setting the baud rate- 

Sim800l supports a 9600 standard baud rate as the default baud rate but you can configure it to any baud rate using the following AT command.  

SIM800l AT commands

Baud Rate Setting

 

sim800l baud rate

Baud Rate AT Commands

 

 

 

Scanning Network-  

By default, module scans the network automatically, but if it is not scanning automatically then you can use the following AT command to manually scan the network. 

https://robu.in/wp-content/uploads/2019/12/Sim800L-network-scan

The response of AT+COPS command.

 

Dialling a number using SIM800L-

Making a Call Using Serial Monitor:

     

 

AT Command Set For Dialing The Number

Calling Screen-Shot

 

Arduino Sample Code For Sim800L:

In the section below, I have shared some sample codes for sim800l, using these codes you will be able to send and receive SMS. 

Troubleshooting guide 

If you use the following code, then your module should work, but it is not working then there may be the following reasons: 

1 balance: 

  The first thing that you do not have enough is a strange thing but sometimes it can be the reason. 

  2 Out of coverage area: 

   In this case, you can run the AT + COPS command to check if it is connected to the network. 

  There can be another reason and that is the issue of power. To make sure you can run AT + CSQ and AT + CBC. 

  AT + CSQ will tell you the signal strength and AT + CBC will tell you the percentage of the battery. 

  3 functionality is enabled 

  If all the above works are working and you have followed this blog from the beginning and still it is not sending SMS then the issue may be here. 

  To overcome this problem you can run the following command 

  AT + CFUN = 1 

  This command enables the functionality of the module. 

Sample Code For Dialing a Number:

#include <SoftwareSerial.h>

String inputString = "";

String fromGSM = "";

SoftwareSerial mySerial(3, 2);

char sim800l[255];

int sim800lIndex = 0;
 
void setup()

{

// put your setup code here, to run once:

Serial.begin(9600);

mySerial.begin(9600);

inputString.reserve(200);

fromGSM.reserve(200);

Serial.println(" Command --> AT ");

mySerial.print("AT");

mySerial.print("\r");

delay(100);

Serial.print(" Response --> ");

while (mySerial.available())

{

sim800l[sim800lIndex] = mySerial.read();

sim800lIndex++;

Serial.print( sim800l[sim800lIndex - 1]);

}

sim800lIndex = 0;

Serial.println("");

Serial.println(" Command --> ATEO ");

Serial.print(" Response --> ");

mySerial.print("ATE0");

mySerial.print("\r");

delay(100);

while (mySerial.available())

{

sim800l[sim800lIndex] = mySerial.read();

sim800lIndex++;

Serial.print( sim800l[sim800lIndex - 1]);

}

sim800lIndex = 0;

Serial.println("");

Serial.println(" Command --> AT+CFUN=1 ");
Serial.print(" Response --> ");
mySerial.print("AT+CFUN =1");
mySerial.print("\r");
delay(100);
while (mySerial.available())
{
sim800l[sim800lIndex] = mySerial.read();
sim800lIndex++;
Serial.print( sim800l[sim800lIndex - 1]);
}
sim800lIndex = 0;
Serial.println("");

mySerial.print("ATD8888844444;"); // enter number ATD<number>
mySerial.print("\r");
while ( !(mySerial.available()) );
while (mySerial.available())
{
sim800l[sim800lIndex] = mySerial.read();
sim800lIndex++;
Serial.print( sim800l[sim800lIndex - 1]);
}
sim800lIndex = 0;
Serial.println(" ");
Serial.println(" Enter 'ATH' command to End the call ");

}

void loop()
{
while (1)
{
while (Serial.available())
{
sim800l[sim800lIndex] = Serial.read();
sim800lIndex++;
mySerial.print( sim800l[sim800lIndex - 1]);
}
while (mySerial.available())
{
sim800l[sim800lIndex] = mySerial.read();
sim800lIndex++;
if (sim800l[sim800lIndex - 4] == 'R' && sim800l[sim800lIndex - 3] == 'I' && sim800l[sim800lIndex - 2] == 'N' && sim800l[sim800lIndex - 1] == 'G')
{
delay(8000);
mySerial.print("ATA"); // AT command to answer the call.
mySerial.print("\r");
}
Serial.print( sim800l[sim800lIndex - 1]);
}
}
}

Reading SMS automatically:     


#include <SoftwareSerial.h>

String inputString = "";

String fromGSM = "";

SoftwareSerial mySerial(3, 2);

char Sim800L[255], SMS[255], smsMemory[5], SmS_Index[5];

int Sim800LIndex = 0, SMS_Index = 0, S_Index = 0;

bool NewSMSArrived = 0, SMSmemory = 0;

void setup()

{

Serial.begin(9600);

mySerial.begin(9600);

inputString.reserve(200);

fromGSM.reserve(200);

Serial.println(" Command --> AT ");

mySerial.print("AT");

mySerial.print("\r");

delay(100);

Serial.print(" Response --> ");

while (mySerial.available())

{

Sim800L[Sim800LIndex] = mySerial.read();

Sim800LIndex++;

Serial.print( Sim800L[Sim800LIndex - 1]);

}

Sim800LIndex = 0;

Serial.println("");

Serial.println(" Command --> ATEO ");

Serial.print(" Response --> ");

mySerial.print("ATE0");

mySerial.print("\r");

delay(100);

while (mySerial.available())

{

Sim800L[Sim800LIndex] = mySerial.read();

Sim800LIndex++;

Serial.print( Sim800L[Sim800LIndex - 1]);

}

Sim800LIndex = 0;

Serial.println("");

Serial.println(" Command --> AT+CFUN=1 ");

Serial.print(" Response --> ");

mySerial.print("AT+CFUN =1");

mySerial.print("\r");

delay(100);

// while( ! (mySerial.available()) );

while (mySerial.available())

{

Sim800L[Sim800LIndex] = mySerial.read();

Sim800LIndex++;

Serial.print( Sim800L[Sim800LIndex - 1]);

}

Sim800LIndex = 0;

Serial.println("");

Serial.println(" Command --> AT+CMGF=1 ");

Serial.print(" Response --> ");

mySerial.print("AT+CMGF =1");

mySerial.print("\r");

delay(100);

// while( ! (mySerial.available()) );

while (mySerial.available())

{

Sim800L[Sim800LIndex] = mySerial.read();

Sim800LIndex++;

Serial.print( Sim800L[Sim800LIndex - 1]);

}

Serial.println(" Command --> AT+CSCS=\"GSM\"");

Serial.print(" Response --> ");

mySerial.print("AT+CSCS =\"GSM\"");

mySerial.print("\r");

delay(100);

// while( ! (mySerial.available()) );

while (mySerial.available())

{

Sim800L[Sim800LIndex] = mySerial.read();

Sim800LIndex++;

Serial.print( Sim800L[Sim800LIndex - 1]);

}

Serial.println(" Command --> AT+CPMS=\"SM\"");

Serial.print(" Response --> ");

mySerial.print("AT+CPMS =\"SM\"");

mySerial.print("\r");

delay(100);

// while( ! (mySerial.available()) );

while (mySerial.available())

{

Sim800L[Sim800LIndex] = mySerial.read();

Sim800LIndex++;

Serial.print( Sim800L[Sim800LIndex - 1]);

}

/*

Serial.println(" Command --> AT+CMGS=\"8669026867\"");

Serial.print(" Response --> ");

mySerial.print("AT+CMGS=\"8669026867\"");

mySerial.print("\n");

delay(100);

//while( ! (mySerial.available()) );

while(mySerial.available())

{

Sim800L[Sim800LIndex] = mySerial.read();

Sim800LIndex++;

Serial.print( Sim800L[Sim800LIndex-1]);

}

mySerial.print(" ENTER THE TXT YOU WISH TO SEND IN THE SMS ");

mySerial.write(0x1A);

*/

Serial.print(" CHECK THE DESTINATION DEVICE ");

}

void loop()

{

while (1)

{

while (Serial.available())

{

Sim800L[Sim800LIndex] = Serial.read();

Sim800LIndex++;

mySerial.print( Sim800L[Sim800LIndex - 1]);

}

while (mySerial.available())

{

Sim800L[Sim800LIndex] = mySerial.read();

Sim800LIndex++;

Serial.print( Sim800L[Sim800LIndex - 1]);

if (Sim800L[Sim800LIndex - 6] == '+' && Sim800L[Sim800LIndex - 5] == 'C' && Sim800L[Sim800LIndex - 4] == 'M' && Sim800L[Sim800LIndex - 3] == 'T' && Sim800L[Sim800LIndex - 2] == 'I' && Sim800L[Sim800LIndex - 1] == ':')

{

SMSmemory = 1;

NewSMSArrived = 1;

}

if (SMSmemory == 1)

{

if (Sim800L[Sim800LIndex - 1] == ',')

{

smsMemory[0] = Sim800L[Sim800LIndex - 4] ;

smsMemory[1] = Sim800L[Sim800LIndex - 3] ;

smsMemory[2] = '\0' ;

SMSmemory = 0;

}

}

delay(5);

} // end of while mySerial.available()

if (NewSMSArrived == 1)

{

int j = 0;

while (Sim800L[j] != '\0')

{

j++;

}

for (int i = 0; i < j ; i++)

{

SMS[i] = Sim800L[i];

}

NewSMSArrived = 0;

Serial.println(SMS);

while (SMS[j - 1] != ',')

{

j--;

}

int i = 0;

while (SMS[j - 1] != '\0' )

{

SmS_Index[i] = SMS[j];

i++;

j++;

}

Serial.println("SMS index is as follow ");

Serial.println(SmS_Index);

Serial.println("SMS Memory is as follow ");

Serial.println(smsMemory);

Serial.println("");

Serial.println(" NEW SMS ARRIVED ");

Serial.println("");

mySerial.print("AT+CMGR=");

mySerial.print(SmS_Index);

mySerial.print("\r");

}

}

}

 

 

     

Sending the SMS Using sim800l: 

#include <SoftwareSerial.h>
String inputString="";
String fromGSM="";
SoftwareSerial mySerial(3,2);
char sim800l[255],SMS[255];
int sim800lIndex=0,SMS_Index=0;
bool NewSMSArrived=0;

void setup() 
{
Serial.begin(9600);
mySerial.begin(9600);
Serial.println(" Command --> AT ");
mySerial.print("AT");
mySerial.print("\r");
delay(100);
Serial.print(" Response --> ");
while(mySerial.available())
{ 
sim800l[sim800lIndex] = mySerial.read();
sim800lIndex++;
Serial.print( sim800l[sim800lIndex-1]);
}
sim800lIndex=0;
Serial.println("");
Serial.println(" Command --> ATEO ");
mySerial.print("ATE0");
mySerial.print("\r");
delay(100);
Serial.print(" Response --> ");
while(mySerial.available())
{ 
sim800l[sim800lIndex] = mySerial.read();
sim800lIndex++;
Serial.print( sim800l[sim800lIndex-1]);
}
sim800lIndex=0;
Serial.println("");

Serial.println(" Command --> AT+CFUN=1 ");
mySerial.print("AT+CFUN =1");
mySerial.print("\r");
delay(100);
Serial.print(" Response --> ");
// while( ! (mySerial.available()) );
while(mySerial.available())
{ 
sim800l[sim800lIndex] = mySerial.read();
sim800lIndex++;
Serial.print( sim800l[sim800lIndex-1]);
}
sim800lIndex=0;
Serial.println("");

Serial.println(" Command --> AT+CMGF=1 ");
Serial.print(" Response --> ");
mySerial.print("AT+CMGF =1");
mySerial.print("\r");
delay(100);
// while( ! (mySerial.available()) );
while(mySerial.available())
{ 
sim800l[sim800lIndex] = mySerial.read();
sim800lIndex++;
Serial.print( sim800l[sim800lIndex-1]);
}

Serial.println(" Command --> AT+CSCS=\"GSM\"");
Serial.print(" Response --> ");
mySerial.print("AT+CSCS =\"GSM\"");
mySerial.print("\r");
delay(100);
// while( ! (mySerial.available()) );
while(mySerial.available())
{ 
sim800l[sim800lIndex] = mySerial.read();
sim800lIndex++;
Serial.print( sim800l[sim800lIndex-1]);
}

Serial.println(" Command --> AT+CPMS=\"SM\"");
Serial.print(" Response --> ");
mySerial.print("AT+CPMS =\"SM\"");
mySerial.print("\r");
delay(100);
// while( ! (mySerial.available()) );
while(mySerial.available())
{ 
sim800l[sim800lIndex] = mySerial.read();
sim800lIndex++;
Serial.print( sim800l[sim800lIndex-1]);
}

Serial.println(" Command --> AT+CMGS=\"4444444444\"");
Serial.print(" Response --> ");
mySerial.print("AT+CMGS=\"4444444444\"");
mySerial.print("\n");
delay(100);
// while( ! (mySerial.available()) );
while(mySerial.available())
{ 
sim800l[sim800lIndex] = mySerial.read();
sim800lIndex++;
Serial.print( sim800l[sim800lIndex-1]);
}
mySerial.print(" ENTER THE TXT YOU WISH TO SEND IN THE SMS "); // txt msg
mySerial.write(0x1A);

Serial.print(" CHECK THE DESTINATION DEVICE ");

}

void loop() 
{ 
while(1)
{
while(Serial.available())
{ 
sim800l[sim800lIndex] = Serial.read();
sim800lIndex++;
mySerial.print( sim800l[sim800lIndex-1]);
}
while(mySerial.available())
{ 
sim800l[sim800lIndex] = mySerial.read();
sim800lIndex++;
/* if(sim800l[sim800lIndex-5]=='+'&&sim800l[sim800lIndex-4]=='C'&&sim800l[sim800lIndex-3]=='M'&&sim800l[sim800lIndex-2]=='T'&&sim800l[sim800lIndex-1]=='I')
{
NewSMSArrived=1; 
} */
Serial.print( sim800l[sim800lIndex-1]);
}

/* if(NewSMSArrived == 1)
{
for(int i=0;i= (sim800lIndex-1);i++)
{
SMS[i] = sim800l[i];
}
NewSMSArrived=0;
Serial.print(SMS);
} */
} 
} 






 

Conclusion – 

    In this section, we have talked about what sim800l is, SIM800l’s interface with Arduino and we learned troubleshooting guides. Congratulations!! You are now well versed in sim800l operations. I hope this blog helps in your project. If there is any doubt, please let us know in the comment section. Thank you have a nice day! 

 


About the Author


Submit a Review

Display Name

Email

Title

Message