Skip to content

Send/Receive SMS using SIM800L with Arduino + DHT11/MLX90614 [DigitSpace.com]

 

 

Hello everyone, and welcome to another tutorial Sponsored by: DigitSpace
Product used: SIM800L Module Replace SIM900A GSM GPRS 5V Serial with Antenna

This tutorial is a follow up of two previous ones, make sure to check them, to be able to use the SIM800L module easily:

Summary:

So on this one we gonna first check how to receive SMS/Text and displays it on the Arduino IDE Serial monitor, and as a project we gonna request data to be sent to us all via SMS: I’ll add two sensors (as example) DHT11 and MLX90614 Contactless thermal sensor, and I’ll send a SMS from my phone containing “DHT” or “MLX” and Arduino will have to look for one of those keywords within the received SMS, and then send the measured values, depending on which sensor the user chosed, by SMS to the programmed phone number.

You can use your own modules, the number of them, send multiple SMS…. it all depends on you, give it a try.

Halt !!

Yes I use this in pretty much all tutorials related to SIM800L, because it’s easy to forget about, the SIM card you are using shouldn’t be protected with a “pin code”, if it’s the case you can either put it in your phone for example and deactivate the “sim lock” from the phone… Or you can use the suitable “AT command” to enter the pincode from Arduino directly which is “AT+CPIN”, I didn’t use this last method but here you can find all “AT commands” to use the module:

SIM800L Full manual of AT commands

Another thing that some may forget about is that your SIM card should have enough credit to be able to send a SMS, it depends on your network provider.

Enough talking… Let’s check our stuffs

SIM800L Module Replace SIM900A GSM GPRS 5V Serial-1-550x550
SIM800L EVB

 

So this is the module I used it’s the EVB version, there are several versions and in the codes things can change so be careful.

 

 

 

 

 

bcd
SIM800L EVB pinout

 

Module pinout, the wires used are 5V/Gnd for power, and then TXD/RXD/GND to communicate with Arduino.

 

 

 

Battery + converterAnd also as I did before, I’m powering the module using a 7.5V Lipo battery, with a Buck converter to be able to power the module with 5V, so before I powered the module directly from Arduino but it was sketchy… so I switched to external power source.

 

 

Test 1

In the test#1 we gonna use a direct wiring with Arduino, set the module on the receiving SMS mode, set the way to handle the SMS received and then show it on the Arduino IDE Serial monitor.

Wiring

Wiring1_bb
The straight forward wiring for your first tests with the module

Libraries

You won’t need any external libraries for this, only the default SoftwareSerial.

Code

So the code basically just sets the module on the receiving SMS mode, sets the way to handle the SMS in the “Setup()”, but on the loop it uses a function that permits the user to check the feedback from the SIM800L and also send Commands from the serial monitor, and as we told the module to transfert the received SMS via Serial to Arduino, we gonna print the SMS received on the Serial monitor.

Download the code here

Sorry the website built-in editor doesn’t have a good code editor to be able to copy it correctly, so I uploaded it to Google Drive… I’ll try to upgrade this soon.

The code contains a lot of comments to help you.

Result

Click to expand/zoom the pictures

Test 1_1
Sending SMS from the phone
Test 1_2
SMS received will be shown on the Serial monitor

Project

So here’s the project, now we can receive the SMS and transfert it to the Arduino board, but we need to detect certain kewords within the SMS, to be able to chose which sensor data is requested, do the measures and send the Data via SMS.

So here as said, I used DHT11 and MLX90614 Contactless thermal sensor as example, you can use your “own sensors* and use how many you can* (* give a try).

Wiring

Wiring2_bb
Full wiring the Arduino is powered via USB, but you can power it using the PS too just add the 5V wire

Libraries

Two libraries should be add (Because of the modules), modules you use will define which libraries to use.

https://github.com/adafruit/DHT-sensor-library
https://github.com/adafruit/Adafruit-MLX90614-Library

Code

So the code is actually where the tricky part is, the SMS received should be stored in a “char” type variable but then we have to change it to “String” to be able to search the keywords within the SMS.

Download the code here

The code contains a lot of comments to help you understand.

Here’s a look from the code as you can see a lot of comments, and those are pretty much the tricks I did to able to achieve the objective, if you have better ones please share it with us.

code_crop

Result

Click on the pictures to expand/zoom

Test 2_1

Send SMS from phone containg DHT and Arduino replies back with DHT11 sensor values

Test 2_2
Same if MLX keyword is found within the SMS
Test 2_3
Here as you can see whatever the SMS content is it just need to find the keyword programmed

Improvements

  • You can improve the code, because that’s the trick that worked for me, maybe you have a better one, I’m sure there’s a better way.
  • You can do multiple readings + averaging before sending the SMS.
  • Improve the keyword detection so things like the last SMS won’t be counted
  • Add some commands to clear the SIM800L memory
  • Send “Error SMS” if a sensor is not working properly

 

Well that’s all folks a big thanks to DigitSpace for their sponsorship.

Sponsorlolz

 

Yassine View All

Automation and Electrical Engineer, Electronics amateur trying to share my little projects.

