0% found this document useful (0 votes)
10 views

#Include LiquidCrystal I2C.h

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

#Include LiquidCrystal I2C.h

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

#include <LiquidCrystal_I2C.

h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // for 4x20 LCD
#include <PZEM004Tv30.h>

// Initialization for PZEM sensors


PZEM004Tv30 pzem(9, 8); // Pin 9 (Tx) and 8 (Rx)
PZEM004Tv30 pzem2(4, 5); // Pin 4 (Tx) and 5 (Rx)

// Variables for sensor readings


float Voltage, Voltage2, Voltage3;
int tegangan1, tegangan2;
float Vmodul_a, Vin_INV;
float Vmodul_b, Vbat;
float R1 = 30001;
float R2 = 7501

// Relay pins
const int relay1 = 6; // PV
const int relay2 = 7; // Neutral PV
const int relay3 = A1; // Grid
const int relay4 = A3; // Neutral Grid

// Voltage and relay status variables


int Vpln;
bool isSlide1 = true;

unsigned long previousMillisLcd = 0;


const unsigned long lcdInterval = 2000;

void setup() {
// Serial communication setup
Serial.begin(9600);

// LCD initialization
lcd.init();
lcd.backlight();
lcd.setCursor(2, 0);
lcd.print("WELCOME TO SYSTEM");
lcd.setCursor(5, 1);
lcd.print("ATS E-BIKE");
lcd.setCursor(2, 2);
lcd.print("CHARGING STATION");
delay(500);
lcd.clear();
delay(500);
lcd.setCursor(9, 0);
lcd.print("BY");
lcd.setCursor(2, 1);
lcd.print("MR. TOKEK RACUN");
lcd.setCursor(1, 2);
lcd.print("MR. TEMPE GOSONG");
lcd.setCursor(3, 3);
lcd.print("MRS TERONG");
delay(500);
lcd.clear();
delay(500);

// Relay setup
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);

digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
digitalWrite(relay4, LOW);
}

void loop() {
unsigned long currentMillis = millis();

// Display slide on LCD


if (currentMillis - previousMillisLcd >= lcdInterval) {
previousMillisLcd = currentMillis;
showSlide();
}

Voltage = pzem.voltage();
Voltage2 = pzem2.voltage();
// Read DC voltage
tegangan1 = analogRead(A0);
Vmodul_a = (tegangan1 * 5.0) / 1024.0;
Vin_INV = Vmodul_a / (R2 / (R1 + R2));

// Algorithm for ATS


static unsigned long previousMillisRelay = 0;
const unsigned long relayInterval = 1000;

// Check conditions and control relays accordingly


if (Vin_INV >= 11.2 && Vin_INV <= 15 && currentMillis - previousMillisRelay >= relayInterval) {
if (Vpln >= 205 && Vpln <= 231) {
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, LOW);
digitalWrite(relay4, LOW);
} else {
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, LOW);
digitalWrite(relay4, LOW);
}
} else if ((Vin_INV <= 11.2 || Vin_INV >= 15) && currentMillis - previousMillisRelay >=
relayInterval) {
if (Vpln >= 205 && Vpln <= 231) {
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
} else {
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
}
} else {
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
digitalWrite(relay4, LOW);
}
}
void showSlide() {
lcd.clear();
// Display slides on LC
if (isSlide1) {
lcd.setCursor(0, 1)
lcd.setCursor(4, 2);
lcd.print("INVERTER ON");
lcd.setCursor(3, 3);
lcd.print("(SYSTEM SAFE)");
isSlide1 = false;
} else {
lcd.setCursor(4, 2);
lcd.print("INVERTER OFF");
lcd.setCursor(6, 3);
lcd.print("(GRID!)");
isSlide1 = true;
}
}

You might also like