Sistem Kendali Pengontrolan Listrik Secara Digital Pada Rumah Sederhana

Alat : Arduino Uno
Market Plan StereoFoam
LED
Female Jumper
Kabel Serabut
Resistor
LDR

// SCRIPT ARDUINO
byte byteRead;

int ledkamar1 = 10;
int ledkamar2 = 11;
int ledrtamu = 12;
int leddapur = 13;
int ledtaman = 5;
int ledsuhu = 6;
int buzzer = 7;
int sensorldr1 = A0; //input analog
int sensorldr2 = A1; //input analog
int  tempPin= A3; //input analog
float temp;
int suhu_aktif = 0;
int ldr_aktif = 0;

void setup()
{
Serial.begin(9600);
pinMode (sensorldr1, INPUT);
pinMode (sensorldr2, INPUT);
pinMode (tempPin, INPUT);
pinMode (ledkamar1, OUTPUT);
pinMode (ledkamar2, OUTPUT);
pinMode (ledrtamu, OUTPUT);
pinMode (leddapur, OUTPUT);
pinMode (ledtaman, OUTPUT);
pinMode (ledsuhu, OUTPUT);
pinMode (buzzer, OUTPUT);
}

void loop() {
if(suhu_aktif == 1)
{
check_suhu();
}
else
{
check_suhu_nonaktif();
}
if(ldr_aktif == 1)
{
led_taman(1);
}
else
{
led_taman(2);
}

if (Serial.available()) {
byteRead = Serial.read();
switch (byteRead)
{
case ‘1’:
ldr_aktif = 1;
Serial.println(“LDR Aktif”);
break;
case ‘q’:
ldr_aktif = 0;
Serial.println(“LDR Non Aktif”);
break;
case ‘u’:
led_kamar(1);
break;
case ‘p’:
led_kamar(2);
break;
case ‘i’:
led_kamar(3);
break;
case ‘n’:
led_kamar(4);
break;
case ‘l’:
led_tamu(1);
break;
case ‘o’:
led_tamu(0);
break;
case ‘h’:
led_dapur(1);
break;
case ‘m’:
led_dapur(0);
break;
case ‘j’:
Serial.println(“==================”);
led_kamar(1);
led_kamar(3);
led_tamu(1);
led_dapur(1);
break;
case ‘k’:
Serial.println(“==================”);
led_kamar(2);
led_kamar(4);
led_tamu(0);
led_dapur(0);
break;
case ‘a’:
check_suhu_aktif();
break;
case ‘b’:
buzer_ledsuhu_off();
check_suhu_nonaktif();
break;
}
}
}
void check_suhu_aktif()
{
suhu_aktif = 1;
}
void check_suhu_nonaktif()
{
suhu_aktif = 0;
}

void buzer_ledsuhu_off()
{
digitalWrite(ledsuhu, LOW);
digitalWrite(buzzer, LOW);
Serial.println(“buzer_ledsuhu_off”);
}
void led_dapur(int led)
{
if(led == 1)
{
digitalWrite(leddapur, HIGH);
Serial.println(“LED DAPUR NYALA”);
}
if(led == 0)
{
digitalWrite(leddapur, LOW);
Serial.println(“LED DAPUR PADAM”);
}
}
void led_tamu(int led1)
{
if(led1 == 1)
{
digitalWrite(ledrtamu, HIGH);
Serial.println(“LED TAMU NYALA”);
}
if(led1 == 0)
{
digitalWrite(ledrtamu, LOW);
Serial.println(“LED TAMU PADAM”);
}
}
void led_kamar(int idx)
{
if(idx == 1)
{
digitalWrite(ledkamar1, HIGH); // Program Opay
Serial.println(“LED KAMAR NYATLA”);
}
if(idx == 2)
{
digitalWrite(ledkamar1, LOW);
Serial.println(“LED KAMAR PADAM”);
}
if(idx == 3)
{
digitalWrite(ledkamar2, HIGH);
Serial.println(“LED KAMAR 2 NYALA”);
}
if(idx == 4)
{
digitalWrite(ledkamar2, LOW);
Serial.println(“LED KAMAR 2 PADAM”);
}
}
void led_taman(int idx)
{
if(idx == 1 )
{
int nilai = analogRead(sensorldr1);
Serial.print(“data ldr :”);
Serial.println(nilai);
if(nilai>=600){
digitalWrite(ledtaman, HIGH);
}
else
{
digitalWrite(ledtaman, LOW);
}
}
if(idx == 2)
{
digitalWrite(ledtaman, LOW);
}
}
void check_suhu()
{

temp = analogRead (tempPin); // Program Moehardi
temp = temp * 0.48828125; //(5V * 100C)/1024
Serial.print(“TEMPERATURE = “);
Serial.print(temp);
Serial.print(“*C”);
Serial.println();
if(temp>=30)
{
digitalWrite(ledsuhu, HIGH);
digitalWrite(buzzer, HIGH);
delay(100);
}
else
{
digitalWrite(ledsuhu, LOW);
digitalWrite(buzzer, LOW);
}
}

// SERIAL CPP

// WEB TEMPLATE

 

// PERSENTASI TUGAS

 

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s