9 thoughts on “Send/Receive SMS using SIM800L with Arduino + DHT11/MLX90614 [DigitSpace.com] Leave a comment

  1. Sir .how to use ultrasonic sensor with gsm sim 800l with .
    My motive is to detect the ultrasonic sensor input .
    And send and receive sms. To check the input of sensor
    .need an code for that .

  2. Sir .how to use ultrasonic sensor with gsm sim 800l with .
    My motive is to detect the ultrasonic sensor input .
    And send and receive sms. To check the input of sensor
    now how to code Arduino uno

  3. Hi, excuse me. I have a error in my IDE, this is the error “compilation terminated.exit status 1
    Error compilando para la tarjeta Arduino Uno.” Some of my colleagues told me that it could be a parenthesis ( ) or { } but I checked and they are all correct. I thank you. Please Help ME 🙁 I was using the second code with DHT11.

    • Hello, what’s the full error message it will tell you if it’s a library problem or a syntax…
      I don’t think I forgot any “;” or bracket, those code I tested directly, may be you have a library problem.

  4. Hey Yassine,

    when compiling i get this messge:

    In file included from C:\Users\ELIAS\Desktop\SIM800L_RequestData\SIM800L_RequestData.ino:10:0:

    C:\Users\ELIAS\Documents\Arduino\libraries\Adafruit-MLX90614-Library-master\libraries\Adafruit_MLX90614_Library/Adafruit_MLX90614.h:18:10: fatal error: Adafruit_I2CDevice.h: No such file or directory

    #include

    ^~~~~~~~~~~~~~~~~~~~~~

    compilation terminated.

    exit status 1
    Erreur de compilation pour la carte Arduino Pro or Pro Mini

    NB: i notice that the library is installed and the arduino card is up to date.

  5. This is the error log when i compile:

    SIM800L_RequestData:34:7: error: expected constructor, destructor, or type conversion before ‘(‘ token

    DHT_OK(5, String);

    ^

    C:\Users\ELIAS\Desktop\SIM800L_RequestData\SIM800L_RequestData.ino: In function ‘void setup()’:

    SIM800L_RequestData:42:6: error: expected unqualified-id before ‘.’ token

    dht.begin();

    ^

    SIM800L_RequestData:45:3: error: ‘ReceiveMode’ was not declared in this scope

    ReceiveMode(); //Calling the function that puts the SIM800L moduleon receiving SMS mode

    ^~~~~~~~~~~

    C:\Users\ELIAS\Desktop\SIM800L_RequestData\SIM800L_RequestData.ino:45:3: note: suggested alternative: ‘Received_SMS’

    ReceiveMode(); //Calling the function that puts the SIM800L moduleon receiving SMS mode

    ^~~~~~~~~~~

    Received_SMS

    C:\Users\ELIAS\Desktop\SIM800L_RequestData\SIM800L_RequestData.ino: In function ‘void loop()’:

    SIM800L_RequestData:72:18: error: expected primary-expression before ‘.’ token

    float h = dht.readHumidity(); //Read temperature and humidity

    ^

    SIM800L_RequestData:73:18: error: expected primary-expression before ‘.’ token

    float t = dht.readTemperature();

    ^

    SIM800L_RequestData:80:5: error: ‘Send_Data’ was not declared in this scope

    Send_Data(); //This function set the sending SMS mode, prepare the phone number to which we gonna send, and send “Data_SMS” String

    ^~~~~~~~~

    SIM800L_RequestData:81:5: error: ‘ReceiveMode’ was not declared in this scope

    ReceiveMode(); //Come back to Receving SMS mode and wait for other SMS

    ^~~~~~~~~~~

    C:\Users\ELIAS\Desktop\SIM800L_RequestData\SIM800L_RequestData.ino:81:5: note: suggested alternative: ‘Received_SMS’

    ReceiveMode(); //Come back to Receving SMS mode and wait for other SMS

    ^~~~~~~~~~~

    Received_SMS

    SIM800L_RequestData:91:3: error: ‘Send_Data’ was not declared in this scope

    Send_Data();

    ^~~~~~~~~

    SIM800L_RequestData:92:3: error: ‘ReceiveMode’ was not declared in this scope

    ReceiveMode();

    ^~~~~~~~~~~

    C:\Users\ELIAS\Desktop\SIM800L_RequestData\SIM800L_RequestData.ino:92:3: note: suggested alternative: ‘Received_SMS’

    ReceiveMode();

    ^~~~~~~~~~~

    Received_SMS

    C:\Users\ELIAS\Desktop\SIM800L_RequestData\SIM800L_RequestData.ino: At global scope:

    SIM800L_RequestData:99:1: error: expected declaration before ‘}’ token

    }

    ^

    exit status 1
    expected constructor, destructor, or type conversion before ‘(‘ token

    NB: i copied and pasted, so nothing forgotten i hope.

  6. Hello, i got the others working but the code for SIM800L_RequestData show the error “exit status 1
    Error compiling for board Arduino Uno” during compiling. Can you please help me…

Leave a Reply to elias Cancel reply

%d bloggers like this: