//#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
LiquidCrystal_I2C lcd(0x27,20,4); //LiquidCrystal_I2C lcd(0x20,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display or 20 chars and 4 line display
//#include <LiquidCrystal.h>
//LiquidCrystal lcd(3,4,5,6,7,8);
//int chk;
#define up 12
#define down 11
#define res 10
#define Clear 5
#define FAN 9
#define batt 8
#define AC A3
#define Temp A2
#define load1 6
#define load2 7
#define DHTPIN 2
#define DHTTYPE DHT22
#define PIRPIN 3
DHT dht(DHTPIN, DHT22);
int ldrPin = A0; // LDR pin
int ldrVal = 0;
int temparature = 0;
int humidity = 0;
float temp = 0;
float arus = 0;
int illumination = 0;
int drive = 13;
int input = 0;
int downsel = 0;
int hum;
int suhu;
float voltage = 0;
float resistance = 0;
int lux = 0;
int pirState = LOW;
int val = 0;
byte Simbol_derajat = B11011111;
const float GAMMA = 0.7;
const float RL10 = 50;
void setup() {
Serial.begin(9600); // Initialise the serial monitor
lcd.init(); // initialize the lcd
lcd.backlight();
pinMode(2, OUTPUT);
dht.begin();
//lcd.begin(20,4);
pinMode(up,INPUT_PULLUP);
pinMode(down,INPUT_PULLUP);
pinMode(res,INPUT_PULLUP);
pinMode(Clear,INPUT_PULLUP);
pinMode(FAN,OUTPUT);
pinMode(batt,INPUT);
pinMode(AC,INPUT);
pinMode(load1,OUTPUT);
pinMode(load2,OUTPUT);
pinMode(Temp,INPUT);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
pinMode(drive, OUTPUT);
pinMode(PIRPIN, INPUT);
// pinMode(led,OUTPUT);
welcome();
//lcd.setCursor(0, 0);
// lcd.write(byte(0)); // when calling lcd.write() '0' must be cast as a byte
// lcd.setCursor(0,1);
// lcd.write(1);
// lcd.setCursor(0,2);
// lcd.write(2);
// lcd.setCursor(0,3);
// lcd.write(3);
// lcd.setCursor(1,0);
//lcd.write(4);
// lcd.setCursor(1,1);
// lcd.write(5);
}
void welcome(){
lcd.setCursor(5,0);
lcd.print("WELCOME TO ");
lcd.setCursor(5,1);
lcd.print("PT.ADMS-TECH ");
lcd.setCursor(3,2);
lcd.print("Electrical and ");
lcd.setCursor(0,3);
lcd.print("Electronics Services");
digitalWrite(13, HIGH);
delay(1000);
lcd.clear();
}
void home(){
temperature1();
humidity1();
illumination1();
}
void temperature1(){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("STATUS WEATHER TODAY");
lcd.setCursor(0,1); //formula using for perform action power
lcd.print("TEMPERATURE : C");
lcd.setCursor(15,1);
lcd.print(suhu);
lcd.setCursor(18,1);
lcd.write(Simbol_derajat);
}
void humidity1(){ //formula using for perform action power
lcd.setCursor(0,2);
lcd.print("HUMIDITY : %");
lcd.setCursor(15,2);
lcd.print(hum);
//lcd.setCursor(18,2);
//lcd.write(Simbol_derajat);
}
void illumination1(){
lcd.setCursor(0,3); //formula using for perform action power
lcd.print("LUMANATION : LX");
lcd.setCursor(15,3);
lcd.print(lux);
}
void temps(){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("TEMP Status");
lcd.setCursor(0,1);//formula using for perform action power
lcd.print("TEMP 1: C");
//
lcd.setCursor(7,1);
lcd.print(temp);
lcd.setCursor(0,2); //formula using for perform action power
lcd.print("TEMP 2: C");
lcd.setCursor(7,2);
lcd.print(temp);
//
lcd.setCursor(0,3); //formula using for perform action power
lcd.print("TEMP 3: C");
lcd.setCursor(7,3);
lcd.print(temp);
delay(150);
}
void arusflow(){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("ARUS Status");
lcd.setCursor(0,1); //formula using for perform action power
lcd.print("ARUS 1: A");
lcd.setCursor(7,1);
lcd.print(arus);
//
lcd.setCursor(0,2); //formula using for perform action power
lcd.print("ARUS 2: A");
lcd.setCursor(7,2);
lcd.print(arus);
//
lcd.setCursor(0,3); //formula using for perform action power
lcd.print("ARUS 3: A");
lcd.setCursor(7,3);
lcd.print(arus);
delay(150);
}
void voltages(){
lcd.clear();
lcd.setCursor(2,0);
lcd.print("AC VOLTAGE Status");
lcd.setCursor(0,1);
lcd.print("Voltage:");
lcd.setCursor(11,1);
lcd.print("V");
//
lcd.setCursor(0,2);
lcd.print("Current:");
lcd.setCursor(11,2);
lcd.print("A");
//
lcd.setCursor(0,3);
lcd.print("Wattage:");
lcd.setCursor(11,3);
lcd.print("W");
delay(150);
}
void loads(){
lcd.clear();
lcd.setCursor(5,0);
lcd.print("LOAD Status");
lcd.setCursor(0,1);
lcd.print("LOAD1:");
//
lcd.setCursor(0,2);
lcd.print("LOAD2:");
//
lcd.setCursor(0,3);
lcd.print("LOAD3:");
delay(150);
}
void bgProses(){
hum = dht.readHumidity();
suhu = dht.readTemperature();
//input = analogRead(A0); //analogRead function is used to recive analog data Power
//dht22 = (input * 40.0) / 1024.0;
//input = analogRead(A1); //analogRead function is used to recive analog data Power
//reflected = (input * 5.0) / 1024.0;
ldrVal = analogRead(ldrPin); // Read the analog value of the LDR
voltage = ldrVal / 1024. * 5;
resistance = 2000 * voltage / (1 - voltage / 5);
lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
//Serial.println(lux);
val = digitalRead(PIRPIN); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(drive, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(drive, LOW); // turn LED OFF
if (pirState == HIGH) {
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
/*input = analogRead(A2); //analogRead function is used to recive analog data Power
temp = (input * 5.0) / 1024.0;
input = analogRead(A2); //analogRead function is used to recive analog data Power
temp = (input * 20.0) / 1024.0;
input = analogRead(A2); //analogRead function is used to recive analog data Power
temp = (input * 5.0) / 1024.0;
input = analogRead(A3); //analogRead function is used to recive analog data Power
arus = (input * 50.0) / 1024.0;
input = analogRead(A3); //analogRead function is used to recive analog data Power
arus = (input * 50.0) / 1024.0;
input = analogRead(A3); //analogRead function is used to recive analog data Power
arus = (input * 50.0) / 1024.0; */
}
// TAMPILAN MENU HOME STATUS SYSTEM
void status(){
lcd.clear();
switch(downsel){
case 0:
home();
bgProses();
delay(500);
break;
case 1:
temps();
bgProses();
delay(500);
break;
case 2:
arusflow();
bgProses();
delay(500);
break;
case 3:
voltages();
bgProses();
delay(500);
break;
case 4:
loads();
bgProses();
delay(500);
break;
}
if(digitalRead(down) == LOW){
downsel++;
if(downsel > 4){
downsel = 0;
}
delay(200);
}
if(digitalRead(up)== LOW){
downsel--;
if(downsel < 0){
downsel = 4;
}
delay(200);
}
delay(100);
}
// PEMPROSESAN PROGRAM SYSTEM
// diskripsi [ jika refledted lebih besar dari 20 maka pin 13 high dan print high reflected]
// diskripsi [ jika rf in lebih besar dari 20 maka pin 13 high dan print over drive]
// diskripsi [ jika temperatur lebih besar dari 40 maka pin 13 high dan print high temperatur]
// diskripsi [ jika arus lebih besar dari 30 maka pin 13 high dan print high arus]
// diskripsi [ jika semua status dibawah nilai maka system kemali ke normal {void loop di status saja}]
void kelembapan(){
digitalWrite(13, LOW);
while(hum > 50){
digitalWrite(13,HIGH);
lcd.clear();
lcd.setCursor(2,1);
lcd.print("PENYIRAMAN TAMAN");
lcd.setCursor(7,2);
lcd.print("AKTIF");
delay(150);
bgProses();
if(hum < 50){
digitalWrite(13, LOW);
return 0;
}
}
}
void cahaya(){
digitalWrite(13, LOW);
while(lux < 50){
digitalWrite(13,HIGH);
//lcd.clear();
lcd.setCursor(4,1);
lcd.print("LAMPU TAMAN");
lcd.setCursor(7,2);
lcd.print("AKTIF");
delay(150);
bgProses();
if(illumination > 60){
digitalWrite(13, LOW);
return 0;
}
}
}
void loop() {
status();
kelembapan();
cahaya();
}