Translate

Membuat Alat Monitoring Suhu dan Kelembaban DHT22 SMS Gateway SIM900A RTC DS3231 ARDUINO

Membuat Alat Monitoring Suhu dan Kelembaban DHT22 SMS Gateway SIM900A RTC DS3231 ARDUINO


         Pada kesempaan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa digunakan untuk monitoring suhu dan kelembaban dengan indikator berupa SMS. alat ini terdapat fitur RTC yang digunakan untuk menampilkan jam dan waktu kemudian SIM900A digunakan untuk mengirimkan sms tiap jam tertentu sesuai pada program.



a. Arduino Uno




b. Sensor DHT22




c. LCD + I2C




d. RTC Modul






e. Program arduino IDE

#include "Wire.h"
#include <LiquidCrystal.h>
#include "DHT.h"
#include "SIM900.h"
#include <SoftwareSerial.h>

#include "sms.h"
SMSGSM sms;

#define DHTPIN 8     // what digital pin we're connected to
#define DHTTYPE DHT22   // DHT 22
#define DS3231_I2C_ADDRESS 0x68

DHT dht(DHTPIN, DHTTYPE);

LiquidCrystal lcd(9, 10, 4, 5, 6, 7);
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

int relaykipas1 = A0;
int relaykipas2 = A1;
int relaypompa = A2;
int relayheater = A3;

// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}


int mark = 0;
char string[160];

int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];

int tanda = 0;
int tanda2 = 0;

void setup() {

pinMode(relaykipas1,OUTPUT);
pinMode(relaykipas2,OUTPUT);
pinMode(relaypompa,OUTPUT);
pinMode(relayheater,OUTPUT);
 
digitalWrite(relaykipas1,HIGH); 
digitalWrite(relaykipas2,HIGH); 
digitalWrite(relaypompa,HIGH); 
digitalWrite(relayheater,HIGH); 
 
  lcd.begin(16, 2);
  lcd.clear();
  lcd.noCursor();
 
   lcd.setCursor(0,0);
   lcd.print("LOADING......");
  
     //Serial connection.
     Serial.begin(9600);
     Serial.println("GSM Shield testing.");
     //Start configuration of shield with baudrate.
     //For http uses is raccomanded to use 4800 or slower.
     if (gsm.begin(2400)) {
          Serial.println("\nstatus=READY");
          started=true;
     } else Serial.println("\nstatus=IDLE");

     if(started) {
         //if (sms.SendSMS("089691234567", "Alat Ready"))
         // Serial.println("\nSMS sent OK");
     }

  dht.begin();
  Serial.begin(9600);
   while (!Serial) {
  }
 
  lcd.clear();
 
    Wire.begin();
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
   setDS3231time(0,59,5,6,23,11,18);




void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
  // sets time and date data to DS3231
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)
  Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}
void displayTime()
{
  lcd.setCursor(0,1);
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  lcd.print(hour, DEC);
  // convert the byte variable to a decimal number when displayed
  lcd.print(":");
  if (minute<10)
  {
    lcd.print("0");
  }
  lcd.print(minute, DEC);
  lcd.print(":");
  if (second<10)
  {
    lcd.print("0");
  }
  lcd.print(second, DEC);
  lcd.print(" ");
  Serial.print(dayOfMonth, DEC);
  Serial.print("/");
  Serial.print(month, DEC);
  Serial.print("/");
  Serial.print(year, DEC);
  Serial.print(" Day of week: ");
  switch(dayOfWeek){
  case 1:
    Serial.println("Sunday");
    break;
  case 2:
    Serial.println("Monday");
    break;
  case 3:
    Serial.println("Tuesday");
    break;
  case 4:
    Serial.println("Wednesday");
    break;
  case 5:
    Serial.println("Thursday");
    break;
  case 6:
    Serial.println("Friday");
    break;
  case 7:
    Serial.println("Saturday");
    break;
  }
}

void loop(){
 displayTime();
 int h = dht.readHumidity();
 int t = dht.readTemperature();
 int f = dht.readTemperature(true);

 sprintf(string,"suhu = %d dan kelembaban = %d ", t , h);
 
 int hum = h ;
 int suhu = t;

  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  float hif = dht.computeHeatIndex(f, h);
  float hic = dht.computeHeatIndex(t, h, false);
 
   lcd.setCursor(0,0);
   lcd.print("s/h=");
   lcd.print(suhu);
   lcd.print("/");
   lcd.print(hum);
   lcd.print("        ");



 if((suhu > 25)&&(suhu < 32)){
 digitalWrite(relaykipas1,HIGH);
 digitalWrite(relaykipas2,HIGH);
 digitalWrite(relayheater,HIGH); 
 }


 if(suhu < 25){
 digitalWrite(relayheater,LOW);
 }
 if(suhu >= 32){
 digitalWrite(relayheater,HIGH);
 digitalWrite(relaykipas1,LOW);
 digitalWrite(relaykipas2,LOW);
 }



 if(hum < 60){
 digitalWrite(relaypompa,LOW);
 }
 if(hum > 60){
 digitalWrite(relaypompa,HIGH);
 }

 if(hum >= 70){
 digitalWrite(relayheater,LOW);
 }

 if(hum < 70){
 digitalWrite(relayheater,HIGH);
 }


 if((suhu > 32)&&(tanda == 0)){
    if (sms.SendSMS("089691234567", "suhu ekstrim"))
    Serial.println("\nSMS sent OK");
    tanda = 1;
 }

 if((suhu >= 25)&&(suhu <= 32)){
  tanda = 0;
 }

 if((suhu < 25)&&(tanda == 0)){
    if (sms.SendSMS("089691234567", "suhu ekstrim"))
    Serial.println("\nSMS sent OK");
    tanda = 1;
 }


 if((hum > 70)&&(tanda2 == 0)){
    if (sms.SendSMS("089691234567", "kelembaban ekstrim"))
    Serial.println("\nSMS sent OK");
    tanda2 = 1;
 }

 if((hum < 60)&&(tanda2 == 0)){
    if (sms.SendSMS("089691234567", "kelembaban ekstrim"))
    Serial.println("\nSMS sent OK");
    tanda2 = 1;   
 }

 if((hum >= 60)&&(hum <= 70)){
    tanda2 = 0;
 }



   if((hour == 6)&&(mark == 0)){  
   if (sms.SendSMS("089691234567", string));
   mark = 1;
   }  

   if((hour == 9)&&(mark == 1)){  
   if (sms.SendSMS("089691234567", string));
   mark = 2;
   }
 
   if((hour == 12)&&(mark == 2)){  
   if (sms.SendSMS("089691234567", string));
   mark = 3;
   } 
  
   if((hour == 15)&&(mark == 3)){  
   if (sms.SendSMS("089691234567", string));
   mark = 4;
   }
  
   if((hour == 18)&&(mark == 4)){  
   if (sms.SendSMS("089691234567", string));
   mark = 0;
   }
 
   delay(1000);
  

 

 


f. VIDEO HASILNYA










No comments:

Post a Comment