In this project we’re going to show you how to request sensor data via SMS with the Arduino. As an example we’re going to request the temperature and humidity from a DHT11 sensor. To send and receive SMS with the Arduino we’re going to use the SIM900 GSM shield.
![]()
When you send an SMS to the Arduino with the message “STATE”, it replies with the latest temperature and humidity readings.
Before proceeding with this tutorial we recommend the following resources:
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’s the shield we recommend you to get.
The SIM900 GSM shield is shown in figure below:

For an introduction to the GSM shield, and how to set it up, read the Guide to SIM900 GSM GPRS Shield with Arduino.
Here’s a list of all the components needed for this project:

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!
Before getting started with your SIM900 GSM module, you need to consider some aspects about the SIM card and the shield power supply.
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’re using a prepaid plan with unlimited SMS.

The shield uses the original SIM card size, not micro or nano. If you have micro or nano you may consider getting a SIM card size adapter.
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.
In my case, I need to go through: Settings > Advanced Settings > Security > SIM lock and turn off the lock sim card with pin.

The shield has a DC jack for power as shown in figure below.

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 – move the toggle switch to use the external power supply as shown above.
To power up the shield, it is advisable to use a 5V power supply that can provide 2A as the one shown below.

You can find the right power adapter for this shield here. Make sure you select the model with 5V and 2A.
The following steps show you how to set up the SIM900 GSM shield.
1) Insert 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.

2) Confirm the antenna is well connected.
3) On the serial port select, make sure the jumper cap is connected as shown in figure below to use software serial.

4) Power the shield using an external 5V power supply. Double-check that you have the external power source selected as we’ve mentioned earlier.

5) To power up/down the shield press the power key for about 2 seconds.

6) 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.

7) You can test if the shield is working properly by sending AT commands from the Arduino IDE using an FTDI programmer – as we’ll show below.
You don’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.

1) Connect the FTDI programmer to the GSM shield as shown in figure below.
2) Open the Arduino IDE and select the right COM port.
3) Open the Serial monitor.

4) Select 19200 baud rate – the shield default setting is 19200 – and Carriage return. Write AT at the box highlighted in red and then press enter. See figure below.

5) The shield will respond with OK, if everything is working properly.

