Lampiran 2
Data Arduino
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
#include "MQ7.h"
#include "DHT.h"
#define DHTPIN 22
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
MQ7 mq7(A0,5.0);
SoftwareSerial mySerial(7, 8);
LiquidCrystal_I2C lcd(0x3F, 16, 2);
void setup()
{
lcd.begin();
lcd.setCursor(0, 0);
lcd.print("Leo Afrendra");
lcd.setCursor(0, 1);
lcd.print("1410024427082");
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Alat Pendeteksi");
lcd.setCursor(0, 1);
lcd.print("Gas CO dan suhu");
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Menghubungkan Ke");
lcd.setCursor(0, 1);
lcd.print("Jaringan....");
delay(20000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Terkoneksi Ke");
lcd.setCursor(0, 1);
lcd.print("Jaringan....");
delay(1000);
pinMode(6, OUTPUT); //buzzer
dht.begin();
mySerial.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
delay(100);
}
void loop()
{
float celcius_1 = dht.readTemperature();
float data = celcius_1 - 7;
Serial.print("Suhu : ");
Serial.print(data);
Serial.print(" 'C ");
//Serial.print("\n");
float gas = mq7.getPPM();
//float persen= gas*0.0001;
Serial.print("Gas : ");
Serial.print(gas);
Serial.print("\n");
//Serial.print(persen);
//Serial.print("\n");
if (gas >= 200) // bahaya
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Gas CO : ");
lcd.print(gas);
lcd.setCursor(13, 0);
lcd.println("ppm ");
lcd.setCursor(2, 1);
lcd.print("STATUS BAHAYA");
lcd.setCursor(0, 1);
lcd.print("Suhu : ");
lcd.print(data);
lcd.setCursor(13, 1);
lcd.println(" 'C ");
digitalWrite(6, HIGH);
Serial.print(gas);
Serial.println();
{
SendMessageBahaya();
}
}
else if ((gas >= 101)&&(gas <= 200)) //Tidak Sehat
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Gas CO : ");
lcd.print(gas);
lcd.setCursor(13, 0);
lcd.println("ppm ");
lcd.setCursor(0, 1);
lcd.print("STATUS TDK SEHAT");
lcd.setCursor(0, 1);
lcd.print("Suhu : ");
lcd.print(data);
lcd.setCursor(13, 1);
lcd.println(" 'C ");
digitalWrite(6, HIGH);
Serial.print(gas);
Serial.println();
{
SendMessageTidakSehat();
}
}
else if ((gas >= 51)&&(gas <= 100)) //Sedang
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Gas CO : ");
lcd.print(gas);
lcd.setCursor(13, 0);
lcd.println("ppm ");
lcd.setCursor(2, 1);
lcd.print("STATUS SEDANG");
lcd.setCursor(0, 1);
lcd.print("Suhu : ");
lcd.print(data);
lcd.setCursor(13, 1);
lcd.println(" 'C ");
digitalWrite(6, HIGH);
Serial.print(gas);
Serial.println();
{
SendMessageSedang();
}
}
else if ((gas >= 5)&&(gas <= 50)) //Baik
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Gas CO : ");
lcd.print(gas);
lcd.setCursor(13, 0);
lcd.println("ppm ");
lcd.setCursor(2, 1);
lcd.print("STATUS BAIK");
lcd.setCursor(0, 1);
lcd.print("Suhu : ");
lcd.print(data);
lcd.setCursor(13, 1);
lcd.println(" 'C ");
digitalWrite(6, LOW);
Serial.print(gas);
Serial.println();
{
SendMessageBaik();
}
}
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Gas CO : ");
lcd.print(gas);
lcd.setCursor(13, 0);
lcd.println("ppm ");
lcd.setCursor(0, 1);
lcd.print("Suhu : ");
lcd.print(data);
lcd.setCursor(13, 1);
lcd.println(" 'C ");
digitalWrite(6, LOW);
Serial.print(gas);
Serial.println();
}
delay(200);
}
void SendMessageBahaya()
{
float gas = mq7.getPPM();
float celcius_1 = dht.readTemperature();
float data = celcius_1 - 7;
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"+6282288148871\"\r"); // Replace x with mobile
number
delay(1000);
mySerial.println("Gas CO dalam STATUS BAHAYA");// The SMS text you want
to send
delay(100);
mySerial.println(gas);delay(100);
mySerial.println("ppm");
mySerial.println("Suhu :");// The SMS text you want to send
delay(100);
mySerial.println(data);delay(100);
mySerial.println("*C");
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void SendMessageTidakSehat()
{
float gas = mq7.getPPM();
float celcius_1 = dht.readTemperature();
float data = celcius_1 - 7;
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"+6282288148871\"\r"); // Replace x with mobile
number
delay(1000);
mySerial.println("Gas CO dalam STATUS TIDAK SEHAT");// The SMS text you
want to send
delay(100);
mySerial.println(gas);delay(100);
mySerial.println("ppm");
mySerial.println("Suhu :");// The SMS text you want to send
delay(100);
mySerial.println(data);delay(100);
mySerial.println("*C");
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void SendMessageSedang()
{
float gas = mq7.getPPM();
float celcius_1 = dht.readTemperature();
float data = celcius_1 - 7;
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"+6282288148871\"\r"); // Replace x with mobile
number
delay(1000);
mySerial.println("Gas CO dalam STATUS SEDANG");// The SMS text you want to
send
delay(100);
mySerial.println(gas);delay(100);
mySerial.println("ppm");
mySerial.println("Suhu :");// The SMS text you want to send
delay(100);
mySerial.println(data);delay(100);
mySerial.println("*C");
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void SendMessageBaik()
{
float gas = mq7.getPPM();
float celcius_1 = dht.readTemperature();
float data = celcius_1 - 7;
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"+6282288148871\"\r"); // Replace x with mobile
number
delay(1000);
mySerial.println("Gas CO dalam STATUS BAIK");// The SMS text you want to
send
delay(100);
mySerial.println(gas);delay(100);
mySerial.println("ppm");
mySerial.println("Suhu :");// The SMS text you want to send
delay(100);
mySerial.println(data);delay(100);
mySerial.println("*C");
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}