int period = 500; // ok d perbaiki
unsigned long time_now = 0;
int period1 = 500;
#include <avr/wdt.h>
int buttonPin = 8; // kiri depan ( minta -) 2
int buttonPin1 = 9; // kanan depan ( minta -)3
int buttonPin2 = 10; // kiri blkng (monta -)4
int buttonPin3 = 11; // kanan blkng!(minta -)5
int buttonPin4 =12;///bagasi) 6
bool buttonState = false;
bool buttonState1 = false;
bool buttonState2 = false;
bool buttonState3 = false;
bool buttonState4 = false;
// PIN LED
byte lampumalam = 3; // minta power (+)7
byte airradiator = 2; // minta power (+)8
byte kipasmobil = 6; // minta power (+)9
// PINLED
byte led = 7; // indikator air radiator(10)
//byte led1 = 4; // indikator pintu open * tidak di gunakan(13)
byte led2 = 5; // indikator kipas radiator(11)
byte led3 = 13; // suhu(12)
int nilai; // air radiator
int nilai1; // lampu malam
int nilai2; // kipas
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int ThermistorPin = A1; // suhu kabin
int ThermistorPin1 = A2; // suhu mesin
int Vo;
float R1 = 10000;
float logR2, R2, T, Tc, Tf;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
const int voltageSensorPin = A0; // sensor pin
float vIn; // measured voltage (3.3V = max. 16.5V, 5V = max 25V)
float vOut;
float voltageSensorVal; // value on pin A3 (0 - 1023)
const float factor = 5.128; // reduction factor of the Voltage Sensor shield
const float vCC = 5.00;
//0
byte suhu[8] = {
B00100,
B01010,
B01010,
B01110,
B01110,
B11111,
B11111,
B01110
};
//1
byte aki[8] ={
B00000,
B00000,
B01010,
B11111,
B10101,
B11111,
B00000,
B00000
};
//2
byte garis[8] = {
B01110,
B11111,
B01110,
B01110,
B01110,
B01110,
B11111,
B01110
};
//3
byte gmiringkanan[8] = {
B00000,
B10000,
B01000,
B00100,
B00010,
B00001,
B00000,
B00000
};
//4
byte luruskanan[8] = {
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
B10000
};
//5
byte luruskiri[8] = {
B00001,
B00001,
B00001,
B00001,
B00001,
B00001,
B00001,
B00001
};
//6
byte gmiringkiri[8] = {
B00000,
B00001,
B00010,
B00100,
B01000,
B10000,
B00000,
B00000
};
//7
byte A[8] = {
B00000,
B01110,
B01010,
B01010,
B01110,
B01010,
B01010,
B00000
};
//8
byte L[8] = {
B00000,
B01000,
B01000,
B01000,
B01000,
B01000,
B01110,
B00000
};
//9
byte Te[8] = {
B00000,
B01110,
B00100,
B00100,
B00100,
B00100,
B00100,
B00000
};
//10
byte lonceng[8] = {
B00100,
B01110,
B01110,
B01110,
B01110,
B11111,
B00100,
B00000
};
//11
byte packmanopen[8]={
B00000,
B00000,
B01110,
B11011,
B11100,
B01110,
B00000,
B00000
};
void setup() {
wdt_disable();
delay(2000);
wdt_enable(WDTO_8S);
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.createChar(0, suhu);
lcd.createChar(1, aki);
lcd.createChar(2,garis);
lcd.createChar(3,gmiringkanan);
lcd.createChar(4,luruskanan);
lcd.createChar(5,luruskiri);
lcd.createChar(6,gmiringkiri);
//lcd.createChar(7,A);
//lcd.createChar(8,L);
//lcd.createChar(9,Te);
//lcd.createChar(10,lonceng);
//lcd.createChar(11,packmanopen);
//pin arduino output
pinMode (led, OUTPUT); // indikator air radiator
//pinMode (led1, OUTPUT); // indikator pintu * tidak di gunakan lampunya
pinMode (led2, OUTPUT); // indikator kipas radiator
pinMode (led3, OUTPUT); // suhu
//pin input
pinMode(A0, INPUT); //volt
pinMode(A1, INPUT);//suhu kabin
pinMode(A2, INPUT);//suhu mesin
pinMode(lampumalam, INPUT);//lampu malam
pinMode(buttonPin, INPUT); // pintu kiri depan
pinMode(buttonPin1, INPUT); // pintu kiri blkng
pinMode(buttonPin2, INPUT); // pintu kanan depan
pinMode(buttonPin3, INPUT); // pintu kanan blkng
pinMode(buttonPin4, INPUT); // bagasi
pinMode (kipasmobil, INPUT); // kipas mobil
pinMode (airradiator, INPUT); // air radiator
digitalWrite(led, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
delay(1000);
digitalWrite(led, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
}
void loop() {
time_now = millis();
wdt_reset();
lcd.setCursor(1,0);
lcd.write(2);
lcd.setCursor(1,1);
lcd.write(2);
lcd.setCursor(4,0);
lcd.write(0);
lcd.setCursor(4,1);
lcd.write(0);
lcd.setCursor(11,0);
lcd.write(1);
//lcd.setCursor(10,1);
//lcd.print(" ALTIS ");
//lcd.print(" ");
//lcd.print((char)152);
//lcd.write(7);
//lcd.write(8);
//lcd.write(9);
//lcd.print("A");
//delay(200);
//lcd.print("L");
//delay(200);
//lcd.print("");
//delay(200);
//lcd.print("T");
//delay(200);
//lcd.print("I");
//delay(200);
//lcd.print("S");
//delay(200);
// pintu kiri depan
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH){
lcd.setCursor(0,0);
lcd.write(5);
delay(1);
}
else{
lcd.setCursor(0,0);
lcd.write(6);
delay(1);
}
// pintu kiri belalang
buttonState1 = digitalRead(buttonPin1);
if(buttonState1 == HIGH){
lcd.setCursor(0,1);
lcd.write(5);
delay(1);
}else{
lcd.setCursor(0,1);
lcd.write(6);
delay(1);
}
// pintu kanan depan
buttonState2 = digitalRead(buttonPin2);
if(buttonState2 == HIGH){
lcd.setCursor(2,0);
lcd.write(4);
delay(1);
}else{
lcd.setCursor(2,0);
lcd.write(3);
delay(1);
}
// pintu kanan belakang
buttonState3 = digitalRead(buttonPin3);
if(buttonState3 == HIGH){
lcd.setCursor(2,1);
lcd.write(4);
delay(1);
}else{
lcd.setCursor(2,1);
lcd.write(3);
delay(1);
}
buttonState4 = digitalRead(buttonPin4);
if(buttonState4 == LOW){
lcd.setCursor(10,1);
lcd.print("BAGASI");
//digitalWrite(led, HIGH);
//digitalWrite(led3, HIGH);
delay(1000);
lcd.setCursor(10,1);
lcd.print("TRBUKA");
//digitalWrite(led, LOW);
// digitalWrite(led3, LOW);
delay(1000);
}
nilai = digitalRead(airradiator);
if(nilai == LOW){
digitalWrite(led,LOW);
}else{
delay(500);
digitalWrite(led, HIGH);
lcd.clear();
//mp3_play(1);
lcd.setCursor(0,0);
lcd.print(" AIR KOSONG!!!!");
//delay(1000);
lcd.setCursor(1,1);
lcd.print("SILAHKAN DI ISI");
delay(1000);
lcd.clear();
}
// suhu kabin
Vo = analogRead(ThermistorPin);
R2 = R1 * (1023.0 / (float)Vo - 1.0);
logR2 = log(R2);
T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
Tc = T - 273.15;
Tf = (Tc * 9.0)/ 5.0 + 32.0;
Serial.print("Temperature: ");
Serial.print(Tc,0);
Serial.println(" C");
lcd.setCursor(5,0);
lcd.print(Tc,0);
lcd.print((char)223);
lcd.print("C");
lcd.print(" ");
delay(1000);
lcd.setCursor(10,1);
lcd.print(" ");
// suhu mesin
Vo = analogRead(ThermistorPin1);
R2 = R1 * (1023.0 / (float)Vo - 1.0);
logR2 = log(R2);
T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
Tc = T - 273.15;
Tf = (Tc * 9.0)/ 5.0 + 32.0;
Serial.print("Temperature1: ");
Serial.print(Tc,0);
Serial.println(" C");
lcd.setCursor(5,1);
lcd.print(Tc,0);
lcd.print((char)223); // derajat
lcd.print("C");
lcd.print(" ");
if(Tc>100){
digitalWrite(led3, HIGH);
//mp3_play(2);
/*lcd.setCursor(10,1);
lcd.print ("!OVER!");
delay(1000);
lcd.setCursor(10,1);
lcd.print("!HEAT!");*/
delay(1000);
lcd.clear();
lcd.setCursor(2,0);
lcd.print("OVER HEAT!!!!");
lcd.setCursor(0,1);
lcd.print("SLAHKN ISTIRAHAT");
delay(1000);
lcd.clear();
}else{
digitalWrite(led3, LOW);
}
// voltase
voltageSensorVal = analogRead(voltageSensorPin); // read the current sensor value (0 - 1023)
vOut = (voltageSensorVal / 1024) * vCC; // convert the value to the real voltage on the analog pin
vIn = vOut * factor; // convert the voltage on the source by multiplying with the factor
Serial.print("Voltage = ");
lcd.setCursor(11,0);
lcd.write(1);
lcd.print(vIn);
nilai2 = digitalRead(kipasmobil);
if(nilai2 == HIGH){
digitalWrite(led2, HIGH);
}else{
digitalWrite(led2, LOW);
}
// lampu malam
nilai1 = digitalRead(lampumalam);
nilai = digitalRead(airradiator);
if(nilai1 == HIGH && nilai == LOW && buttonState == HIGH && buttonState1 == HIGH && buttonState2 == HIGH && buttonState3 == HIGH && buttonState4 == HIGH && Tc<100){
lcd.noBacklight();
lcd.noDisplay();
}else{
lcd.display();
lcd.backlight();
}
lcd.setCursor(10,1);
// lcd.print("ALTIS");
//delay(1000);
//lcd.print(" ");
//lcd.print((char)152);
//lcd.write(7);
//lcd.write(8);
//lcd.write(9);
lcd.print(" A");
delay(100);
lcd.print("L");
delay(100);
lcd.print("T");
delay(100);
lcd.print("I");
delay(100);
lcd.print("S");
delay(100);
lcd.setCursor(10,1);
lcd.print(" ALTIS ");
delay(500);
while(millis() < time_now + period){
}
time_now = millis () ;
//lcd.setCursor(10,1);
//lcd.print(" ");
}