Hello. This project is part of a much bigger project. Because I had a lot of problems with this part and eventually found a solution, I decided to share it with the community and hope it may help them on their projects.
Send SMS to Arduino and get the temperature at home.Software
For the SIM800L module, I used “Seeeduino_GPRS-master” Library. I had to change the following lines in the “sim800.h” Library to enable it to work on a MEGA:
#define SIM800_TX_PIN 8 #define SIM800_RX_PIN 7
...to TX_PIN 10 and RX_PIN 11. To change the Library from “SoftwareSerial” to one of the Mega Serial ports, i.e. Serial3, was too difficult so I took the easy way out.
Basically, my code is cut and paste examples from two libraries: “DHT.h “ and “Seeeduino_GPRS-master”. The problem I had was that the “gprs.h” example only showed how to send a predetermined message in quotes. I couldn’t work out how to send the variable float value from my temperature sensor. This was also true with other libraries I tried: “GPRS_SIM900-master” and “SIM800L-master” .
I had spent weeks searching the WEB for examples to solve my problem and found none. I had found forum postings on the same subject, and for those poor lost souls who didn’t get answers, I hope you find this posting.
Convert the float value to a String and then the String to a Char Array - simple!Code Snippet
MyString = String(temp,0); //Convert float to String MyString = (MyString + " Degrees C"); // convert string to char starts here // Length (with one extra character for the null terminator) int str_len = MyString.length() + 1; // Prepare the character array (the buffer) char char_array[str_len]; // Copy it over MyString.toCharArray(char_array, str_len); // convert string to char ends here gprs.sendSMS("04++++++++",char_array); //define phone number and text.
I used a ULTRAFIRE 18650 battery to supply power to the sim module. Later I will add a voltage regulator to the circuit. See this tutorial.