Introduction
In this post, we will talk about how to use the sim800l module with the adafruit fona library. This board can be controlled with AT commands and offer possibilities such as call, take calls, send or receive sms or even make posts on a web page among many others.
If you want to see all the possibilities allowed by the phone library, here is a link to their github.
Requirements
Ethernet or 20 I/Os PLC:Â Â Â Â Ethernet PLCÂ Â Â 20 I/Os PLCÂ Â Â Â Â
Industrial Shields boards:   Industrial Shields Boards      Â
Adafruit FONA library:      Adafruit FONA github library     Â
   Â
Description
GPRS Module
The SIM800L module is the main component of the FONA 800 cards of Adafruit, so we can use the library made for these cards with the economic modules that assemble the SIM800L.
In this tutorial, we focus on the use of the Adafruit library, but we also show how to test the module sending AT commands by the serial monitor and also how to register the SIM card for sending text messages.
Â
Connections
Software
In this first sketch we check if the module sim800l correctly receives the AT commands. It simply expects to receive the commands through the serial port and, if the operation is correct, returns the AT response through the same serial port:
/*
  Copyright (c) 2019 Boot&Work Corp., S.L. All rights reserved
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
#define SERIAL_PORTÂ Â Serial1
////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
 Serial.begin(9600L);
 Serial.println("gprs-serial started");
 Serial1.begin(115200UL);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
 Â
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void serialEvent() {
 Serial1.write(Serial.read());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void serialEvent1() {
 Serial.write(Serial1.read());
}
This second sketch, once we have verified that it receives and sends the AT commands correctly, allows us, through the Adafruit FONA library to configure the SIM card by entering the PIN and it will indicate the registration status in which the card is located.
There are the following possibilities:
Not registered, Not registered (searching), Denied, Registered (home), or registered (roaming).
Remember to enter the mobile number to which you are going to send the SMS, the pin number of your SIM card, and the APN configuration of your SIM's telephone company.
The SMS will only be sent once and will be when the SIM card has been registered correctly (at home, not in Roaming).
 /*
  Copyright (c) 2019 Boot&Work Corp., S.L. All rights reserved
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
#include <Adafruit_FONA.h>
#define SIM800L_SERIAL Serial1
#define SIM800L_RESETÂ 2
#define PIN "XXXX" //Enter the pin code of your SIM card
#define CALL_NUM "XXXXXXXXX" //Enter the mobile number to which you want to send the SMS
Adafruit_FONA sim800l = Adafruit_FONA(SIM800L_RESET);
////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
 Serial.begin(9600L);
 Serial.println("sim800l started");
 SIM800L_SERIAL.begin(115200UL);
 sim800l.begin(SIM800L_SERIAL);
 char imei[16];
 if (sim800l.getIMEI(imei) > 0) {
  Serial.print("IMEI: ");
  Serial.println(imei);
 }
 //Find the APN configuration of your SIM card company. Here you have two examples (Yoigo and Orange configuration).
 //sim800l.setGPRSNetworkSettings(F("internet"), F(""), F("")); // YOIGO
 //sim800l.setGPRSNetworkSettings(F("orangeworld"), F("orange"), F("orange")); // ORANGE
 if (sim800l.unlockSIM((char*)PIN)) {
  Serial.println("PIN OK");  Â
 }
 else {
  Serial.println("PIN FAIL");
 }
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
 static uint32_t lastStatusRead = millis();
 if (millis() - lastStatusRead > 3000) {
  lastStatusRead = millis();
  int networkStatus = sim800l.getNetworkStatus();
  switch (networkStatus) {
   case 0:
    Serial.println("Not registered");
    sim800l.enableGPRS(true);
    break;
   case 1:
    Serial.println("Registered (home)");
    sendSMS();
    break;
   case 2:
    Serial.println("Not registered (searching)");
    break;
   case 3:
    Serial.println("Denied");
    sim800l.enableGPRS(true);
    break;
   case 4:
    Serial.println("Unknown");
    sim800l.enableGPRS(true);
    break;
   case 5:
    Serial.println("Registered (roaming)");
    break;
  }
 }
}
void sendSMS() {
 static bool sent = false;
 if (!sent) {
  sent = true;
  sim800l.sendSMS(CALL_NUM, "Industrial Shields says Hi everyone!");Â
  Serial.println("message sent");
 } Â
}