Hello everyone, i need some help to modify my 'ev charger project' arduino code.
Let me explain the duty of my code.
I have relay card in my circuit. When i enter the correct password, relay will be triggered, charge module will work and charge module will need to work until i enter the password again to stop it. If i enter password again it should stop charging. I mean set the relay state non triggered and hold like this until i enter password again.
Everything is working fine in my code, when i enter the password relay is triggered and charging is activated but it is not holding like this. when the enter password screen shows up it is like refreshing i mean the code behaves like not holding like i want, you can think like my code is opening door when i enter pass and closing automatically.
What i want is like that; open the door when i enter pass, stay opened, if i enter again the pass, close after i enter the password again and stay closed.
I hope i mentioned what i want exactly, I am not so familiar to explain these type of things in english.
If u want me to explain more or if u have questions please feel free to ask.
Thanks in advance.
code;
#include <Keypad.h>
#include<EEPROM.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
char password[4];
char initial_password[4],new_password[4];
int i=0;
int relay_pin = 11;
char key_pressed=0;
const byte rows = 4;
const byte columns = 4;
char hexaKeys[rows][columns] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte row_pins[rows]={7, 8, 9, 10};
byte column_pins[columns]={3, 4, 5, 6};
Keypad keypad_key=Keypad( makeKeymap(hexaKeys),row_pins,column_pins,rows,columns);
void setup(){
lcd.init();
lcd.backlight();
pinMode(relay_pin, OUTPUT);
digitalWrite(11, HIGH);
lcd.setCursor(5,0);
lcd.print("B & F");
lcd.setCursor(2,1);
lcd.print("ELECTRONICS");
delay(5000);
lcd.clear();
lcd.setCursor(4,0);
lcd.print("WELCOME");
delay(3000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("ELECTRIC VEHICLE");
lcd.setCursor(0,1);
lcd.print("CHARGING STATION");
delay(3000);
lcd.clear();
lcd.setCursor(1,0);
lcd.print("PLEASE CONNECT");
lcd.setCursor(1,1);
lcd.print("CHARGING CABLE");
delay(3000);
lcd.clear();
lcd.setCursor(4,0);
lcd.print("TO YOUR");
lcd.setCursor(0,1);
lcd.print("ELECTRIC VEHICLE");
delay(3000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("AFTER CONNECTION");
lcd.setCursor(0,1);
lcd.print("ENTER YOUR PIN");
delay(3000);
lcd.clear();
lcd.print(" Enter Password");
lcd.setCursor(6,1);
initialpassword();
}
void loop(){
digitalWrite(relay_pin,HIGH);
key_pressed = keypad_key.getKey();
if(key_pressed=='#')
change();
if (key_pressed)
{
password[i++]=key_pressed;
lcd.print('*');
}
if(i==4)
{
delay(200);
for(int j=0;j<4;j++)
initial_password[j]=EEPROM.read(j);
if(!(strncmp(password, initial_password,4))){
lcd.clear();
lcd.setCursor(2,0);
lcd.print("PASSWORD IS");
lcd.setCursor(4,1);
lcd.print("CORRECT");
digitalWrite(relay_pin,LOW);
delay(8000);
lcd.setCursor(0,0);
lcd.print("to set new pin");
lcd.setCursor(0,1);
lcd.print("Press >#< button");
delay(5000);
lcd.clear();
lcd.print(" Enter Password");
lcd.setCursor(0,1);
i=0;
}
else{
digitalWrite(relay_pin, HIGH);
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Wrong Password");
lcd.setCursor(3,1);
lcd.print("Try Again");
delay(2000);
lcd.setCursor(0,0);
lcd.print("Press >#< button");
lcd.setCursor(0,1);
lcd.print("to set new pin");
delay(2000);
lcd.clear();
lcd.print(" Enter Password");
lcd.setCursor(0,1);
i=0;
}}}
void change(){
int j=0;
lcd.clear();
lcd.print("Current Password");
lcd.setCursor(0,1);
while(j<4){
char key=keypad_key.getKey();
if(key)
{
new_password[j++]=key;
lcd.print(key);
}
key=0;}
delay(500);
if((strncmp(new_password, initial_password, 4))){
lcd.clear();
lcd.print("Wrong Password");
lcd.setCursor(0,1);
lcd.print("Try Again");
delay(1000);}
else{
j=0;
lcd.clear();
lcd.print("New Password");
lcd.setCursor(0,1);
while(j<4){
char key=keypad_key.getKey();
if(key)
{
initial_password[j]=key;
lcd.print(key);
EEPROM.write(j,key);
j++;}}
lcd.print("PIN is Changed");
delay(1000);}
lcd.clear();
lcd.print(" Enter Password");
lcd.setCursor(0,1);
key_pressed=0;
}
void initialpassword(){
int j;
for(j=0;j<4;j++)
EEPROM.write(j,j+49);
for(j=0;j<4;j++)
initial_password[j]=EEPROM.read(j);}