{"id":89131,"date":"2019-09-12T11:10:28","date_gmt":"2019-09-12T11:10:28","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=89131"},"modified":"2020-07-30T14:09:05","modified_gmt":"2020-07-30T14:09:05","slug":"esp32-sim800l-send-text-messages-sms","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp32-sim800l-send-text-messages-sms\/","title":{"rendered":"ESP32 SIM800L: Send Text Messages (SMS Alert) with Sensor Readings"},"content":{"rendered":"\n<p>In this project we\u2019re going to create an SMS notification system with the T-Call ESP32 SIM800L module that sends an SMS when sensor readings are above or below a certain threshold. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/ESP32-SIM800L-Send-Text-Message-SMS-Temperature.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 SIM800L Send Text Messages (SMS Alert) with Sensor Readings\" class=\"wp-image-89261\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/ESP32-SIM800L-Send-Text-Message-SMS-Temperature.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/ESP32-SIM800L-Send-Text-Message-SMS-Temperature.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/ESP32-SIM800L-Send-Text-Message-SMS-Temperature.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/ESP32-SIM800L-Send-Text-Message-SMS-Temperature.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n\n<p>In this example, we\u2019ll use a <a href=\"https:\/\/randomnerdtutorials.com\/esp32-ds18b20-temperature-arduino-ide\/\">DS18B20 temperature sensor<\/a>, and we\u2019ll send a text message when the temperature is above 28\u00baC. Once the temperature has decreased below the threshold, we\u2019ll send another SMS alert. <\/p>\n\n\n\n<p class=\"rntbox rntclblue\">To send an SMS with the T-Call ESP32 SIM800L module, you just need to use <span class=\"rnthl rntliteral\">modem.sendSMS(SMS_TARGET, smsMessage)<\/span> after initializing a <span class=\"rnthl rntliteral\">modem<\/span> object for the SIM800L module (using the TinyGSM library).<\/p>\n\n\n\n<p class=\"rntbox rntcred\"><strong>Important: <\/strong> the SIM800L works on 2G networks, so it will only work in your country, if 2G networks are available. Check if you have 2G network in your country, otherwise it won\u2019t work.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Watch the Video Tutorial<\/h2>\n\n\n\n<p>You can watch the video tutorial or continue reading for the complete project instructions.<\/p>\n\n\n<p style=\"text-align:center\"><iframe width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/VM-viZHZvAs?rel=0\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Project Overview<\/h2>\n\n\n\n<p>This tutorial is divided into two sections:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>Send an SMS with the TTGO T-Call ESP32 SIM800L<\/strong>: you&#8217;ll learn how to send a simple &#8220;Hello World&#8221; message.<\/li><li><strong>SMS Notification system with sensor readings<\/strong>: send a message every time the temperature readings cross the threshold value.<\/li><\/ol>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Project-overview-for-post-send-SMS.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"850\" height=\"530\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Project-overview-for-post-send-SMS.png?resize=850%2C530&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"SMS Notification System with Sensor Readings using the T-Call ESP32 SIM800L Board\" class=\"wp-image-89212\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Project-overview-for-post-send-SMS.png?w=850&amp;quality=100&amp;strip=all&amp;ssl=1 850w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Project-overview-for-post-send-SMS.png?resize=300%2C187&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Project-overview-for-post-send-SMS.png?resize=768%2C479&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/a><\/figure><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li>The ESP32 gets new temperature readings every 5 seconds<\/li><li>It checks if the temperature is above the threshold value<\/li><li>If it&#8217;s above the threshold value, it sends an alert SMS with the current temperature value<\/li><li>When the temperature goes below the threshold, it sends another alert<\/li><li>The ESP32 sends only one SMS every time the temperature readings cross the threshold value<\/li><\/ul>\n\n\n\n<p>You can modify this project for your specific case. For example, you may want to put the <a href=\"https:\/\/randomnerdtutorials.com\/esp32-timer-wake-up-deep-sleep\/\">ESP32 in deep sleep mode<\/a> and send an SMS every hour with the current temperature readings, etc.<\/p>\n\n\n\n<p><strong>You may also like: <\/strong><a href=\"https:\/\/randomnerdtutorials.com\/esp32-sim800l-publish-data-to-cloud\/\">ESP32 Publish Data to Cloud without Wi-Fi (TTGO T-Call ESP32 SIM800L)<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">TTGO T-Call ESP32 SIM800L<\/h2>\n\n\n\n<p>The TTGO T-Call is a new ESP32 development board that combines a SIM800L GSM\/GPRS module.&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/ttgo-t-call-esp32-sim800\/\" target=\"_blank\">You can get if for approximately $11<\/a>.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/ESP32-SIM800L-GPRS-Module.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"TTGO T-Call ESP32 SIM800L Board\" class=\"wp-image-88988\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/ESP32-SIM800L-GPRS-Module.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/ESP32-SIM800L-GPRS-Module.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>Besides Wi-Fi and Bluetooth, you can communicate with this ESP32 board using SMS, phone calls or you can connect it to the internet. In this tutorial, you\u2019ll learn how to send an SMS notification.<\/p>\n\n\n\n<p>For a complete overview of this board, you can read the following article: <a rel=\"noreferrer noopener\" aria-label=\"$11 TTGO T-Call ESP32 with SIM800L GSM\/GPRS (Overview) (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/ttgo-t-call-esp32-with-sim800l-gsm-gprs\/\" target=\"_blank\">$11 TTGO T-Call ESP32 with SIM800L GSM\/GPRS (Overview)<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. ESP32 add-on Arduino IDE<\/h3>\n\n\n\n<p>We\u2019ll program the ESP32 using Arduino IDE. So, you need to have the ESP32 add-on installed in your Arduino IDE. Follow the next tutorial, if you haven\u2019t already.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/installing-the-esp32-board-in-arduino-ide-windows-instructions\/\">Installing the ESP32 Board in Arduino IDE (Windows, Mac OS X, Linux)<\/a><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. Prepaid SIM Card (SMS plan)<\/h3>\n\n\n\n<p>To use the TTGO T-Call ESP32 SIM800L board, you need a nano SIM card. We recommend using a SIM card with a prepaid or monthly plan, so that you know exactly how much you\u2019ll spend.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/ESP32-SIM800L-insert-sim-card.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"TTGO T-Call ESP32 SIM800L Insert nano SIM card\" class=\"wp-image-89214\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/ESP32-SIM800L-insert-sim-card.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/ESP32-SIM800L-insert-sim-card.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">3. Libraries<\/h3>\n\n\n\n<p>For this project ,you also need to install the <a rel=\"noreferrer noopener\" aria-label=\"TinyGSM library (opens in a new tab)\" href=\"https:\/\/github.com\/vshymanskyy\/TinyGSM\" target=\"_blank\">TinyGSM library<\/a> to interface with the SIM800L module and the&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/PaulStoffregen\/OneWire\" target=\"_blank\">One Wire library by Paul Stoffregen<\/a>&nbsp;and the&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/milesburton\/Arduino-Temperature-Control-Library\" target=\"_blank\">Dallas Temperature library<\/a> to get readings from the DS18B20 temperature sensor.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Installing the TinyGSM Library<\/h4>\n\n\n\n<p>Open your Arduino IDE and go to&nbsp;<strong>Sketch&nbsp;<\/strong>&gt;&nbsp;<strong>Include Library<\/strong>&nbsp;&gt;&nbsp;<strong>Manage Libraries<\/strong>. The Library Manager should open. Search for&nbsp;<strong>TinyGSM<\/strong>. Select the TinyGSM library by Volodymyr Shymanskyy.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"786\" height=\"443\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/08\/Install-TinyGSM-Library-Arduino-IDE.png?resize=786%2C443&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Installing TinyGSM library Arduino IDE\" class=\"wp-image-88782\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/08\/Install-TinyGSM-Library-Arduino-IDE.png?w=786&amp;quality=100&amp;strip=all&amp;ssl=1 786w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/08\/Install-TinyGSM-Library-Arduino-IDE.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/08\/Install-TinyGSM-Library-Arduino-IDE.png?resize=768%2C433&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/figure><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Installing DS18B20 Libraries<\/h4>\n\n\n\n<p>In the Arduino IDE Library Manager, type \u201c<strong>onewire<\/strong>\u201d in the search box and install OneWire library by Paul Stoffregen.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"786\" height=\"443\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/install-onewire-library.png?resize=786%2C443&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Install OneWire library by Paul Stoffregen in Arduino IDE\" class=\"wp-image-86581\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/install-onewire-library.png?w=786&amp;quality=100&amp;strip=all&amp;ssl=1 786w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/install-onewire-library.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/install-onewire-library.png?resize=768%2C433&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/figure><\/div>\n\n\n\n<p>Then, search for \u201c<strong>Dallas<\/strong>\u201d and install DallasTemperature library by Miles Burton.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"787\" height=\"443\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/install-dallas-temperature.png?resize=787%2C443&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Install DallasTemperature library by Miles Burton in Arduino IDE\" class=\"wp-image-86582\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/install-dallas-temperature.png?w=787&amp;quality=100&amp;strip=all&amp;ssl=1 787w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/install-dallas-temperature.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/install-dallas-temperature.png?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 787px) 100vw, 787px\" \/><\/figure><\/div>\n\n\n\n<p>After installing the libraries, restart your Arduino IDE.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Parts Required<\/h2>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"424\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/ESP32-SIM800L-DS18B20-circuit.jpg?resize=750%2C424&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"T-Call ESP32 SIM800L DS18B20 Temperature Sensor Circuit\" class=\"wp-image-89215\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/ESP32-SIM800L-DS18B20-circuit.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/ESP32-SIM800L-DS18B20-circuit.jpg?resize=300%2C170&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>To follow this tutorial you need the following parts:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/ttgo-t-call-esp32-sim800\/\" target=\"_blank\"><strong>TTGO T-Call ESP32 SIM800L<\/strong><\/a><\/li><li>Nano SIM card with SMS plan <\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/usb-c-data-charging-cable\/\" target=\"_blank\">USB-C cable<\/a><\/li><li><a rel=\"noreferrer noopener nofollow\" href=\"https:\/\/rover.ebay.com\/rover\/1\/711-53200-19255-0\/1?ff3=2&amp;toolid=10044&amp;campid=5338179998&amp;customid=MakerAdvisorT&amp;lgeo=1&amp;vectorid=229466&amp;item=311649924872\" target=\"_blank\">Antenna&nbsp;<\/a>(optional)<\/li><li><a rel=\"noreferrer noopener\" aria-label=\"DS18B20 temperature sensor (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/ds18b20-temperature-sensor-2\/\" target=\"_blank\">DS18B20 temperature sensor<\/a> (<a href=\"https:\/\/randomnerdtutorials.com\/esp32-ds18b20-temperature-arduino-ide\/\">Guide for DS18B20 sensor with ESP32<\/a>)<\/li><li><a rel=\"noreferrer noopener\" aria-label=\"4.7k Ohm resistor\u2028 (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\">4.7k Ohm resistor<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\">Breadboard<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\">Jumper wires<\/a> <\/li><\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<p><strong>Note: <\/strong> we had some signal strength issues with the antenna that came with the board package, so we\u2019ve used <a rel=\"noreferrer noopener nofollow\" aria-label=\"another antenna (opens in a new tab)\" href=\"https:\/\/rover.ebay.com\/rover\/1\/711-53200-19255-0\/1?ff3=2&amp;toolid=10044&amp;campid=5338179998&amp;customid=MakerAdvisorT&amp;lgeo=1&amp;vectorid=229466&amp;item=311649924872\" target=\"_blank\">another antenna<\/a> (as shown below) and all those connection problems were solved.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"420\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/ESP32-SIM800-another-antenna.jpg?resize=750%2C420&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Alternative Antenna for TTGO T-Call ESP32 SIM800L Board\" class=\"wp-image-88992\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/ESP32-SIM800-another-antenna.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/ESP32-SIM800-another-antenna.jpg?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Send SMS with T-Call ESP32 SIM800L<\/h2>\n\n\n\n<p>In this section, we&#8217;ll show you how to send an SMS with the T-Call ESP32 SIM800L board. Let&#8217;s build a simple example that sends an &#8220;<strong>Hello from ESP32!<\/strong>&#8221; message to your smartphone.<\/p>\n\n\n\n<p>Copy the following code to your Arduino IDE. But don&#8217;t upload it yet, you need to insert the recipient&#8217;s phone number in the code.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n  Rui Santos\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-sim800l-send-text-messages-sms\/\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files.\n  \n  The above copyright notice and this permission notice shall be included in all\n  copies or substantial portions of the Software.\n*\/\n\n\/\/ SIM card PIN (leave empty, if not defined)\nconst char simPIN[]   = &quot;&quot;;\n\n\/\/ Your phone number to send SMS: + (plus sign) and country code, for Portugal +351, followed by phone number\n\/\/ SMS_TARGET Example for Portugal +351XXXXXXXXX\n#define SMS_TARGET  &quot;+351XXXXXXXXX&quot;\n\n\/\/ Configure TinyGSM library\n#define TINY_GSM_MODEM_SIM800      \/\/ Modem is SIM800\n#define TINY_GSM_RX_BUFFER   1024  \/\/ Set RX buffer to 1Kb\n\n#include &lt;Wire.h&gt;\n#include &lt;TinyGsmClient.h&gt;\n\n\/\/ TTGO T-Call pins\n#define MODEM_RST            5\n#define MODEM_PWKEY          4\n#define MODEM_POWER_ON       23\n#define MODEM_TX             27\n#define MODEM_RX             26\n#define I2C_SDA              21\n#define I2C_SCL              22\n\n\/\/ Set serial for debug console (to Serial Monitor, default speed 115200)\n#define SerialMon Serial\n\/\/ Set serial for AT commands (to SIM800 module)\n#define SerialAT  Serial1\n\n\/\/ Define the serial console for debug prints, if needed\n\/\/#define DUMP_AT_COMMANDS\n\n#ifdef DUMP_AT_COMMANDS\n  #include &lt;StreamDebugger.h&gt;\n  StreamDebugger debugger(SerialAT, SerialMon);\n  TinyGsm modem(debugger);\n#else\n  TinyGsm modem(SerialAT);\n#endif\n\n#define IP5306_ADDR          0x75\n#define IP5306_REG_SYS_CTL0  0x00\n\nbool setPowerBoostKeepOn(int en){\n  Wire.beginTransmission(IP5306_ADDR);\n  Wire.write(IP5306_REG_SYS_CTL0);\n  if (en) {\n    Wire.write(0x37); \/\/ Set bit1: 1 enable 0 disable boost keep on\n  } else {\n    Wire.write(0x35); \/\/ 0x37 is default reg value\n  }\n  return Wire.endTransmission() == 0;\n}\n\nvoid setup() {\n  \/\/ Set console baud rate\n  SerialMon.begin(115200);\n\n  \/\/ Keep power when running from battery\n  Wire.begin(I2C_SDA, I2C_SCL);\n  bool isOk = setPowerBoostKeepOn(1);\n  SerialMon.println(String(&quot;IP5306 KeepOn &quot;) + (isOk ? &quot;OK&quot; : &quot;FAIL&quot;));\n\n  \/\/ Set modem reset, enable, power pins\n  pinMode(MODEM_PWKEY, OUTPUT);\n  pinMode(MODEM_RST, OUTPUT);\n  pinMode(MODEM_POWER_ON, OUTPUT);\n  digitalWrite(MODEM_PWKEY, LOW);\n  digitalWrite(MODEM_RST, HIGH);\n  digitalWrite(MODEM_POWER_ON, HIGH);\n\n  \/\/ Set GSM module baud rate and UART pins\n  SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);\n  delay(3000);\n\n  \/\/ Restart SIM800 module, it takes quite some time\n  \/\/ To skip it, call init() instead of restart()\n  SerialMon.println(&quot;Initializing modem...&quot;);\n  modem.restart();\n  \/\/ use modem.init() if you don't need the complete restart\n\n  \/\/ Unlock your SIM card with a PIN if needed\n  if (strlen(simPIN) &amp;&amp; modem.getSimStatus() != 3 ) {\n    modem.simUnlock(simPIN);\n  }\n\n  \/\/ To send an SMS, call modem.sendSMS(SMS_TARGET, smsMessage)\n  String smsMessage = &quot;Hello from ESP32!&quot;;\n  if(modem.sendSMS(SMS_TARGET, smsMessage)){\n    SerialMon.println(smsMessage);\n  }\n  else{\n    SerialMon.println(&quot;SMS failed to send&quot;);\n  }\n}\n\nvoid loop() {\n  delay(1);\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP32\/ESP32_SIM800L_Send_SMS.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How the Code Works<\/h3>\n\n\n\n<p>Insert you SIM card PIN in the following variable. If it\u2019s not defined, you can leave this variable empty.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ SIM card PIN (leave empty, if not defined)\nconst char simPIN&#091;] = \"\";<\/code><\/pre>\n\n\n\n<p>Then, add the phone number you want to send the SMS to. The number should be in international format, otherwise, it won&#8217;t work: (plus sign) and country code, for Portugal +351, followed by phone number.<\/p>\n\n\n\n<p>Example for Portugal <span class=\"rnthl rntliteral\">+351XXXXXXXXX<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define SMS_TARGET \"+351XXXXXXXXXXXX\"<\/code><\/pre>\n\n\n\n<p>Configure the <span class=\"rnthl rntliteral\">TinyGSM<\/span> library to work with the SIM800L modem:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define TINY_GSM_MODEM_SIM800    \/\/ Modem is SIM800\n#define TINY_GSM_RX_BUFFER 1024  \/\/ Set RX buffer to 1Kb<\/code><\/pre>\n\n\n\n<p>Include the following libraries:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;Wire.h>\n#include &lt;TinyGsmClient.h><\/code><\/pre>\n\n\n\n<p>The following lines define the pins used by the SIM800L module:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define MODEM_RST            5\n#define MODEM_PWKEY          4\n#define MODEM_POWER_ON       23\n#define MODEM_TX             27\n#define MODEM_RX             26\n#define I2C_SDA              21\n#define I2C_SCL              22<\/code><\/pre>\n\n\n\n<p>Initialize a serial communication to interact with the Serial Monitor and another to interact with the SIM800L module.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Set serial for debug console (to Serial Monitor, default speed 115200)\n#define SerialMon Serial\n\/\/ Set serial for AT commands (to SIM800 module)\n#define SerialAT Serial1<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, initialize the Serial Monitor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>SerialMon.begin(115200);<\/code><\/pre>\n\n\n\n<p>Setup the SIM800L pins in a proper state to operate:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>pinMode(MODEM_PWKEY, OUTPUT);\npinMode(MODEM_RST, OUTPUT);\npinMode(MODEM_POWER_ON, OUTPUT);\ndigitalWrite(MODEM_PWKEY, LOW);\ndigitalWrite(MODEM_RST, HIGH);\ndigitalWrite(MODEM_POWER_ON, HIGH);<\/code><\/pre>\n\n\n\n<p>Initialize a serial communication with the SIM800L module:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);<\/code><\/pre>\n\n\n\n<p>Initialize the SIM800L module and unlock the SIM card PIN if needed.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>SerialMon.println(\"Initializing modem...\");\nmodem.restart();\n\/\/ use modem.init() if you don't need the complete restart\n\n\/\/ Unlock your SIM card with a PIN if needed\nif (strlen(simPIN) &amp;&amp; modem.getSimStatus() != 3 ) {\n  modem.simUnlock(simPIN);\n}<\/code><\/pre>\n\n\n\n<p>To send an SMS, you just need to use the <span class=\"rnthl rntliteral\">sendSMS()<\/span> method on the <span class=\"rnthl rntliteral\">modem<\/span> object and pass as arguments the recipient&#8217;s phone number and the message.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>modem.sendSMS(SMS_TARGET, smsMessage);<\/code><\/pre>\n\n\n\n<p>In this case, the message is &#8220;<strong>Hello from ESP32!<\/strong>&#8220;, but it can be replaced with other info like sensor data.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>String smsMessage = \"Hello from ESP32!\";\nif(modem.sendSMS(SMS_TARGET, smsMessage)){\n  SerialMon.println(smsMessage);\n}\nelse{\n  SerialMon.println(\"SMS failed to send\");\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Demonstration<\/h3>\n\n\n\n<p>With the nano SIM card inserted in the module, upload the code to your <a href=\"https:\/\/makeradvisor.com\/tools\/ttgo-t-call-esp32-sim800\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"T-Call ESP32 SIM800L board (opens in a new tab)\">T-Call ESP32 SIM800L board<\/a>. <\/p>\n\n\n\n<p>Go to&nbsp;<strong>Tools&nbsp;<\/strong>&gt;&nbsp;<strong>Board&nbsp;<\/strong>and select&nbsp;<strong>ESP32 Dev Module<\/strong>. Go to&nbsp;<strong>Tools<\/strong>&nbsp;&gt;&nbsp;<strong>Port<\/strong>&nbsp;and select the COM port your board is connected to. Finally, press the upload button to upload the code to your board.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"34\" height=\"29\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/12\/arduino-ide-upload-button.png?resize=34%2C29&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Upload Code to Arduino IDE\" class=\"wp-image-65439\"\/><\/figure><\/div>\n\n\n\n<p class=\"rntbox rntclblue\"><strong>Note:&nbsp;<\/strong>at the moment, there isn\u2019t a board for the T-Call ESP32 SIM800L, but we\u2019ve selected the <strong>ESP32 Dev Module<\/strong> and it\u2019s been working fine.<\/p>\n\n\n\n<p>After uploading the code, open the Serial Monitor at a baud rate of 115200 to see what&#8217;s going on.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"873\" height=\"493\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Arduino-IDE-Serial-Monitor-Send-SMS-ESP32-SIM800L.png?resize=873%2C493&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Initializing the T-Call ESP32 SIM800L Board Serial Monitor Arduino IDE\" class=\"wp-image-89139\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Arduino-IDE-Serial-Monitor-Send-SMS-ESP32-SIM800L.png?w=873&amp;quality=100&amp;strip=all&amp;ssl=1 873w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Arduino-IDE-Serial-Monitor-Send-SMS-ESP32-SIM800L.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Arduino-IDE-Serial-Monitor-Send-SMS-ESP32-SIM800L.png?resize=768%2C434&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 873px) 100vw, 873px\" \/><\/figure><\/div>\n\n\n\n<p>After a few seconds, you should receive an SMS on the recipient&#8217;s phone number.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"340\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Receive-Hello-World-from-ESP32-SMS_f.jpg?resize=750%2C340&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Send SMS with T-Call ESP32 SIM800L Board\" class=\"wp-image-89252\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Receive-Hello-World-from-ESP32-SMS_f.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Receive-Hello-World-from-ESP32-SMS_f.jpg?resize=300%2C136&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting<\/h2>\n\n\n\n<p>If at this point, you don\u2019t receive an SMS, it can be caused by one of the following reasons:<br><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>This module only works if 2G is supported in your country;<\/li><li>The phone number might have a typo or it\u2019s not properly formatted with the plus (+) sign and country code;<\/li><li>The antenna might not be working properly. In our case, we\u2019ve replaced the antenna with <a rel=\"noreferrer noopener nofollow\" aria-label=\"this one (opens in a new tab)\" href=\"https:\/\/rover.ebay.com\/rover\/1\/711-53200-19255-0\/1?ff3=2&amp;toolid=10044&amp;campid=5338179998&amp;customid=MakerAdvisorT&amp;lgeo=1&amp;vectorid=229466&amp;item=311649924872\" target=\"_blank\">this one<\/a>;<\/li><li>You might need to go outside to get better signal coverage;<\/li><li>Or you might not be supplying enough current to the module. If you\u2019re connecting the module to your computer using a USB hub, it might not provide enough current to operate.<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">ESP32 SMS Notification System<\/h2>\n\n\n\n<p>In this section, we&#8217;ll show you how to build an SMS notification system that sends a text message when the sensor readings cross a predetermined threshold temperature value.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Schematic Diagram<\/h3>\n\n\n\n<p>Before proceeding, connect the DS18B20 temperature sensor to the T-Call ESP32 SIM800L board as shown in the following schematic diagram. We&#8217;re connecting the DS18B20 data pin to <span class=\"rnthl rntcblue\">GPIO 13<\/span>.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"761\" height=\"609\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/ESP32-SIM800-with-DS18B20-schematic.png?resize=761%2C609&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"T-Call ESP32 SIM800L Wiring to DS18B20 Schematic Diagram\" class=\"wp-image-89144\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/ESP32-SIM800-with-DS18B20-schematic.png?w=761&amp;quality=100&amp;strip=all&amp;ssl=1 761w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/ESP32-SIM800-with-DS18B20-schematic.png?resize=300%2C240&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 761px) 100vw, 761px\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Code<\/h3>\n\n\n\n<p>Copy the following code to your Arduino IDE. Insert the recipient&#8217;s phone number and set the threshold value. Then, you can upload the code to the T-Call ESP32 SIM800L board.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n  Rui Santos\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-sim800l-send-text-messages-sms\/\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files.\n  \n  The above copyright notice and this permission notice shall be included in all\n  copies or substantial portions of the Software.\n*\/\n\n\/\/ SIM card PIN (leave empty, if not defined)\nconst char simPIN[]   = &quot;&quot;;\n\n\/\/ Your phone number to send SMS: + (plus sign) and country code, for Portugal +351, followed by phone number\n\/\/ SMS_TARGET Example for Portugal +351XXXXXXXXX\n#define SMS_TARGET  &quot;+351XXXXXXXXX&quot;\n\n\/\/ Define your temperature Threshold (in this case it's 28.0 degrees Celsius)\nfloat temperatureThreshold = 28.0;\n\/\/ Flag variable to keep track if alert SMS was sent or not\nbool smsSent = false;\n\n\/\/ Configure TinyGSM library\n#define TINY_GSM_MODEM_SIM800      \/\/ Modem is SIM800\n#define TINY_GSM_RX_BUFFER   1024  \/\/ Set RX buffer to 1Kb\n\n#include &lt;Wire.h&gt;\n#include &lt;TinyGsmClient.h&gt;\n#include &lt;OneWire.h&gt;\n#include &lt;DallasTemperature.h&gt;\n\n\/\/ GPIO where the DS18B20 is connected to\nconst int oneWireBus = 13;     \n\n\/\/ Setup a oneWire instance to communicate with any OneWire devices\nOneWire oneWire(oneWireBus);\n\n\/\/ Pass our oneWire reference to Dallas Temperature sensor \nDallasTemperature sensors(&amp;oneWire);\n\n\/\/ TTGO T-Call pins\n#define MODEM_RST            5\n#define MODEM_PWKEY          4\n#define MODEM_POWER_ON       23\n#define MODEM_TX             27\n#define MODEM_RX             26\n#define I2C_SDA              21\n#define I2C_SCL              22\n\n\/\/ Set serial for debug console (to Serial Monitor, default speed 115200)\n#define SerialMon Serial\n\/\/ Set serial for AT commands (to SIM800 module)\n#define SerialAT  Serial1\n\n\/\/ Define the serial console for debug prints, if needed\n\/\/#define DUMP_AT_COMMANDS\n\n#ifdef DUMP_AT_COMMANDS\n  #include &lt;StreamDebugger.h&gt;\n  StreamDebugger debugger(SerialAT, SerialMon);\n  TinyGsm modem(debugger);\n#else\n  TinyGsm modem(SerialAT);\n#endif\n\n#define IP5306_ADDR          0x75\n#define IP5306_REG_SYS_CTL0  0x00\n\nbool setPowerBoostKeepOn(int en){\n  Wire.beginTransmission(IP5306_ADDR);\n  Wire.write(IP5306_REG_SYS_CTL0);\n  if (en) {\n    Wire.write(0x37); \/\/ Set bit1: 1 enable 0 disable boost keep on\n  } else {\n    Wire.write(0x35); \/\/ 0x37 is default reg value\n  }\n  return Wire.endTransmission() == 0;\n}\n\nvoid setup() {\n  \/\/ Set console baud rate\n  SerialMon.begin(115200);\n\n  \/\/ Keep power when running from battery\n  Wire.begin(I2C_SDA, I2C_SCL);\n  bool isOk = setPowerBoostKeepOn(1);\n  SerialMon.println(String(&quot;IP5306 KeepOn &quot;) + (isOk ? &quot;OK&quot; : &quot;FAIL&quot;));\n\n  \/\/ Set modem reset, enable, power pins\n  pinMode(MODEM_PWKEY, OUTPUT);\n  pinMode(MODEM_RST, OUTPUT);\n  pinMode(MODEM_POWER_ON, OUTPUT);\n  digitalWrite(MODEM_PWKEY, LOW);\n  digitalWrite(MODEM_RST, HIGH);\n  digitalWrite(MODEM_POWER_ON, HIGH);\n\n  \/\/ Set GSM module baud rate and UART pins\n  SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);\n  delay(3000);\n\n  \/\/ Restart SIM800 module, it takes quite some time\n  \/\/ To skip it, call init() instead of restart()\n  SerialMon.println(&quot;Initializing modem...&quot;);\n  modem.restart();\n  \/\/ use modem.init() if you don't need the complete restart\n\n  \/\/ Unlock your SIM card with a PIN if needed\n  if (strlen(simPIN) &amp;&amp; modem.getSimStatus() != 3 ) {\n    modem.simUnlock(simPIN);\n  }\n  \n  \/\/ Start the DS18B20 sensor\n  sensors.begin();\n}\n\nvoid loop() {\n  sensors.requestTemperatures();\n  \/\/ Temperature in Celsius degrees \n  float temperature = sensors.getTempCByIndex(0);\n  SerialMon.print(temperature);\n  SerialMon.println(&quot;*C&quot;);\n  \n  \/\/ Temperature in Fahrenheit degrees\n  \/*float temperature = sensors.getTempFByIndex(0);\n  SerialMon.print(temperature);\n  SerialMon.println(&quot;*F&quot;);*\/\n\n  \/\/ Check if temperature is above threshold and if it needs to send the SMS alert\n  if((temperature &gt; temperatureThreshold) &amp;&amp; !smsSent){\n    String smsMessage = String(&quot;Temperature above threshold: &quot;) + \n           String(temperature) + String(&quot;C&quot;);\n    if(modem.sendSMS(SMS_TARGET, smsMessage)){\n      SerialMon.println(smsMessage);\n      smsSent = true;\n    }\n    else{\n      SerialMon.println(&quot;SMS failed to send&quot;);\n    }    \n  }\n  \/\/ Check if temperature is below threshold and if it needs to send the SMS alert\n  else if((temperature &lt; temperatureThreshold) &amp;&amp; smsSent){\n    String smsMessage = String(&quot;Temperature below threshold: &quot;) + \n           String(temperature) + String(&quot;C&quot;);\n    if(modem.sendSMS(SMS_TARGET, smsMessage)){\n      SerialMon.println(smsMessage);\n      smsSent = false;\n    }\n    else{\n      SerialMon.println(&quot;SMS failed to send&quot;);\n    }\n  }\n  delay(5000);\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP32\/ESP32_SIM800L_Send_SMS_Temperature_Alert.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How the Code Works<\/h3>\n\n\n\n<p>In the previous example, we&#8217;ve already explained how to initialize the SIM800L and all the required configurations. So, let\u2019s skip to the relevant parts for this project.<\/p>\n\n\n\n<p>First, type your SIM card PIN. If it\u2019s not defined, you can leave this variable empty.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char simPIN&#091;] = \"\";<\/code><\/pre>\n\n\n\n<p>Then, add the phone number you want to send the SMS to. The number should be in international format, otherwise it won&#8217;t work. <\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define SMS_TARGET \"+351XXXXXXXXXXX\"<\/code><\/pre>\n\n\n\n<p>Define your temperature threshold. We\u2019ve set it to 28 degrees Celsius.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>float temperatureThreshold = 28.0;<\/code><\/pre>\n\n\n\n<p>Create a variable to keep track if an SMS was sent or not.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>bool smsSent = false;<\/code><\/pre>\n\n\n\n<p>The temperature sensor is connected to <span class=\"rnthl rntcblue\">GPIO 13<\/span>, but you can use any other GPIO. <\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const int oneWireBus = 13;<\/code><\/pre>\n\n\n\n<p><strong>Related content:<\/strong> <a rel=\"noreferrer noopener\" aria-label=\"ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) (opens in a new tab)\" href=\"https:\/\/randomnerdtutorials.com\/esp32-ds18b20-temperature-arduino-ide\/\" target=\"_blank\">ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server)<\/a><\/p>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">loop()<\/span>, get the temperature readings.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>sensors.requestTemperatures();\n\/\/ Temperature in Celsius degrees \nfloat temperature = sensors.getTempCByIndex(0);\nSerialMon.print(temperature);\nSerialMon.println(\"*C\");<\/code><\/pre>\n\n\n\n<p>By default, the temperature is in Celsius degrees, but you can uncomment the following lines to use the temperature in Fahrenheit degrees. Then, you should also adjust the threshold value to match your temperature units.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Temperature in Fahrenheit degrees\n\/*float temperature = sensors.getTempFByIndex(0);\nSerialMon.print(temperature);\nSerialMon.println(\"*F\");*\/<\/code><\/pre>\n\n\n\n<p>After that, there&#8217;s a condition that checks if the current temperature value is above the defined threshold and if an alert SMS hasn\u2019t been sent.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if((temperature > temperatureThreshold) &amp;&amp; !smsSent){<\/code><\/pre>\n\n\n\n<p>If that condition is true, send an SMS saying \u201cTemperature above threshold: \u201d and the current temperature value.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>String smsMessage = String(\"Temperature above threshold: \") + \n           String(temperature) + String(\"C\");\nif(modem.sendSMS(SMS_TARGET, smsMessage)){\n  SerialMon.println(smsMessage);\n  smsSent = true;\n}\nelse{\n  SerialMon.println(\"SMS failed to send\");\n}<\/code><\/pre>\n\n\n\n<p>As you can see, to send a text message, you use the <span class=\"rnthl rntliteral\">sendSMS()<\/span> method on the <span class=\"rnthl rntliteral\">modem<\/span> object. You just need to pass as arguments, the phone number you want to send the SMS to, and the message content.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if(modem.sendSMS(SMS_TARGET, smsMessage)){<\/code><\/pre>\n\n\n\n<p>After sending the message, set the <span class=\"rnthl rntliteral\">smsSent<\/span> variable to <span class=\"rnthl rntliteral\">true<\/span> to avoid multiple SMS alerts for the same threshold reached.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>smsSent = true;<\/code><\/pre>\n\n\n\n<p>When the temperature goes below the threshold, we also receive an SMS.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>else if((temperature &lt; temperatureThreshold) &amp;&amp; smsSent){\n  String smsMessage = String(\"Temperature below threshold: \") + \n           String(temperature) + String(\"C\");\n  if(modem.sendSMS(SMS_TARGET, smsMessage)){\n    SerialMon.println(smsMessage);\n    smsSent = false;\n  }\n  else{\n    SerialMon.println(\"SMS failed to send\");\n  }\n}<\/code><\/pre>\n\n\n\n<p>This time, set the <span class=\"rnthl rntliteral\">smsSent<\/span> variable to <span class=\"rnthl rntliteral\">false<\/span>, so that we stop receiving messages below the threshold. <\/p>\n\n\n\n<p>These conditions are checked every 5 seconds, but you can change the delay time.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Upload the Code<\/h3>\n\n\n\n<p>After inserting the recipient&#8217;s phone number and SIM card pin code, upload the sketch to your ESP32. <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Go to <strong>Tools <\/strong>&gt; <strong>Board <\/strong>and select the<strong> ESP32 Dev module<\/strong><\/li><li>After that, go to <strong>Tools <\/strong>&gt; <strong>Port <\/strong>and select the COM port the ESP32 is connected to<\/li><li>Then, press the <strong>Upload <\/strong>button<\/li><\/ul>\n\n\n\n<p>After a few seconds, the code should be successfully uploaded.<\/p>\n\n\n\n<p>You can also open the Serial Monitor at a baud rate of 115200 to see the current sensor readings.<\/p>\n\n\n\n<p>If I put my finger on top of the sensor, the temperature will start increasing.When it goes above 28\u00baC, it sends an SMS.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"421\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Receive-Temperature-SMS-from-TCall-ESP32-SIM800L-board.jpg?resize=750%2C421&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Receive SMS with Temperature Readings from T-Call ESP32 SIM800L Board\" class=\"wp-image-89217\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Receive-Temperature-SMS-from-TCall-ESP32-SIM800L-board.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Receive-Temperature-SMS-from-TCall-ESP32-SIM800L-board.jpg?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>When the temperature goes below the threshold, I\u2019ll receive another SMS.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"421\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Receive-Temperature-below-threshold-SMS-from-TCall-ESP32-SIM800L-board.jpg?resize=750%2C421&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Receive Temperature Below Threshold SMS from T-Call ESP32 SIM800L Board\" class=\"wp-image-89218\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Receive-Temperature-below-threshold-SMS-from-TCall-ESP32-SIM800L-board.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Receive-Temperature-below-threshold-SMS-from-TCall-ESP32-SIM800L-board.jpg?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>With this project you&#8217;ve learned how to send SMS with the <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/ttgo-t-call-esp32-sim800\/\" target=\"_blank\">T-Call ESP32 SIM800L module<\/a>. Now, you can use this project in a real application and leave it sending SMS notifications when the threshold value is reached or send SMS with sensor readings every hour, for example.<\/p>\n\n\n\n<p>To make this project battery powered, I recommend using <a href=\"https:\/\/randomnerdtutorials.com\/esp32-deep-sleep-arduino-ide-wake-up-sources\/\">deep sleep mode and wake up the ESP32 every hour<\/a> to check the current temperature, because if you use the code in this project it will drain your battery quickly.<\/p>\n\n\n\n<p>Other articles\/projects with the T-Call ESP32 SIM800L board:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-sim800l-publish-data-to-cloud\/\">ESP32 Publish Data to Cloud without Wi-Fi (TTGO T-Call ESP32 SIM800L)<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/ttgo-t-call-esp32-with-sim800l-gsm-gprs\/\" target=\"_blank\">TTGO T-Call ESP32 with SIM800L GSM\/GPRS (in-depth review)<\/a> <\/li><\/ul>\n\n\n\n<p>Learn more about the ESP32 with our resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/learn-esp32-with-arduino-ide\/\">Learn ESP32 with Arduino IDE (Course)<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/micropython-programming-with-esp32-and-esp8266\/\">MicroPython Programming with ESP32 and ESP8266 (eBook)<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp32\/\">More ESP32 Projects and Tutorials<\/a><\/li><\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this project we\u2019re going to create an SMS notification system with the T-Call ESP32 SIM800L module that sends an SMS when sensor readings are above or below a certain &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP32 SIM800L: Send Text Messages (SMS Alert) with Sensor Readings\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp32-sim800l-send-text-messages-sms\/#more-89131\" aria-label=\"Read more about ESP32 SIM800L: Send Text Messages (SMS Alert) with Sensor Readings\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":89261,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[276,281,277,299,264,1],"tags":[],"class_list":["post-89131","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32","category-esp32-project","category-esp32-arduino-ide","category-0-esp32","category-project","category-uncategorized"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/ESP32-SIM800L-Send-Text-Message-SMS-Temperature.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/89131","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=89131"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/89131\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/89261"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=89131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=89131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=89131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}