Now that you know the shield is working properly, you are ready to start building the project.
The figure below shows the circuit schematics for this project.
You have to connect the SIM900 GSM shield and the DHT11 temperature and humidity sensor to the Arduino as shown in the figure below.
To read from the DHT sensor, you must have the DHT library installed. If you don’t have the DHT library installed, follow the instructions below:
To use the DHT temperature and humidity sensor, you also need to install the Adafruit_Sensor library. Follow the next steps to install the library in your Arduino IDE:
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 “STATE”.
You need to modify the code provided with the phone number your Arduino should reply the readings to. The code is well commented for you to understand the purpose of each line of code. Don’t upload the code now. Scroll down and read the explanation below the code.
/* * Rui Santos * Complete Project Details https://randomnerdtutorials.com */ // Include DHT library and Adafruit Sensor Library #include "DHT.h" #include <Adafruit_Sensor.h> //Include Software Serial library to communicate with GSM #include <SoftwareSerial.h> // Pin DHT is connected to #define DHTPIN 2 // Uncomment whatever type of sensor you're using #define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22 (AM2302) //#define DHTTYPE DHT21 // DHT 21 (AM2301) // Initialize DHT sensor for normal 16mhz Arduino DHT dht(DHTPIN, DHTTYPE); // Create global varibales to store temperature and humidity float t; // temperature in celcius float f; // temperature in fahrenheit float h; // humidity // Configure software serial port SoftwareSerial SIM900(7, 8); // Create variable to store incoming SMS characters char incomingChar; void setup() { dht.begin(); Serial.begin(19200); SIM900.begin(19200); // Give time to your GSM shield log on to network delay(20000); Serial.print("SIM900 ready..."); // AT command to set SIM900 to SMS mode SIM900.print("AT+CMGF=1\r"); delay(100); // Set module to send SMS data to serial out upon receipt SIM900.print("AT+CNMI=2,2,0,0,0\r"); delay(100); } void loop(){ if (SMSRequest()){ if(readData()){ delay(10); // REPLACE THE X's WITH THE RECIPIENT'S MOBILE NUMBER // USE INTERNATIONAL FORMAT CODE FOR MOBILE NUMBERS SIM900.println("AT + CMGS = \"+XXXXXXXXXX\""); delay(100); // REPLACE WITH YOUR OWN SMS MESSAGE CONTENT String dataMessage = ("Temperature: " + String(t) + "*C " + " Humidity: " + String(h) + "%"); // Uncomment to change message with farenheit temperature // String dataMessage = ("Temperature: " + String(f) + "*F " + " Humidity: " + String(h) + "%"); // Send the SMS text message SIM900.print(dataMessage); delay(100); // End AT command with a ^Z, ASCII code 26 SIM900.println((char)26); delay(100); SIM900.println(); // Give module time to send SMS delay(5000); } } delay(10); } boolean readData() { //Read humidity h = dht.readHumidity(); // Read temperature as Celsius t = dht.readTemperature(); // Read temperature as Fahrenheit f = dht.readTemperature(true); // Compute temperature values in Celcius t = dht.computeHeatIndex(t,h,false); // Uncomment to compute temperature values in Fahrenheit //f = dht.computeHeatIndex(f,h,false); // Check if any reads failed and exit early (to try again). if (isnan(h) || isnan(t) || isnan(f)) { Serial.println("Failed to read from DHT sensor!"); return false; } Serial.print("Humidity: "); Serial.print(h); Serial.print(" %\t"); Serial.print("Temperature: "); Serial.print(t); Serial.print(" *C "); //Uncomment to print temperature in Farenheit //Serial.print(f); //Serial.print(" *F\t"); return true; } boolean SMSRequest() { if(SIM900.available() >0) { incomingChar=SIM900.read(); if(incomingChar=='S') { delay(10); Serial.print(incomingChar); incomingChar=SIM900.read(); if(incomingChar =='T') { delay(10); Serial.print(incomingChar); incomingChar=SIM900.read(); if(incomingChar=='A') { delay(10); Serial.print(incomingChar); incomingChar=SIM900.read(); if(incomingChar=='T') { delay(10); Serial.print(incomingChar); incomingChar=SIM900.read(); if(incomingChar=='E') { delay(10); Serial.print(incomingChar); Serial.print("...Request Received \n"); return true; } } } } } } return false; }
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.
#include "DHT.h" #include <Adafruit_Sensor.h> #include <SoftwareSerial.h>
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’re using in the code.
#define DHTPIN 2 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE);
You also create float variables to store the temperature and humidity values.
float t; // temperature in celcius float f; // temperature in fahrenheit float h; // humidity
The following line configures the software serial on pins 7 and 8. Pin 7 is being configure as RX and pin 8 as TX.
SoftwareSerial SIM900(7, 8);
You also create a char variable to store the incoming SMS characters.
char incomingChar;
In the setup(), 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:
SIM900.print("AT+CMGF=1\r");
SIM900.print("AT+CNMI=2,2,0,0,0\r");We create a function to read the temperature and humidity called readData(). This function stores the values on the t and h variables. The code uses temperature in Celsius, but it is prepared if you want Fahrenheit instead – the code is commented on where you should make the changes.
We also create a function that checks if the incoming message is equal to STATE – the SMSRequest() function. This functions returns true if the Arduino receives a message with the text STATE and false if not. You read the SMS incoming characters using:
incomingChar = SIM900.read();
In the loop(), you check if there was an SMS request with the SMSRequest() function – you check if the Arduino received a STATE message. If true, it will read the temperature and humidity and send it via SMS to you.
The number the Arduino answers to is set at the following line:
SIM900.println("AT + CMGS = \"XXXXXXXXXXXX\"");Replace the XXXXXXXXXXXX with the recipient’s phone number.
Note: you must add the number according to the international phone number format. For example, in Portugal the number is preceded by +351XXXXXXXXX.
Then, you store the message you want to send in the dataMessage variable. Finally you send the SMS text message using:
SIM900.print(dataMessage);
When you send the STATE message to the Arduino, it replies with the sensor data.

Watch the video at the beginning of the post for a more in depth project demo.
Copyright ©2025. All Rights Reserved Emblab THE RAVE INNOVATION