ArduinoArduino Projects

Request Temperature Data Using GSM and Arduino programming

 

Request Temperature

Description:

This tutorial is based on monitoring temperature and humidity using 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 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 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:

Request Temperature

GSM SIM900A Module:

Request Temperature

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 controlled 5v adaptor, you can also use 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 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

Request Temperature Programming:

/*
  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 = " ";
    }
 
}


}

Watch Video Tutorial

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button