{"id":61678,"date":"2018-05-10T11:15:58","date_gmt":"2018-05-10T11:15:58","guid":{"rendered":"http:\/\/randomnerdtutorials.com\/?p=61678"},"modified":"2025-03-24T11:52:06","modified_gmt":"2025-03-24T11:52:06","slug":"request-sensor-data-sms-arduino-sim900-gsm-shield","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/request-sensor-data-sms-arduino-sim900-gsm-shield\/","title":{"rendered":"Request Sensor Data via SMS using Arduino and SIM900 GSM Shield"},"content":{"rendered":"<p>In this project we&#8217;re going to show you how to request sensor data via SMS with the Arduino. As an example we&#8217;re going to request the temperature and humidity from a DHT11 sensor. To send and receive SMS with the Arduino we&#8217;re going to use the SIM900 GSM shield. <!--more--><\/p>\n<p><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-61694\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/Request-Sensor-Data-via-SMS-thumbnail-f.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"1200\" height=\"675\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/Request-Sensor-Data-via-SMS-thumbnail-f.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/Request-Sensor-Data-via-SMS-thumbnail-f.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/Request-Sensor-Data-via-SMS-thumbnail-f.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/Request-Sensor-Data-via-SMS-thumbnail-f.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<p>When you send an SMS to the Arduino with the message &#8220;STATE&#8221;, it replies with the latest temperature and humidity readings.<\/p>\n<p>Before proceeding with this tutorial we recommend the following resources:<\/p>\n<ul>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/sim900-gsm-gprs-shield-arduino\/\" target=\"_blank\" rel=\"noopener noreferrer\">Guide to SIM900 GSM GPRS Shield with Arduino<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/complete-guide-for-dht11dht22-humidity-and-temperature-sensor-with-arduino\/\" target=\"_blank\" rel=\"noopener noreferrer\">Guide for DHT11\/DHT22 Humidity and Temperature Sensor With Arduino<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/arduino-mini-course\/\" target=\"_blank\" rel=\"noopener noreferrer\">Enroll in our free Arduino Mini Course<\/a><\/li>\n<li><strong>Recommended course:\u00a0<\/strong> <a href=\"https:\/\/randomnerdtutorials.com\/arduino-step-by-step-projects\/\">25 Arduino Step-by-step Projects<\/a><\/li>\n<\/ul>\n<h2>First, watch the video demonstration<\/h2>\n<p style=\"text-align:center\"><iframe width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/2Cz1GOvEbrw?rel=0\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<h2>SIM900 GSM Shield<\/h2>\n<p>There are several modules you can use to send and receive SMS with the Arduino. We did this project using the SIM900 GSM shield and that&#8217;s the shield we recommend you to get.<\/p>\n<p>The SIM900 GSM shield is shown in figure below:<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter size-full wp-image-43806\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/SIM900-GSM-shield_f.jpg?resize=700%2C421&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"700\" height=\"421\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/SIM900-GSM-shield_f.jpg?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/SIM900-GSM-shield_f.jpg?resize=300%2C180&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p>For an introduction to the GSM shield, and how to set it up, read the\u00a0<a href=\"https:\/\/randomnerdtutorials.com\/sim900-gsm-gprs-shield-arduino\/\" target=\"_blank\" rel=\"noopener noreferrer\">Guide to SIM900 GSM GPRS Shield with Arduino<\/a>.<\/p>\n<h2>Parts Required<\/h2>\n<p>Here&#8217;s a list of all the components needed for this project:<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter size-full wp-image-61683\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/GSM-parts-required.jpg?resize=700%2C508&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"700\" height=\"508\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/GSM-parts-required.jpg?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/GSM-parts-required.jpg?resize=300%2C218&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<ul>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/compatible-arduino-uno-r3-board\/\" target=\"_blank\" rel=\"noopener noreferrer\">Arduino UNO<\/a>\u00a0\u2013 read\u00a0<a href=\"https:\/\/makeradvisor.com\/best-arduino-starter-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">Best Arduino Starter Kits<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/sim900-gsm-gprs-shield\/\" target=\"_blank\" rel=\"noopener noreferrer\">SIM900 GSM Shield<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/5v-2a-power-adaptor-dc-jack\/\" target=\"_blank\" rel=\"noopener noreferrer\">5V 2A Power Adaptor<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/ftdi-programmer-board\/\" target=\"_blank\" rel=\"noopener noreferrer\">FTDI programmer<\/a> (optional)<\/li>\n<li>SIM Card<\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/dht11-temperature-humidity-sensor\/\" target=\"_blank\" rel=\"noopener noreferrer\">DHT11<\/a> or\u00a0<a href=\"https:\/\/makeradvisor.com\/tools\/dht22-temperature-humidity-sensor\/\" target=\"_blank\" rel=\"noopener noreferrer\">DHT22<\/a> Temperature and Humidity Sensor<\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">10 kOhm resistor<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noopener noreferrer\">Breadboard<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noopener noreferrer\">Jumper Wires<\/a><\/li>\n<\/ul>\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<h2>Preliminary steps<\/h2>\n<p>Before getting started with your SIM900 GSM module, you need to consider some aspects about the SIM card and the shield power supply.<\/p>\n<h3>Prepaid SIM card<\/h3>\n<p>We recommend that you use a prepaid plan or a plan with unlimited SMS for testing purposes. Otherwise, if something goes wrong, you may need to pay a huge bill for hundreds of SMS text messages sent by mistake. In this tutorial we\u2019re using a prepaid plan with unlimited SMS.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-42388\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/SIM-card.jpg?resize=700%2C394&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"700\" height=\"394\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/SIM-card.jpg?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/SIM-card.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p>The shield uses the original SIM card size, not micro or nano. If you have micro or nano you may consider getting a<a href=\"http:\/\/ebay.to\/2gbdOcC\" target=\"_blank\" rel=\"noopener noreferrer\"> SIM card size adapter<\/a>.<\/p>\n<h3>Turn off the PIN lock<\/h3>\n<p>To use the SIM card with the shield, you need to turn off the pin lock. The easiest way to do this, is to insert the SIM card in your smartphone and turn off the pin lock in the phone security settings.<\/p>\n<p>In my case, I need to go through:\u00a0<strong>Settings<\/strong>\u00a0&gt;\u00a0<strong>Advanced\u00a0Settings\u00a0<\/strong>&gt;\u00a0<strong>Security\u00a0<\/strong>&gt; <strong>SIM lock<\/strong>\u00a0and turn off the lock sim card with pin.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61684\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/turnoffpinlock.png?resize=700%2C379&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"700\" height=\"379\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/turnoffpinlock.png?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/turnoffpinlock.png?resize=300%2C162&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<h3>Getting the right power supply<\/h3>\n<p>The shield has a DC jack for power as shown in figure below.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-42432\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/DC-jack.png?resize=699%2C398&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"699\" height=\"398\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/DC-jack.png?w=699&amp;quality=100&amp;strip=all&amp;ssl=1 699w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/DC-jack.png?resize=300%2C171&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 699px) 100vw, 699px\" \/><\/p>\n<p>Next to the power jack there is a toggle switch to select the power source. Next to the toggle switch on the board, there is an arrow indicating the toggle position to use an external power supply \u2013 move the toggle switch to use the external power supply as shown above.<\/p>\n<p>To power up the shield, it is advisable to use a 5V power supply that can provide 2A as the one shown below.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-42383\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/power-adapter.jpg?resize=700%2C640&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"700\" height=\"640\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/power-adapter.jpg?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/power-adapter.jpg?resize=300%2C274&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p>You can find the right power adapter for this shield <a href=\"http:\/\/ebay.to\/2wLRhJS\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>. Make sure you select the model with 5V and 2A.<\/p>\n<h2>Setting up the SIM900 GSM Shield<\/h2>\n<p>The following steps show you how to set up the SIM900 GSM shield.<\/p>\n<p><strong>1)<\/strong>\u00a0Insert the SIM card into the SIM card holder. You need a SIM card with the standard size. The shield is not compatible with micro or nano SIM cards. If you need, you may get a sim card size adapter. Also, it is advisable to use a SIM card with a prepaid plan or unlimited SMS.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-42389\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/insert-SIM.jpg?resize=700%2C245&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"700\" height=\"245\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/insert-SIM.jpg?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/insert-SIM.jpg?resize=300%2C105&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p><strong>2) <\/strong>Confirm\u00a0the antenna is well connected.<\/p>\n<p><strong>3)<\/strong> On the serial port select, make sure the jumper cap is connected as shown in figure below to use software serial.<\/p>\n<p><em>\u00a0<img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-42415\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/software-serial.jpg?resize=700%2C296&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"700\" height=\"296\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/software-serial.jpg?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/software-serial.jpg?resize=300%2C127&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/em><\/p>\n<p><strong>4)<\/strong> Power the shield using an external 5V power supply. Double-check that you have the external power source selected as we&#8217;ve mentioned earlier.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-42416\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/power-select.png?resize=338%2C227&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"338\" height=\"227\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/power-select.png?w=338&amp;quality=100&amp;strip=all&amp;ssl=1 338w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/power-select.png?resize=300%2C201&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 338px) 100vw, 338px\" \/><\/p>\n<p><strong>5)\u00a0<\/strong>To power up\/down the shield press the power key for about 2 seconds.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-42417\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/power-key.png?resize=309%2C199&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"309\" height=\"199\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/power-key.png?w=309&amp;quality=100&amp;strip=all&amp;ssl=1 309w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/power-key.png?resize=300%2C193&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 309px) 100vw, 309px\" \/><\/p>\n<p><strong>6)<\/strong> Then, the Status LED will light up and the NetLight LED will blink every 800 ms until it finds the network. When it finds the network the NetLight LED will start blinking every three seconds.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61688\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/GSM-shield-labels-LEDs.png?resize=402%2C193&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"402\" height=\"193\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/GSM-shield-labels-LEDs.png?w=402&amp;quality=100&amp;strip=all&amp;ssl=1 402w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/GSM-shield-labels-LEDs.png?resize=300%2C144&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 402px) 100vw, 402px\" \/><\/p>\n<p><strong>7)<\/strong> You can test if the shield is working properly by sending AT commands from the Arduino IDE using an FTDI programmer \u2013 as we\u2019ll show below.<\/p>\n<h2>Testing the Shield with FTDI programmer<\/h2>\n<p>You don&#8217;t need to do this step to get the shield working properly. This is an extra step to ensure that you can communicate with your GSM shield and send AT commands from the Arduino IDE serial monitor. For that, you need an FTDI programmer as the one shown in figure below.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-42385\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/FTDI.jpg?resize=665%2C282&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"665\" height=\"282\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/FTDI.jpg?w=665&amp;quality=100&amp;strip=all&amp;ssl=1 665w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/FTDI.jpg?resize=300%2C127&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 665px) 100vw, 665px\" \/><\/p>\n<p><strong>1)<\/strong> Connect the FTDI programmer to the GSM shield as shown in figure below.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/GSM-FTDI-circuit-1.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-42442 size-full\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/GSM-FTDI-circuit-1.png?resize=1066%2C754&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"1066\" height=\"754\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/GSM-FTDI-circuit-1.png?w=1066&amp;quality=100&amp;strip=all&amp;ssl=1 1066w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/GSM-FTDI-circuit-1.png?resize=300%2C212&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/GSM-FTDI-circuit-1.png?resize=768%2C543&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/GSM-FTDI-circuit-1.png?resize=1024%2C724&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1066px) 100vw, 1066px\" \/><\/a><\/p>\n<p><strong>2)<\/strong> Open the Arduino IDE and select the right COM port.<\/p>\n<p><strong>3)<\/strong> Open the Serial monitor.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61341\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/serial-monitor.png?resize=745%2C109&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"745\" height=\"109\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/serial-monitor.png?w=745&amp;quality=100&amp;strip=all&amp;ssl=1 745w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/serial-monitor.png?resize=300%2C44&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 745px) 100vw, 745px\" \/><\/p>\n<p><strong>4)<\/strong> Select <strong>19200<\/strong> baud rate \u2013 the shield default setting is 19200 \u2013 and <strong>Carriage return<\/strong>. Write <strong>AT<\/strong> at the box highlighted in red and then press enter. See figure below.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61689\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/GSM-arduino-ide-serial-monitor-set-baud-rate.png?resize=559%2C315&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"559\" height=\"315\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/GSM-arduino-ide-serial-monitor-set-baud-rate.png?w=559&amp;quality=100&amp;strip=all&amp;ssl=1 559w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/GSM-arduino-ide-serial-monitor-set-baud-rate.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 559px) 100vw, 559px\" \/><\/p>\n<p><strong>5)<\/strong> The shield will respond with <strong>OK<\/strong>, if everything is working properly.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61690\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/GSM-arduino-ide-serial-monitor.png?resize=559%2C306&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"559\" height=\"306\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/GSM-arduino-ide-serial-monitor.png?w=559&amp;quality=100&amp;strip=all&amp;ssl=1 559w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/GSM-arduino-ide-serial-monitor.png?resize=300%2C164&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 559px) 100vw, 559px\" \/><\/p>\n<p>Now that you know the shield is working properly, you are ready to start building the project.<\/p>\n<h2>Schematics<\/h2>\n<p>The figure below shows the circuit schematics for this project.<\/p>\n<p>You have to connect the SIM900 GSM shield and the DHT11 temperature and humidity sensor to the Arduino as shown in the figure below.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/Request-data-GSM-schematics.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-61685 size-full\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/Request-data-GSM-schematics.png?resize=1200%2C958&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"1200\" height=\"958\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/Request-data-GSM-schematics.png?w=1238&amp;quality=100&amp;strip=all&amp;ssl=1 1238w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/Request-data-GSM-schematics.png?resize=300%2C239&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/Request-data-GSM-schematics.png?resize=768%2C613&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/Request-data-GSM-schematics.png?resize=1024%2C817&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/a><\/p>\n<h2>Installing the DHT library<\/h2>\n<p>To read from the DHT sensor, you must have the DHT library installed. If you don&#8217;t have the DHT library installed, follow the instructions below:<\/p>\n<ol>\n<li><a href=\"https:\/\/github.com\/adafruit\/DHT-sensor-library\/archive\/master.zip\" target=\"_blank\" rel=\"noopener noreferrer\">Click here to download the DHT-sensor-library<\/a>. You should have a .zip folder in your Downloads folder<\/li>\n<li>Unzip the .zip folder and you should get <strong>DHT-sensor-library-master folder<\/strong><\/li>\n<li>Rename your folder from <del><strong>DHT-sensor-library-master<\/strong><\/del> to <strong>DHT <\/strong><\/li>\n<li>Move the <strong>DHT<\/strong> folder to your Arduino IDE installation libraries folder<\/li>\n<li>Finally, re-open your Arduino IDE<\/li>\n<\/ol>\n<h2>Installing the Adafruit_Sensor library<\/h2>\n<p>To use the DHT temperature and humidity sensor, you also need to install the\u00a0<a href=\"https:\/\/github.com\/adafruit\/Adafruit_Sensor\" target=\"_blank\" rel=\"noopener noreferrer\">Adafruit_Sensor library<\/a>. Follow the next steps to install the library in your Arduino IDE:<\/p>\n<ol>\n<li><a href=\"https:\/\/github.com\/adafruit\/Adafruit_Sensor\/archive\/master.zip\" target=\"_blank\" rel=\"noopener noreferrer\">Click here to download<\/a>\u00a0the Adafruit_Sensor library. You should have a .zip folder in your Downloads folder<\/li>\n<li>Unzip the .zip folder and you should get Adafruit_Sensor-master folder<\/li>\n<li>Rename your folder from\u00a0<del>Adafruit_Sensor-master<\/del>\u00a0to Adafruit_Sensor<\/li>\n<li>Move the\u00a0<em>Adafruit_Sensor<\/em>\u00a0folder to your Arduino IDE installation libraries folder<\/li>\n<li>Finally, re-open your Arduino IDE<\/li>\n<\/ol>\n<h2>Code<\/h2>\n<p>The following code reads the temperature and humidity from the DHT sensor and sends them via SMS when you send an SMS to the Arduino with the message &#8220;STATE&#8221;.<\/p>\n<p><strong>You need to modify the code provided with the phone number your Arduino should reply the readings to.<\/strong> The code is well commented for you to understand the purpose of each line of code. Don&#8217;t upload the code now. Scroll down and read the explanation below the code.<\/p>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n * Rui Santos \n * Complete Project Details http:\/\/randomnerdtutorials.com\n *\/\n\n\n\/\/ Include DHT library and Adafruit Sensor Library\n#include &quot;DHT.h&quot;\n#include &lt;Adafruit_Sensor.h&gt;\n\/\/Include Software Serial library to communicate with GSM\n#include &lt;SoftwareSerial.h&gt;\n\n\/\/ Pin DHT is connected to\n#define DHTPIN 2\n  \n\/\/ Uncomment whatever type of sensor you're using\n#define DHTTYPE DHT11   \/\/ DHT 11 \n\/\/#define DHTTYPE DHT22   \/\/ DHT 22  (AM2302)\n\/\/#define DHTTYPE DHT21   \/\/ DHT 21 (AM2301)\n\n\/\/ Initialize DHT sensor for normal 16mhz Arduino\nDHT dht(DHTPIN, DHTTYPE);\n\n\/\/ Create global varibales to store temperature and humidity\nfloat t; \/\/ temperature in celcius\nfloat f; \/\/ temperature in fahrenheit\nfloat h; \/\/ humidity\n\n\/\/ Configure software serial port\nSoftwareSerial SIM900(7, 8);\n\n\/\/ Create variable to store incoming SMS characters\nchar incomingChar;\n\nvoid setup() {\n  dht.begin();\n  \n  Serial.begin(19200); \n  SIM900.begin(19200);\n\n  \/\/ Give time to your GSM shield log on to network\n  delay(20000);\n  Serial.print(&quot;SIM900 ready...&quot;);\n\n  \/\/ AT command to set SIM900 to SMS mode\n  SIM900.print(&quot;AT+CMGF=1\\r&quot;); \n  delay(100);\n  \/\/ Set module to send SMS data to serial out upon receipt \n  SIM900.print(&quot;AT+CNMI=2,2,0,0,0\\r&quot;);\n  delay(100);\n}\n\nvoid loop(){\n  if (SMSRequest()){\n    if(readData()){\n      delay(10);\n      \/\/ REPLACE THE X's WITH THE RECIPIENT'S MOBILE NUMBER\n      \/\/ USE INTERNATIONAL FORMAT CODE FOR MOBILE NUMBERS\n      SIM900.println(&quot;AT + CMGS = \\&quot;+XXXXXXXXXX\\&quot;&quot;);\n      delay(100);\n      \/\/ REPLACE WITH YOUR OWN SMS MESSAGE CONTENT\n      String dataMessage = (&quot;Temperature: &quot; + String(t) + &quot;*C &quot; + &quot; Humidity: &quot; + String(h) + &quot;%&quot;);\n      \/\/ Uncomment to change message with farenheit temperature\n      \/\/ String dataMessage = (&quot;Temperature: &quot; + String(f) + &quot;*F &quot; + &quot; Humidity: &quot; + String(h) + &quot;%&quot;);      \n      \n      \/\/ Send the SMS text message\n      SIM900.print(dataMessage);\n      delay(100);\n      \/\/ End AT command with a ^Z, ASCII code 26\n      SIM900.println((char)26); \n      delay(100);\n      SIM900.println();\n      \/\/ Give module time to send SMS\n      delay(5000);  \n    }\n  }\n  delay(10); \n}\n\nboolean readData() {\n  \/\/Read humidity\n  h = dht.readHumidity();\n  \/\/ Read temperature as Celsius\n  t = dht.readTemperature();\n  \/\/ Read temperature as Fahrenheit\n  f = dht.readTemperature(true);\n\n  \/\/ Compute temperature values in Celcius\n  t = dht.computeHeatIndex(t,h,false);\n\n  \/\/ Uncomment to compute temperature values in Fahrenheit\n  \/\/f = dht.computeHeatIndex(f,h,false);\n  \n  \/\/ Check if any reads failed and exit early (to try again).\n  if (isnan(h) || isnan(t) || isnan(f)) {\n    Serial.println(&quot;Failed to read from DHT sensor!&quot;);\n    return false;\n  }\n  Serial.print(&quot;Humidity: &quot;); \n  Serial.print(h);\n  Serial.print(&quot; %\\t&quot;);\n  Serial.print(&quot;Temperature: &quot;); \n  Serial.print(t);\n  Serial.print(&quot; *C &quot;);\n  \/\/Uncomment to print temperature in Farenheit\n  \/\/Serial.print(f);\n  \/\/Serial.print(&quot; *F\\t&quot;);\n  return true;\n}\n\nboolean SMSRequest() {\n  if(SIM900.available() &gt;0) {\n    incomingChar=SIM900.read();\n    if(incomingChar=='S') {\n      delay(10);\n      Serial.print(incomingChar);\n      incomingChar=SIM900.read();\n      if(incomingChar =='T') {\n        delay(10);\n        Serial.print(incomingChar);\n        incomingChar=SIM900.read();\n        if(incomingChar=='A') {\n          delay(10);\n          Serial.print(incomingChar);\n          incomingChar=SIM900.read();\n          if(incomingChar=='T') {\n            delay(10);\n            Serial.print(incomingChar);\n            incomingChar=SIM900.read();\n            if(incomingChar=='E') {\n              delay(10);\n              Serial.print(incomingChar);\n              Serial.print(&quot;...Request Received \\n&quot;);\n              return true;\n            }\n          }\n        }\n      }\n    }\n  }\n  return false;\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Arduino-Projects\/raw\/master\/code\/24_Data_request_via_SMS.ino\" target=\"_blank\">View raw code<\/a><\/p>\n<h3>Importing libraries<\/h3>\n<p>First, you include the libraries needed for this project: the DHT library to read from the DHT sensor and the SoftwareSerial library to communicate with the SIM900 GSM module.<\/p>\n<pre>#include \"DHT.h\"\n#include &lt;Adafruit_Sensor.h&gt;\n#include &lt;SoftwareSerial.h&gt;<\/pre>\n<h3>DHT sensor<\/h3>\n<p>Then, you tell the Arduino that the DHT data pin is connected to pin 2, select the DHT sensor type and create a dht instance. The code is compatible with other DHT sensors as long as you define the one you&#8217;re using in the code.<\/p>\n<pre>#define DHTPIN 2\n#define DHTTYPE DHT11\nDHT dht(DHTPIN, DHTTYPE);<\/pre>\n<p>You also create float variables to store the temperature and humidity values.<\/p>\n<pre>float t; \/\/ temperature in celcius\nfloat f; \/\/ temperature in fahrenheit\nfloat h; \/\/ humidity<\/pre>\n<h3>GSM shield<\/h3>\n<p>The following line configures the software serial on pins 7 and 8. Pin 7 is being configure as RX and pin 8 as TX.<\/p>\n<pre>SoftwareSerial SIM900(7, 8);<\/pre>\n<p>You also create a char variable to store the incoming SMS characters.<\/p>\n<pre>char incomingChar;<\/pre>\n<h3>setup()<\/h3>\n<p>In the <strong>setup()<\/strong>, you begin the DHT and the SIM900 shield. The SIM900 shield is set to text mode and you also set the module to send the SMS data to the serial monitor when it receives it. This is done with the following two lines, respectively:<\/p>\n<pre>SIM900.print(\"AT+CMGF=1\\r\"); \nSIM900.print(\"AT+CNMI=2,2,0,0,0\\r\");<\/pre>\n<h3>Functions<\/h3>\n<p>We create a function to read the temperature and humidity called\u00a0<strong>readData()<\/strong>. This function stores the values on the <strong>t<\/strong> and <strong>h<\/strong> variables. The code uses temperature in Celsius, but it is prepared if you want Fahrenheit instead &#8211; the code is commented on where you should make the changes.<\/p>\n<p>We also create a function that checks if the incoming message is equal to STATE &#8211; the <strong>SMSRequest()<\/strong> function. This functions returns <strong>true<\/strong> if the Arduino receives a message with the text STATE and <strong>false<\/strong> if not. \u00a0You read the SMS incoming characters using:<\/p>\n<pre>incomingChar = SIM900.read();<\/pre>\n<h3>loop()<\/h3>\n<p>In the <strong>loop()<\/strong>, you check if there was an SMS request with the <strong>SMSRequest()<\/strong> function &#8211; you check if the Arduino received a STATE message. If <strong>true<\/strong>, it will read the temperature and humidity and send it via SMS to you.<\/p>\n<p>The number the Arduino answers to is set at the following line:<\/p>\n<pre>SIM900.println(\"AT + CMGS = \\\"<span style=\"color: #ff0000;\"><strong>XXXXXXXXXXXX<\/strong><\/span>\\\"\");<\/pre>\n<p>Replace the <strong><span style=\"color: #ff0000;\">XXXXXXXXXXXX<\/span><\/strong> with the recipient&#8217;s phone number.<\/p>\n<p><strong>Note:<\/strong> you must add the number according to the international phone number format. For example, in Portugal the number is preceded by <strong><span style=\"color: #ff0000;\">+351<\/span><\/strong>XXXXXXXXX.<\/p>\n<p>Then, you store the message you want to send in the <strong>dataMessage<\/strong> variable. Finally you send the SMS text message using:<\/p>\n<pre>SIM900.print(dataMessage);<\/pre>\n<h2>Demonstration<\/h2>\n<p>When you send the STATE message to the Arduino, it replies with the sensor data.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61686\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/arduino-request-sensor-data.png?resize=477%2C401&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"477\" height=\"401\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/arduino-request-sensor-data.png?w=477&amp;quality=100&amp;strip=all&amp;ssl=1 477w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/arduino-request-sensor-data.png?resize=300%2C252&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 477px) 100vw, 477px\" \/><\/p>\n<p>Watch the video at the beginning of the post for a more in depth project demo.<\/p>\n<h2>Wrapping Up<\/h2>\n<p>This is a great project to get you started with the SIM900 GSM shield. You&#8217;ve learned how to read and send SMS text messages with the Arduino.<\/p>\n<p>You can apply the concepts learned in pretty much any project. Here&#8217;s some ideas of projects:<\/p>\n<ul>\n<li>Surveillance system that sends an SMS when it detects movement<\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/control-a-12v-lamp-via-sms-with-arduino\/\" target=\"_blank\" rel=\"noopener noreferrer\">Control a relay via SMS<\/a><\/li>\n<li>Request specific sensor data from a collection of sensors by adding more conditions to the code<\/li>\n<\/ul>\n<p><strong>If you like Arduino, you&#8217;ll certainly like these <a href=\"https:\/\/randomnerdtutorials.com\/arduino-step-by-step-projects\/\" target=\"_blank\" rel=\"noopener noreferrer\">25 Arduino Step-by-step Projects<\/a>.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this project we&#8217;re going to show you how to request sensor data via SMS with the Arduino. As an example we&#8217;re going to request the temperature and humidity from &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Request Sensor Data via SMS using Arduino and SIM900 GSM Shield\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/request-sensor-data-sms-arduino-sim900-gsm-shield\/#more-61678\" aria-label=\"Read more about Request Sensor Data via SMS using Arduino and SIM900 GSM Shield\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":61694,"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":[303,267,2,264,10],"tags":[],"class_list":["post-61678","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-arduino","category-arduino-project","category-arduino","category-project","category-a-tutorials"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/Request-Sensor-Data-via-SMS-thumbnail-f.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\/61678","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\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=61678"}],"version-history":[{"count":1,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/61678\/revisions"}],"predecessor-version":[{"id":168256,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/61678\/revisions\/168256"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/61694"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=61678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=61678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=61678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}