Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
SurtrTech
Published © GPL3+

Send SMS/Text From Arduino Using SIM800L GSM/GPRS Module

Easy tu torial on how to send a simple text + send sensor values, here used DHT11 as example.

BeginnerFull instructions provided1 hour97,054
Send SMS/Text From Arduino Using SIM800L GSM/GPRS Module

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
DigitSpace SIM800L
×1
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Wiring 1

Wiring 2

Code

SIM800L_Simple_text.ino

Arduino
Send simple SMS/Text
/* This code works with Sim800L and a push button
 * Press the button to send a simple SMS/Text to a specified phone number
 * Refer to www.SurtrTech.com for more details 
 */

#include <SoftwareSerial.h>

SoftwareSerial sim800l(2, 3); // RX,TX for Arduino and for the module it's TXD RXD, they should be inverted

#define button1 7 //Button pin, on the other pin it's wired with GND

bool button_State; //Button state


void setup()
{
 
  pinMode(button1, INPUT_PULLUP); //The button is always on HIGH level, when pressed it goes LOW
  sim800l.begin(9600);   //Module baude rate, this is on max, it depends on the version
  Serial.begin(9600);   
  delay(1000);
}
 
void loop()
{
  

  button_State = digitalRead(button1);   //We are constantly reading the button State
 
  if (button_State == LOW) {            //And if it's pressed
    Serial.println("Button pressed");   //Shows this message on the serial monitor
    delay(200);                         //Small delay to avoid detecting the button press many times
    
    SendSMS();                          //And this function is called

 }
 
  if (sim800l.available()){            //Displays on the serial monitor if there's a communication from the module
    Serial.write(sim800l.read()); 
  }
}
 
void SendSMS()
{
  Serial.println("Sending SMS...");               //Show this message on serial monitor
  sim800l.print("AT+CMGF=1\r");                   //Set the module to SMS mode
  delay(100);
  sim800l.print("AT+CMGS=\"+*********\"\r");  //Your phone number don't forget to include your country code, example +212123456789"
  delay(500);
  sim800l.print("SIM800l is working");       //This is the text to send to the phone number, don't make it too long or you have to modify the SoftwareSerial buffer
  delay(500);
  sim800l.print((char)26);// (required according to the datasheet)
  delay(500);
  sim800l.println();
  Serial.println("Text Sent.");
  delay(500);

}
 

SIM800L_SMS_DHT.ino

Arduino
Send DHT11 data to phone via SMS
/* This code works with Sim800L, a push button and DHT11
 * Press the button to send a simple SMS/Text containing the Temperature and humidity values to a specified phone number
 * Refer to www.SurtrTech.com for more details 
 */

#include <SoftwareSerial.h>    //Libraries required for the Serial communication and DHT
#include "DHT.h"

#define DHTpin 8             //DHT signal pin
#define DHTTYPE DHT11        //DHT type
#define button1 7            //Button pin, the other pin is wired with GND

bool button_State;          //Stores the button state
String Data_SMS;            //String that we're going to send via SMS
float t,h;                  //Stores the Temperature and humidity

SoftwareSerial sim800l(2, 3); // RX,TX for Arduino and for the module it's TXD RXD, they should be inverted
DHT dht(DHTpin, DHTTYPE);     // Declaring the dht

void setup()
{
  pinMode(button1, INPUT_PULLUP); //The button is always on HIGH level, when pressed it goes LOW
  sim800l.begin(9600);   //Module baude rate, this is on max, it depends on the version
  Serial.begin(9600); 
  dht.begin();           //Start the DHT
  delay(1000);
}
 
void loop()
{
   h = dht.readHumidity();            //Read the humidity and temperature in % and C
   t = dht.readTemperature();
    
  button_State = digitalRead(button1); //Reading the button state too
 
  if (button_State == LOW) {           //If the button is pressed
    Serial.println("Button pressed");  //Displays this message
    delay(200); //Delay to avoid reading the button state many times
    
    Send_DHT_Data();                   //And call this function

 }
 
  Serialcom();         //If no SMS is being sent we constantly call this function, it permits the communication between you and the module via the serial monitor
                       //You can try AT commands and check the feedback, also sending message is an AT command
  
}
 
void Send_DHT_Data()
{
  Serial.println("Sending Data...");     //Displays on the serial monitor
  sim800l.print("AT+CMGF=1\r");          // Set the shield to SMS mode
  delay(100);
  sim800l.print("AT+CMGS=\"+***********\"\r");  //Your phone number don't forget to include your country code example +212xxxxxxxxx"
  delay(500);
  Data_SMS = "Temperature = "+String(t,1)+" C" + " \nHumidity ="+String(h,1)+ " %";   //A string to regroup the whole message as it's composed of Strings and Float --> to a single string,
                                                                                      //Example: Temperature 23.1 C
                                                                                      //         Humidity 40 %
  sim800l.print(Data_SMS);  //This string is sent as SMS
  delay(500);
  sim800l.print((char)26);//(required according to the datasheet)
  delay(500);
  sim800l.println();
  Serial.println("Data Sent.");
  delay(500);

}

void Serialcom()
{
  delay(500);
  while (Serial.available()) 
  {
    sim800l.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(sim800l.available()) 
  {
    Serial.write(sim800l.read());//Forward what Software Serial received to Serial Port
  }
}
 

Credits

SurtrTech
9 projects • 207 followers
YT Channel bit.ly/35Ai76l, run by Automation and Electrical Engineer, Electronics amateur, no IT background so you may see wreckage in codes

Comments