Request Temperature Data Using GSM and Arduino
Request Temperature Data Using GSM and Arduino
com
/request-temperature-data-using-gsm-and-arduino/
Request Temperature using GSM– This project is based on the Temperature and Humidity
monitoring using a Cell phone, Arduino, and the famous DHT11 Temperature and Humidity Sensor. In
this tutorial, you will learn how to request temperature and humidity values from anywhere around the
world using your cell phone. There are projects in which the Sensors data is sent after regular intervals,
which I believe is not good. This project is different from the rest of the GSM-based projects, as in this
project the Temperature and Humidity values are sent only when the owner sends a request message.
Amazon Links:
12v Adaptor:
Arduino Uno
Arduino Nano
Mega 2560:
1/8
DC 5V 2A Adaptor
Digital Oscilloscopes
Variable Supply
Digital Multimeter
*Please Note: These are affiliate links. I may make a commission if you buy the components through
these links. I would appreciate your support in this way!
The DHT11 Temperature and Humidity module have a total of 4 pins, out of which only three pins are
used. Pin number 3 is not used. The interfacing of the DHT11 temperature sensor with the Arduino can
be seen in the circuit diagram. For the complete explanation, watch the video given at the end.
2/8
GSM SIM900A Module:
This is the GSM module that I will be using in this tutorial, in the market we have different types of GSM
modules, the one I will be using today is SIM900A, the same code is also tested on sim900D, so if you
want you can also use sim900D.
If you are from Pakistan, Bangladesh or India make sure you purchase the unlocked version of the
SIM900A. This GSM SIM900A module the one we will be using in this tutorial, as you can see on the
screen has no Onboard voltage regulator, so be careful while applying the voltage. The ideal voltage for
this GSM module is 4.7v but you can also connect it with the 5v adaptor.
As the ideal voltage for this GSM module is 4.7v to 5volts, so any voltage above this can damage the
GSM module. If you don’t have the regulated 5v adaptor then you can also use an lm317t adjustable
voltage regulator. I have a very detailed tutorial on this. Watch the video.
3/8
As you can see SIM900A module has so many pins that are clearly labeled but we will be using only 5 of
these pins, the power supply pins, GND, RXD 5v, and TXD 5v. The GND of the GSM SIM900A module
will be connected with the Arduino GND, TXD of the GSM SIM900A will be connected with the Arduino
pin7 and finally, the RXD of the GSM SIM900A module will be connected with the Arduino pin8.
For the complete circuit Diagram explanation watch Video tutorial given at the end of this article.
4/8
21 // Connect pin 4 (on the right) of the sensor to GROUND
22 // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
23
24 // Initialize DHT sensor for normal 16mhz Arduino
25 DHT dht(DHTPIN, DHTTYPE);
26
27 char inchar; // Will hold the incoming character from the GSM shield
28
29 SoftwareSerial SIM900(8, 7); // gsm module connected here.
30
31 String TextForSms ;
32 String humidity = " Humidity: %";
33 String temperature = " Temperature";
34 String sign = " *C";
35
36
37 void setup() {
38
39 Serial.begin(9600);
40 SIM900.begin(9600); // original 19200
41 dht.begin();
42 pinMode(6, OUTPUT);
43 digitalWrite(6, HIGH);
44
45 // delay(10000); // give time to log on to network.
46 randomSeed(analogRead(0));
47
48 SIM900.print("AT+CMGF=1\r"); // set SMS mode to text
49 delay(1000);
50 SIM900.print("AT+CNMI=2,2,0,0,0\r");
51 // blurt out contents of new SMS upon receipt to the GSM shield's serial out
52 delay(1000);
53 SIM900.println("AT+CMGD=1,4"); // delete all SMS
54 delay(5000);
55 Serial.println("Ready...");
56
57 }
58
59
60
61
62 void sendSMS(String message)
63 {
64 SIM900.println("AT+CMGF=1\r"); // AT command to send SMS message
65 delay(1000);
66 SIM900.println("AT+CMGS = \"+923339218213\""); // recipient's mobile number, in
67 international format
68 delay(1000);
69 SIM900.println(message); // message to send
70 delay(1000);
71 SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
72 delay(1000);
73 SIM900.println();
74 delay(1000); // give module time to send SMS
75 // turn off module
76 }
5/8
77 void loop() {
78
79 if(SIM900.available() == 0)
80 {
81
82 // Wait a few seconds between measurements.
83 delay(2000);
84
85 // Reading temperature or humidity takes about 250 milliseconds!
86 // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
87 int h = dht.readHumidity();
88 // Read temperature as Celsius
89 int t = dht.readTemperature();
90 // Read temperature as Fahrenheit
91 int f = dht.readTemperature(true);
92
93 // Check if any reads failed and exit early (to try again).
94 if (isnan(h) || isnan(t) || isnan(f)) {
95 Serial.println("Failed to read from DHT sensor!");
96 return;
97 }
98
99 // Compute heat index
100 // Must send in temp in Fahrenheit!
101 int hi = dht.computeHeatIndex(f, h);
102
103 // Serial.print("Humidity: ");
104 // Serial.print(h);
105 // Serial.print(" %\t");
106 // Serial.print("Temperature: ");
107 // Serial.print(t);
108 // Serial.print(" *C ");
109
110 TextForSms = TextForSms + "Humidity: ";
111 TextForSms.concat(h);
112 TextForSms = TextForSms + "% Temperature: ";
113 TextForSms.concat(t);
114 TextForSms = TextForSms + "*C";
115 Serial.println(TextForSms);
116 delay(2000);
117 TextForSms = " ";
118
119 if ( t > 40 )
120 {
121 Serial.println("Temperature Exceeded");
122 TextForSms = " Temperature Exceeded";
123 sendSMS(TextForSms);
124 delay(5000);
125 TextForSms = "";
126 }
127
128 }
129 if(SIM900.available() >0)
130 {
131
132 inchar=SIM900.read();
6/8
133 Serial.println(inchar);
134 delay(20);
135 if (inchar=='v')
136 {
137 delay(10);
138 Serial.println(inchar);
139
140 // Wait a few seconds between measurements.
141 delay(2000);
142
143 // Reading temperature or humidity takes about 250 milliseconds!
144 // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
145 int h = dht.readHumidity();
146 // Read temperature as Celsius
147 int t = dht.readTemperature();
148 // Read temperature as Fahrenheit
149 int f = dht.readTemperature(true);
150
151 // Check if any reads failed and exit early (to try again).
152 if (isnan(h) || isnan(t) || isnan(f)) {
153 Serial.println("Failed to read from DHT sensor!");
154 return;
155 }
156
157 // Compute heat index
158 // Must send in temp in Fahrenheit!
159 int hi = dht.computeHeatIndex(f, h);
160
161 // Serial.print("Humidity: ");
162 // Serial.print(h);
163 // Serial.print(" %\t");
164 // Serial.print("Temperature: ");
165 // Serial.print(t);
166 // Serial.print(" *C ");
167
168 TextForSms = TextForSms + "HUMIDITY: ";
169 TextForSms.concat(h);
170 TextForSms = TextForSms + "% TEMPERATURE: ";
171 TextForSms.concat(t);
172 TextForSms = TextForSms + "*C";
173 sendSMS(TextForSms);
174 Serial.println(TextForSms);
175 delay(2000);
176 TextForSms = " ";
177 }
178 }
179
180
181 }
182
183
7/8
Other GSM Related Projects:
How to use GSM and Bluetooth Together To monitor Any Sensors wirelessly using Arduino
Tags
Arduino arduino and GSM based temperature arduino and GSM to monitor temperature arduino GSM
and dht11 sensor arduino GSM temperature arduino GSM temperature monitoring arduino temperautre
GSM cell dht11 dht11 with arduino GSM gsm GSM temperature monitoring monitoring read temperature
through GSM arduino request temperature using GSM request temperature using GSM and arduino
sim900A temperature temperature monitoring through GSM arduino temperature monitoring using GSM
8/8