Вы находитесь на странице: 1из 11

Lampiran Program

#include <LiquidCrystal.h>

#define relay 11

#define pb_open 12

#define pb_close 13

#define buzzer 10

#define led1 9

#define led2 8

#define sensitivitas1 66 //30A=66

#define sensitivitas2 185 //5A=185

#define batas_baca 3

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

float tegangan1 = 0;

float tegangan2 = 0;

float teganganRMS1 = 0;

float teganganRMS2 = 0;

float arus1 = 0;

float arus2 = 0;

int jg = 0;

float batasArus=2;

float batasArusGnd=0.5;

char outstr[15];

int maxValue[2] = {0,0}; // store max value here

int minValue[2] = {1024,1024}; // store min value here

int subtract1=0;
int subtract2=0;

float kalibrasi1 = 1.03;//0.95;

float kalibrasi2 = 1;//1.06

unsigned char data_pertama=0;

void setup()

pinMode(relay, OUTPUT);

pinMode(buzzer, OUTPUT);

pinMode(led1, OUTPUT);

pinMode(led2, OUTPUT);

pinMode(relay, OUTPUT);

pinMode(pb_open, INPUT);

pinMode(pb_close, INPUT);

digitalWrite(relay,HIGH);

lcd.begin(16, 2);

lcd.setCursor(0,0);

lcd.print("PROTOTYPE");

lcd.setCursor(0,1);

lcd.print("RECLOSER");

delay(3000);

lcd.clear();

}
void loop()

bacaTombol();

bacaArus();

if(arus1 > batasArus && arus2 > batasArusGnd)

if (data_pertama < batas_baca){data_pertama++;}

else if(data_pertama>=batas_baca)

data_pertama = 0;

tampilArus1();

tampilArus2();

digitalWrite(relay,LOW);

digitalWrite(led1,HIGH);

digitalWrite(led2,HIGH);

jg++;

tampilJG();

if(jg>=3)

delay(1000);

digitalWrite(led1,HIGH);

digitalWrite(led2,HIGH);

tampilTripPermanen();

while(1)

{
buzzerOn();

else

delay(3000);

digitalWrite(led1,LOW);

digitalWrite(led2,LOW);

digitalWrite(relay,HIGH);

else if(arus1 > batasArus && arus2 <= batasArusGnd)

if (data_pertama < batas_baca){data_pertama++;}

else if(data_pertama>=batas_baca)

data_pertama = 0;

tampilArus1();

tampilArus2();

digitalWrite(relay,LOW);

digitalWrite(led1,HIGH);

digitalWrite(led2,LOW);

jg++;

tampilJG();

if(jg>=3)
{

delay(3000);

digitalWrite(led1,HIGH);

tampilTripPermanen();

while(1)

buzzerOn();

else

delay(3000);

digitalWrite(led1,LOW);

digitalWrite(relay,HIGH);

else if(arus1 <= batasArus && arus2 > batasArusGnd)

if (data_pertama < batas_baca){data_pertama++;}

else if(data_pertama>=batas_baca)

data_pertama = 0;

tampilArus1();

tampilArus2();

digitalWrite(relay,LOW);
digitalWrite(led1,LOW);

digitalWrite(led2,HIGH);

jg++;

tampilJG();

if(jg>=3)

delay(3000);

digitalWrite(led2,HIGH);

tampilTripPermanen();

while(1)

buzzerOn();

else

delay(3000);

digitalWrite(led2,LOW);

digitalWrite(relay,HIGH);

else

jg=0;

data_pertama=0;
digitalWrite(relay,HIGH);

digitalWrite(led1,LOW);

digitalWrite(led2,LOW);

tampilArus1();

tampilArus2();

tampilJG();

void buzzerOn()

digitalWrite(buzzer, HIGH);

delay(500);

digitalWrite(buzzer, LOW);

delay(500);

void bacaTombol()

if(digitalRead(pb_open)==LOW)

digitalWrite(relay,LOW);

if(digitalRead(pb_close)==LOW)

digitalWrite(relay,HIGH);
}

void bacaArus()

teganganPP();

teganganRMS1 = (tegangan1/2.0) * 0.707;

teganganRMS1 = teganganRMS1 * kalibrasi1;

arus1 = (teganganRMS1 * 1000)/sensitivitas1;

teganganRMS2 = (tegangan2/2.0) * 0.707;

teganganRMS2 = teganganRMS2 * kalibrasi2;

arus2 = (teganganRMS2 * 1000)/sensitivitas2;

void teganganPP()

int adcValue1, adcValue2; //nilai adc dari sensor

maxValue[0] = 0; //store max value here

maxValue[1] = 0; //store max value here

minValue[0] = 1024; //store min value here

minValue[1] = 1024; //store min value here

uint32_t start_time = millis();

while((millis()-start_time) < 1000) //sample for 1 Sec


{

adcValue1 = analogRead(A0);

adcValue2 = analogRead(A1);

if (adcValue1 > maxValue[0])

maxValue[0] = adcValue1;

if (adcValue1 < minValue[0])

minValue[0] = adcValue1;

if (adcValue2 > maxValue[1])

maxValue[1] = adcValue2;

if (adcValue2 < minValue[1])

minValue[1] = adcValue2;

bacaTombol();

subtract1 = (maxValue[0] - minValue[0]);

subtract2 = (maxValue[1] - minValue[1]);


tegangan1 = (subtract1 * 5.0)/1024.0;

tegangan2 = (subtract2 * 5.0)/1024.0;

void tampilArus1()

dtostrf(arus1,5, 2, outstr);

lcd.setCursor(0,0);

lcd.print("I1:");

lcd.print(outstr);

// dtostrf(teganganRMS1,5, 2, outstr);

// lcd.setCursor(0,0);

// lcd.print("V1:");

// lcd.print(outstr);

void tampilArus2()

//arus2 = abs(arus2 - 0.3);

dtostrf(arus2,4, 2, outstr);

lcd.setCursor(9,0);

lcd.print("I2:");

lcd.print(outstr);
//dtostrf(teganganRMS2,5, 2, outstr);

//lcd.setCursor(9,0);

//lcd.print("V2:");

//lcd.print(outstr);

void tampilJG()

lcd.setCursor(0,1);

lcd.print("Gangguan: ");

lcd.print(jg);

void tampilTripPermanen()

lcd.clear();

lcd.setCursor(0,0);

lcd.print("Trip Permanen");

lcd.setCursor(0,1);

lcd.print("Tekan Reset");