Request Temperature Data Using GSM and Arduino programming
Description:
This tutorial is based on monitoring temperature and humidity using a cell phone, Arduino and the well-known temperature and humidity sensor DHT11. In this project, we will learn how to use your cell phone to measure temperature and humidity from anywhere in the world. There are projects where the data from the Sensors is sent after regular intervals, which I don’t think is good. This project differs from the rest of the GSM-based projects, as the temperature and humidity values are only sent in this project when the owner sends a request message.
The Amazon Purchase links are given below:
dht11 sensor: https://amzn.to/2sPejzO
GSM SIM900A: https://amzn.to/2QaHuXb
Arduino Uno: https://amzn.to/39aq6ZT
Mega 2560: https://amzn.to/2SszMsI
lm7805 Voltage Regulator: https://amzn.to/2ERYoTJ
330-ohm resistors pack: https://amzn.to/2Qj1Igg
female DC power jack socket: https://amzn.to/377Pg9M
470uf capacitors: https://amzn.to/2MrN3xR
5×7 cm Vero board: https://amzn.to/37b7KWO
female headers: https://amzn.to/350w6RE
connection wires: https://amzn.to/2MvOJXd
Super Starter kit for Beginners: https://amzn.to/398dliF
Jumper Wires: https://amzn.to/2SrnBwo
Bread Board: https://amzn.to/2MxV5FM
12v Adaptor: https://amzn.to/2MuOlZk
PCB plate: https://amzn.to/2MuwNMB
Variable Supply: https://amzn.to/39d0KdP
Digital Multimeter: https://amzn.to/34WbVoa
Vero Board / stripboard: https://amzn.to/39nL9Zg
Soldering iron kit: “best” You guys should definitely purchase this: https://amzn.to/2PVwexF
Solder wire: https://amzn.to/2QlOvTS
Wire Stripper: https://amzn.to/353tYJa
wirecutter: https://amzn.to/2tV2lFj
PCB small portable drill machine: https://amzn.to/2MvQqnx
DISCLAIMER:
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!
DHT11 Temperature and Humidity Sensor:
GSM SIM900A Module:
This is the GSM module I’m going to use in this tutorial, we have different types of GSM modules on the market, the one I’m going to use today is GSM SIM900A, the same software is also being tested on sim900D, so you can use sim900D if you want.
If you’re from Pakistan, Bangladesh or India, make sure you’re buying the SIM900A unlocked version. In this tutorial, I will use GSM SIM900A, as you can see that there is no on-board voltage regulator on the screen, so be careful when applying the voltage. For this GSM module, the ideal voltage is 4.7v but you can also connect it to the 5v adaptor.
Since the ideal voltage is 4.7v to 5volts for this GSM module, any above voltage can harm the GSM module. If you do not have a controlled 5v adaptor, you can also use a voltage regulator that can be set to lm317t.
As you can see, there are so many pins in the SIM900A module that are clearly labeled but only 5 of these pins, the power supply pins, GND, Rxd 5v, and txd 5v will be used.The GSM SIM900A module’s GND will connect to the Arduino GND, the GSM SIM900A’s txd will link to the Arduino pin7, and eventually, the GSM SIM900A’s rxd will attach to the Arduino pin8.
Request Temperature Circuit Diagram:
Request Temperature Programming:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
/* commands v = feedback request */ #include <SoftwareSerial.h> #include "DHT.h" #define DHTPIN 12 // what pin we're connected to //Uncomment whatever the type of sensor we are using. #define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22 (AM2302) //#define DHTTYPE DHT21 // DHT 21 (AM2301) // Connect pin 1 (on the left) of the sensor to +5V // NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1 // to 3.3V instead of 5V! // Connect pin 2 of the sensor to whatever your DHTPIN is // pin3 of the sensor is not connected // Connect pin 4 (on the right) of the sensor to GROUND // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor // Initialize DHT sensor for normal 16mhz Arduino DHT dht(DHTPIN, DHTTYPE); char inchar; // Will hold the incoming character from the GSM shield SoftwareSerial SIM900(8, 7); // gsm module connected here. String TextForSms ; String humidity = " Humidity: %"; String temperature = " Temperature"; String sign = " *C"; void setup() { Serial.begin(9600); SIM900.begin(9600); // original 19200 dht.begin(); pinMode(6, OUTPUT); digitalWrite(6, HIGH); // delay(10000); // give time to log on to network. randomSeed(analogRead(0)); SIM900.print("AT+CMGF=1\r"); // set SMS mode to text delay(1000); SIM900.print("AT+CNMI=2,2,0,0,0\r"); // blurt out contents of new SMS upon receipt to the GSM shield's serial out delay(1000); SIM900.println("AT+CMGD=1,4"); // delete all SMS delay(5000); Serial.println("Ready..."); } void sendSMS(String message) { SIM900.println("AT+CMGF=1\r"); // AT command to send SMS message delay(1000); SIM900.println("AT+CMGS = \"+923339218213\""); // recipient's mobile number, in international format delay(1000); SIM900.println(message); // message to send delay(1000); SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26 delay(1000); SIM900.println(); delay(1000); // give module time to send SMS // turn off module } void loop() { if(SIM900.available() == 0) { // Wait a few seconds between measurements. delay(2000); // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) int h = dht.readHumidity(); // Read temperature as Celsius int t = dht.readTemperature(); // Read temperature as Fahrenheit int f = dht.readTemperature(true); // 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; } // Compute heat index // Must send in temp in Fahrenheit! int hi = dht.computeHeatIndex(f, h); // Serial.print("Humidity: "); // Serial.print(h); // Serial.print(" %\t"); // Serial.print("Temperature: "); // Serial.print(t); // Serial.print(" *C "); TextForSms = TextForSms + "Humidity: "; TextForSms.concat(h); TextForSms = TextForSms + "% Temperature: "; TextForSms.concat(t); TextForSms = TextForSms + "*C"; Serial.println(TextForSms); delay(2000); TextForSms = " "; if ( t > 40 ) { Serial.println("Temperature Exceeded"); TextForSms = " Temperature Exceeded"; sendSMS(TextForSms); delay(5000); TextForSms = ""; } } if(SIM900.available() >0) { inchar=SIM900.read(); Serial.println(inchar); delay(20); if (inchar=='v') { delay(10); Serial.println(inchar); // Wait a few seconds between measurements. delay(2000); // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) int h = dht.readHumidity(); // Read temperature as Celsius int t = dht.readTemperature(); // Read temperature as Fahrenheit int f = dht.readTemperature(true); // 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; } // Compute heat index // Must send in temp in Fahrenheit! int hi = dht.computeHeatIndex(f, h); // Serial.print("Humidity: "); // Serial.print(h); // Serial.print(" %\t"); // Serial.print("Temperature: "); // Serial.print(t); // Serial.print(" *C "); TextForSms = TextForSms + "HUMIDITY: "; TextForSms.concat(h); TextForSms = TextForSms + "% TEMPERATURE: "; TextForSms.concat(t); TextForSms = TextForSms + "*C"; sendSMS(TextForSms); Serial.println(TextForSms); delay(2000); TextForSms = " "; } } } |