--> Project II - 7. Temperature and Humidity Monitoring through SMS Based on Arduino | basic arduino tutorial

Thursday, September 7, 2017

Project II - 7. Temperature and Humidity Monitoring through SMS Based on Arduino

| Thursday, September 7, 2017
Temperature and Humidity Monitoring through SMS


Arduino UNO is used to process DHT11 sensor readings and then sent after SMS in certain format: "GET". If there is no SMS then the temperature is only displayed data on the LCD, and if the incoming SMS is not a "GET" text, then Aruduino will send a message saying "wrong format". Modem or GSM module used in this project with SIM900A type, can also use Wavecom Modem, coding for both modem have been provided in this blog.

Hardware Requirement
  • Arduino Uno Board
  • DHT11 Sensor
  • SIM900A GSM Module (you can also use Wavecom)
  • LCD 16*2 or 20*4 (with i2c connection is recomended)
  • Power supply +5 Volt
  • Jumper

DHT11 | Source

SIM900A | Source


Block Diagram




Schematic (Wavecom)


 If using SIM900A, then no RS232 circuit, just connect to Arduino.
Arduino - LCD 16x2


Arduino LCD 20x4 Wiring

If using 20x4 LCD and I2C connection (I Square C) then the wiring table is as follows

Learn more about I2C connections --> Project V - 14




Arduino - DHT11 Wiring





Arduino - Wavecom GSM Module


If using SIM900A then its wiring is as follows



Coding --> Wavecom

#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include "DHT.h"
#define DHTPIN 10   
#define DHTTYPE DHT11

LiquidCrystal lcd(2,3, 4, 5, 6, 7);
const int rxpin = 8;
const int txpin = 9; 
SoftwareSerial gsm(rxpin, txpin);

DHT dht(DHTPIN, DHTTYPE);
int h,t;

char str,f;
int i,j;

String inString="";

String inString2="";
String Stemp="";
String inbox="";
String noPengirim="";

void setup(){ 
  gsm.begin(9600);
  dht.begin(); 
  lcd.begin(16, 2);
  lcd.print("Tes Koneksi...");
  delay(1000); 
  gsm.println("AT");
  getmodem();
  getmodem();
  lcd.setCursor(0, 1);
  lcd.print(inString);
  delay(2000);   
  lcd.clear();
  lcd.print("Telemetri DHT11");
  lcd.setCursor(0,1);
  lcd.print("by request SMS");
  delay(3000);   
}

//=========================program utama
void loop(){
  lcd.begin(16,2);
  lcd.clear();
  lcd.print("Tunggu SMS masuk");
  lcd.setCursor(0,1);
  lcd.print("kode:GET/Get/get"); 
  //----------------------data ENTER
  getmodem(); 
  lcd.clear();
  lcd.print("SMS Masuk...");
  //----------------------data CMTI:
  getmodem2();   
  i=inString2.indexOf(':'); 
  if(i>0){
     Stemp=inString2.substring(0,i);   
     if(Stemp=="+CMTI"){       
         i=inString2.indexOf(',');
         j=inString2.length ();
         i=i+1;
         inbox=inString2.substring(i,j);       
         gsm.print("AT+CMGR=");
         gsm.println(inbox);       
         getmodem();
         getmodem();
         getmodem2();
         i=inString.indexOf(',');
         i=i+2;
         j=inString.indexOf(',',i);
         j=j-1;         
         noPengirim=inString.substring(i,j);
//--------------------------------isi SMS jika Get
         if(inString2=="GET" || inString2=="Get" || inString2=="get"){
           baca_sensor();
           kirim_sms();
         }       
//---------------------------------other sms
         else {
           gsm.print("AT+CMGS="); 
           gsm.println(noPengirim);
           delay(1000);   
           gsm.print("Format Salah!");
           gsm.write((byte)26);
           gsm.println();         
           lcd.clear();
           lcd.print("Format Salah!"); 
         }
        
        delay(3000); 
        lcd.clear();
        lcd.print("Hapus SMS:");
       //-------------------------hapus inbox
        getmodem();
        getmodem();     
        gsm.print("AT+CMGD=");
        gsm.println(inbox);
        do{
        getmodem(); 
        }
        while(inString != "OK");
        lcd.print(inbox);
        lcd.setCursor(0,1);
        lcd.print(inString);
        delay(3000);         
       }
    }
}
//===========================baca data serial
void getmodem(){
 f=1;
 inString="";
 while(f){
   if(gsm.available()){
       str=gsm.read();             
       switch (str){
           case '\r': break;
           case '\n':f=0; break;
           default:inString+=(char)str;
         }       
     }
 }
}
//====================================
void getmodem2(){
 f=1;
 inString2="";
 while(f){
   if(gsm.available()>0){
       str=gsm.read();           
       switch (str){
           case '\r': break;
           case '\n':f=0; break;
           default:inString2+=(char)str;
         }
     }
 }
}

