Advertisement

How to Play with SIM800L — Part 2/2

Because the SIM800L module is very flexible, a great GSM project design can be relatively simple. But there are a number of reasons for experimenting with more complex ideas, such as enhanced performance and the ability to incorporate customized options. Of course, one major disadvantage of complex designs is that it can take a DIYer weeks to locate and purchase the requisite components, not to mention the time to construct and troubleshoot the project. Surprisingly, today’s microcontroller platforms are both simple and complex in nature but are relatively easy to play with. For most DIYers short on skill and patience, the Arduino is a nice entry into the world of such complex design ideas. The following is an example for testing AT commands with Arduino Uno. It’s assumed that you’ve already tested AT commands successfully in your SIM800L module with a USB-to-serial tool as advised in the first part of this tutorial. Let’s proceed to the next level!

 

SIM800L & Arduino Uno

 

Hardware

To start, set up the hardware as shown below. Naturally, you’re going to need a valid SIM card to fully use the SIM800L module. For compactness, my setup was tested with a 1S (3.7-V) Li-ion battery (with 2,700-mAh capacity) removed from my smartphone. Next, upload the test sketch to Arduino Uno as usual. I used the given sketch to test SIM800L with Arduino Uno. Finally, open the Arduino Serial Monitor and test the recommended AT commands.

 

Test Sketch

 

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); 

void setup()

{



Serial.begin(9600);

mySerial.begin(9600);

}

void loop() 

{

if (mySerial.available())

Serial.write(mySerial.read());

if (Serial.available())

{

while(Serial.available())

{

mySerial.write(Serial.read());

}

mySerial.println();

}

}

AT Commands

 

Command Description
AT Synchronize baud rate
AT+IPR=9600 Set baud rate at 9,600 bps
AT+CBC Inquire charging status and remaining battery capacity
AT+CSQ Inquire GSM signal quality
AT+GSV Display product identification information

 

Here is a screenshot of my Serial Monitor (see the return values):

 

For serious project builders, it’s better to refer to the “SIM800 Series AT Command Manual_V1.09” to learn more about the mystical return values. As an example, the return value “+CBC: 0,62,3900” in my window states that:

 

  • 0 — not charging
  • 62 — 62% of the battery capacity remains
  • 3,900 — battery voltage is 3,900 mV (3.9 V)

 

Quick reminder: The serial communication lines (TXD & RXD) of the SIM800L module used here are for 3.3-V level operation. Although I just wired them to my 5-V Arduino Uno for the quick test without a logic-level converter, I strongly recommend the usage of an appropriate logic-level shifter (see the quick start section in the first part of this tutorial).

 

Arduino GSM Alert — DIY

 

Here’s an application example configured to send an SMS in response to a security switch action. In this cellular-based alert system, once the security sensor switch recognizes an event (i.e., when the normally opened switch flips to a closed state), the system sends a customized alert message to a predefined cellphone number. The following is a hardware diagram of the Arduino GSM Alert system built around an Arduino Uno and SIM800L module. When the hardware setup is ready, just upload the given sketch to Arduino Uno and take a test run!

 

/*

* Arduino GSM Alert (v1.0)

* An Arduino Uno + SIM800L GSM Module Project

* T.K.Hareendran / 2018

*/

//Connect the Tx pin of the SIM800L module to D10

//Connect the Rx pin of the SIM800L module to D11

//SMS Trigger Input (Sense Pin) connected to D3 (Active LOW)

// Connect a push-to-on button switch between D3 and GND

// Push the button switch/ground D3 to send a pre-defined SMS



#include <SoftwareSerial.h>

SoftwareSerial smsSerial(10,11); // RX and TX pins to communicate with SIM800L module

#define sense_pin 3

String number ="1234567890"; // Replace this 10-digits with  recipient's number

void setup()

{

   Serial.begin(9600);

  smsSerial.begin(9600);

   pinMode(sense_pin,INPUT);

   digitalWrite(sense_pin,HIGH);



}

void loop()

{

   //Sends an sms everytime sense_pin sets off

   if (digitalRead(sense_pin)==LOW) // Check if the sense_pin sets off

   {

     smsSerial.println("AT+CMGF=1"); // Set the Mode as Text Mode

      delay(150);

      smsSerial.println("AT+CMGS=\"+91"+number+"\""); // Specify the recipient's number in international format by replacing the 91

      delay(150);

      smsSerial.print("Warning! SIM800L"); // Enter the custom message

      delay(150);

      smsSerial.write((byte)0x1A); // End of message character 0x1A : Equivalent to Ctrl+z

      delay(50);

      smsSerial.println();

   }



}




 

My hardware

 

Screenshot of proof-of-concept

 

This is not a full-fledged design but a simplified version without any dedicated Arduino libraries. My initial intention was to power the SIM800L module from a 3.7-V Li-ion battery (because it draws a lot of current for proper operation) and power the Arduino Uno from a 9-V alkaline battery. Later, I omitted the 9-V alkaline battery and used a “DC/DC boost converter module” to supply 5-V DC to the Arduino Uno board from the 3.7-V Li-ion battery (I didn’t want to use two batteries in a simple project).

 

 

A second, enriched version of the same project is now under development. The concept is trimmed especially for a portable security system project in a small box and powered by a 3.7-V battery. In the meantime, maybe you can fabricate something different based on your own project ideas inspired by my tutorial. Be creative!

No Comments

Join the conversation!

Error! Please fill all fields.
Looking for the latest from TI?