// Nama : Abdul Salim
// Sekolah : SMKN 1 Gunung Tuleh
// Pada tugas akhir ini jika suhu dibawah 30 lampu hidup, antara 30-70 kedip kedip dan di atas 70 lampu mati
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#define DHTPIN 8
#define DHTTYPE DHT22
DHT dht (DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Relay
/*
1. Connect LED anode to Relay dengan digital pin (pin 13)
2. Connect LED catode to resiston (200-ohm) and the to the ground (GND) of the Arduino board.
3. Connect one leg of the push button to the digital pin (pin 2).
4. Connect the other leg of the push button to the ground (GND) of the Arduino board.
*/
// Define variables
int PinRelay = 13; // Digital pin relay
int buttonPin = 2; // Digital pin where the button is connected.
bool buttonState = true;
// END relay
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Sistem Monitoring Suhu");
lcd.begin(16, 2);
dht.begin();
// Relay
pinMode(PinRelay, OUTPUT); // LED pin as an output.
pinMode(buttonPin, INPUT); // Button pin as an input.
//END Relay
}
void loop() {
// put your main code here, to run repeatedly:
float t = dht.readTemperature();
float h = dht.readHumidity();
delay(1000);
//Menampilkan di LCD
lcd.setCursor(0,0);
lcd.println("Suhu=");
lcd.print(t);
lcd.println(" C");
lcd.setCursor(0,1);
lcd.println("Lembab=");
lcd.print(h);
lcd.println(" %");
//Menampilkan di serial monitor
Serial.println("Suhu = ");
Serial.print(t);
Serial.println(" C");
Serial.println("Kelembaban = ");
Serial.print(h);
Serial.println(" %");
//Relay
// Read the state of the button
buttonState = digitalRead(buttonPin);
// Suhu kecil 30 lampu hmenyala terus
if (t<30){
digitalWrite(PinRelay, HIGH); // Turn LED Hidup
}
// END Suhu kecil 30 lampu menyala terus
//Lampu Kedap-kedip jika suhu antara 30-70
if (t<=31 && t>=70) {
digitalWrite(PinRelay, LOW); // LED Hidup
delay(1000); // Tunggu 1000ms
digitalWrite(PinRelay, LOW); // LED mati
delay(1000); // Tunggu 1000ms
}
//END Lampu Kedap-kedip jika suhu antara 30-70
if (t<70){
digitalWrite(PinRelay, HIGH); // Turn LED Mati
}
//END Relay
}