//===================================baca sensor DHT11
void baca_sensor(){
  h = dht.readHumidity(); 
  t = dht.readTemperature();
  lcd.clear();     
  lcd.print("Temp:");   
  lcd.print(t);
  lcd.print("C"); 
  lcd.setCursor(0,1);
  lcd.print("Humi:"); 
  lcd.print(h);
  lcd.print("%"); 
  delay(3000);
}

//====================================kirim SMS
void kirim_sms(){
    gsm.print("AT+CMGS="); 
    gsm.println(noPengirim);
    delay(1000);   
    gsm.print("Suhu:");
    gsm.print(t);
    gsm.print("C, Kelembaban:");
    gsm.print(h);
    gsm.print("%.");
    gsm.write((byte)26);
    gsm.println();
    lcd.clear();
    lcd.print("Kirim SMS....");
    delay(2000);
}


Coding --> Sim900A (Recomended)


#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
#include "DHT.h"
#define DHTPIN 10
#define DHTTYPE DHT11

LiquidCrystal_I2C lcd(0x3F, 20, 4);
#include <GPRS_Shield_Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#define PIN_TX    9
#define PIN_RX    8
#define BAUDRATE  9600
#define PHONE_NUMBER "085640207374"// sesuaikan
#define MESSAGE_FALSE  "Format salah"

#define MESSAGE_LENGTH 160
char message[MESSAGE_LENGTH];
int messageIndex = 0;
char data[50];
char phone[16];
char datetime[24];
int suhu1, suhu2, suhu3, suhu4;
String suhu_all;
DHT dht(DHTPIN, DHTTYPE);
int h, t;

GPRS gprsTest(PIN_TX, PIN_RX, BAUDRATE); //RX,TX,BaudRate

void setup() {
  dht.begin();
  lcd.begin();
  lcd.setCursor(0, 0);
  lcd.print("Initialization.....");
  lcd.setCursor(0, 2);
  lcd.print("       Waiting     ");
  delay(1000);
  while (!gprsTest.init()) {
    delay(1000);
    Serial.print("init error\r\n");
  }
  Serial.println("gprs init success");
  //In order not to full SIM Memory, is better to delete it
  gprsTest.deleteSMS(messageIndex);
  delay(1000);
  lcd.clear();
}

//=========================program utama
void loop() {
  lcd.setCursor(0, 0);
  lcd.print("Monitoring DHT11-SMS");
  lcd.setCursor(0, 2);
  lcd.print("       READY      ");
  messageIndex = gprsTest.isSMSunread();
  if (messageIndex > 0) { //At least, there is one UNREAD SMS
    gprsTest.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
    if (String(message) == "GET")
    {
      Serial.print("From number: ");
      Serial.println(phone);
      Serial.print("Datetime: ");
      Serial.println(datetime);
      Serial.print("Recieved Message: ");
      Serial.println(message);
      lcd.setCursor(0, 1);
      lcd.print("    New Message   ");
      lcd.setCursor(3, 2);
      lcd.print(phone);
      lcd.setCursor(8, 3);
      lcd.print(message);
      delay(2000);
      h = dht.readHumidity();
      t = dht.readTemperature();
      lcd.setCursor(0, 2);
      lcd.print("                    ");
      delay(100);
      suhu_all = String(t) + "C  " + String(h) + "% ";
      lcd.setCursor(7, 2);
      lcd.print(suhu_all);
      delay(2000);
      lcd.setCursor(0, 3);
      lcd.print("Sending data . . .");
      Serial.println(suhu_all);
      delay(3000);
      suhu_all.toCharArray(data, 50);
      gprsTest.sendSMS(PHONE_NUMBER, data);
      lcd.clear();
    }
    else
    {
      lcd.setCursor(0, 2);
      lcd.print("      Format Salah    ");
      delay(1000);
      gprsTest.sendSMS(PHONE_NUMBER, MESSAGE_FALSE);
      lcd.clear();
    }
  }
}


How it Works

1. Connect the Arduino with Peripherals needed.
2. Plug in the Power Source on the device.

3. Add some library if needed
4. Compile and upload the script program
5. First, Modem will initialize and it takes about 3 seconds



4. When the modem is ready, the LCD will show that the system is ready


5. When there is an SMS marked "GET" character then the number and text will be displayed on the LCD



6. Next LCD will display data readings of DHT11 sensor


 7. Arduino will send the data to the specified number in the program.


8. The display returns to normal again (home page).



Video for Project II - 7. Temperature and Humidity Monitoring through SMS Based on Arduino



Required file


Related Posts

No comments:

Post a Comment