#include <LiquidCrystal.h>
#include "DHT.h" //library sensor yang telah diimportkan
#define DHTPIN 6 //Pin apa yang digunakan
#define DHTTYPE DHT22
#define buzzer 5
#define pirPin 4
#define servo 3
int statusPir = LOW;
int gerakanPir;
#include <Servo.h>
Servo myservo;
int sudut;
int pos = 0;
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd (12, 11, 10 , 9, 8, 7);
void setup() {
myservo.attach(3);
Serial.begin(9600); //baud komunikasi serial
Serial.println("Pengujian DHT11!"); //penulisan di serial monitor
dht.begin(); //prosedur memulai pembacaan module sensor
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(4,0);
lcd.print(" SENSOR ");
lcd.setCursor(4,1);
lcd.print(" SUHU ");
delay(100);
lcd.print(" ");
pinMode(buzzer, OUTPUT);
pinMode(pirPin, INPUT);
}
void loop() {
float suhu = dht.readTemperature();
float f = dht.readTemperature(true);
float t = dht.readTemperature();
float h = dht.readHumidity();
delay(1000);
gerakanPir = digitalRead(pirPin);
if(gerakanPir==HIGH){
tone(buzzer, 10);
delay(500);
if(statusPir==LOW){
Serial.println("Ada Gerakan!!!");
statusPir=HIGH;
}
}
else {
noTone(buzzer);
if(statusPir==HIGH){
Serial.println("Tidak Ada Gerakan!");
statusPir=LOW;
}
if (suhu <=16)
{
lcd.print(" DINGIN ");
}
else if (suhu <=29)
{
lcd.print(" Lembab ");
for (pos = 0; pos <= 100; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 100; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
else if (suhu >=30)
{
lcd.print(" PANAS ");
tone(buzzer, 10);
delay(5000);
noTone(buzzer);
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
//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("Temperature = ");
Serial.print(t);
Serial.println(" C");
Serial.println("Humadity = ");
Serial.print(h);
Serial.println(" %");
}
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
dht1:VCC
dht1:SDA
dht1:NC
dht1:GND
lcd1:VSS
lcd1:VDD
lcd1:V0
lcd1:RS
lcd1:RW
lcd1:E
lcd1:D0
lcd1:D1
lcd1:D2
lcd1:D3
lcd1:D4
lcd1:D5
lcd1:D6
lcd1:D7
lcd1:A
lcd1:K
r1:1
r1:2
bz1:1
bz1:2
pir1:VCC
pir1:OUT
pir1:GND
servo1:GND
servo1:V+
servo1:PWM