Site icon SURTR TECHNOLOGY

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

Send/Receive SMS using SIM800L + Arduino (Request sensor values) | 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 to the Arduino 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 choosed, by SMS to the programmed phone number.

You can use your own modules, chose how many of them, send multiple SMS to multiple phones…. 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 pin code 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 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.

 

 

 

 

 

SIM800L EVB pinout

 

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

 

 

 

Lithium battery + converter

And 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

SIM800L Wired with Arduino UNO board

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 transfer the received SMS via Serial to Arduino, we gonna print the SMS received on the Serial monitor.

Download the code here or check below. The code contains a lot of comments to help you.



Result

After wiring the module and plugging the Arduino, the uploaded code will automatically set the mode for the SIM800l to receive texts/SMS, then we send a SMS from the phone.

Sending SMS from the phone

The SMS received is now displayed on the Serial monitor alongside the phone number.

SMS received will be shown on the Serial monitor

Project: Requesting specific sensor data

So here’s the project, now we can receive SMSs and transfer them to the Arduino board, but we need to detect certain keywords 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 mentioned above, I used DHT11 and MLX90614 Contactless thermal sensor as example, you can use your own sensors* and use how many you can* (* give it a try).

Wiring

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

SIM800L wired with Arduino UNO board and other sensors



Libraries

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

Pay attention to the libraries used, as from time to time they get updated, if you download them from Github make sure to test them first and adapt them to your project.

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.

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 snippet

Download the code here or check below. The code contains a lot of comments to help you understand.



Result

After plugging the Arduino open the serial monitor, you’ll see that the module’s mode has been set, then send a SMS containing the keyword you already set in the code. Here I sent just simple “DHT” and you can see that the Arduino has “found DHT” retrieved the data and displayed it on the serial monitor (before “Sending Data”)

Then the data has been sent and you’ll see a feedback on the monitor showing the message partially.

And last, on the phone you can see the data received.

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

Now we repeat the test by sending the other keyword we already set.

Same if MLX keyword is found within the SMS

Here I send a nonsense but it contains the word “DHT”.

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.

 

Exit mobile version