Folks, it has gotten to that time where I need help, please. I have tried over and again and can't get it right.
Long story when short, I have an Earth Leakage that's too sensitive to lighting - hooked up a solenoid to reset it (Which I do manually with a battery on a long 2-core cable from my room.
I need to put some brains behind this solenoid for when I'm out of the house in the fear that my gates battery runs flat and I get stuck outside.
Right so, on to the code. Everything works fine on tinkercad.com, I'm only struggling with an "auto-reset timer" If the Earth Leakage is still misbehaving and I'm not there to intervene.
Herewith is my code which I've done my best to explain with //
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(6, 5, 4, 3, 2, 1);
const int CURRENTRELAY=7; //Power control to Solenoid
const int POLRELAY1=8; //Polarity changer A
const int POLRELAY2=9; //Polarity changer B
const int ERRORSIG=13; //Signal Earth Leakage Error
const int POWER=12; //Eskom line input
//Key connections with Arduino
const int up_key=10; //Activate the EL Tool
const int down_key=11; //Deactivate the EL Tool
int SetPoint=0; //Up/Down key status
int SetPoint2=0; //Eskom Line input status
int SetPoint3=0; //Solenoid Counter
//=================================================================
// SETUP
//=================================================================
void setup(){
pinMode(CURRENTRELAY,OUTPUT);
pinMode(POLRELAY1,OUTPUT);
pinMode(POLRELAY2,OUTPUT);
pinMode(ERRORSIG,OUTPUT);
pinMode(up_key,INPUT);
pinMode(down_key,INPUT);
//Pull up for setpoint keys
digitalWrite(up_key,HIGH);
digitalWrite(down_key,HIGH);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("E/L RESET TOOL");
lcd.setCursor(0,1); //Move cursor to second Line
lcd.print("VER 1.0");
//lcd.clear();
//digitalWrite(CURRENTRELAY,LOW); //Green LED Off
//digitalWrite(POLRELAY1,LOW); //Red LED On
//digitalWrite(POLRELAY2,LOW); //Turn off Relay
delay(3000);
}
//=================================================================
// LOOP
//=================================================================
void loop(){
//Get user input for setpoints
if(digitalRead(down_key)==LOW)
{
if(SetPoint>0)
{
SetPoint--;
}
}
if(digitalRead(up_key)==LOW)
{
if(SetPoint<1)
{
SetPoint++;
}
}
//MAIN Control
if(SetPoint3>=6 && SetPoint==1) //If EarthLeakage has been reset 6 times then shut down
{
digitalWrite(CURRENTRELAY,LOW); //Turn off solenoid
digitalWrite(POLRELAY1,LOW); //Turn Polarity changer A off
digitalWrite(POLRELAY2,LOW); //Turn Polarity changer B off
digitalWrite(ERRORSIG,HIGH); //Turn Alarm output on
lcd.setCursor(0,0);
lcd.print("ERROR FAIL ERROR"); //Print message on screen
}
//==========================================================================
//Here is my problem - I though I had it a couple times but it either freezes or does nothing
//If I am not home and its been 1hr I want the arduino to reset and try execute the solenoid
//operation again and repeat:
/*
else if(SetPoint3==6 && SetPoint2==0 && SetPoint==1)
{
delay(10000);
SetPoint3*=0;
digitalWrite(ERRORSIG,LOW);
}
*/
//Also if I so happen to be sleeping, EL trips and cant reset - this counter must do its thing
//but if I wake up and come toggle the system on/off I must be able to override the countdown
//and have the code reset to be ready for the next trip
//ditto if I'm away it must do its thing and carry on without intervention
//============================================================================================
if(SetPoint3>=1 && SetPoint==0) //If the solenoid counter is maxed and I toggle the system off/on it resets
{
SetPoint3*=0;
digitalWrite(ERRORSIG,LOW);
}
else
{
if(SetPoint3<6 && SetPoint==1 || SetPoint3<6 && SetPoint==0)
{
//Display Set point on LCD
lcd.setCursor(0,1);
lcd.print("SYSTEM:");
if(SetPoint==1)
{
lcd.print(" ON");
}
if(SetPoint==0)
{
lcd.print(" OFF");
}
if(digitalRead(POWER)==LOW) //Check if EarthLeakage has tripped
{
if(SetPoint2>0)
{
SetPoint2--;
}
lcd.setCursor(0,0);
lcd.print("POWER: ");
lcd.print("FAIL ");
lcd.print(SetPoint3); //Display Solenoid Counter
}
if(digitalRead(POWER)==HIGH) //Check if EarthLeakage has tripped
{
if(SetPoint2<1)
{
SetPoint2++;
}
lcd.setCursor(0,0);
lcd.print("POWER: ");
lcd.print("ACTIVE ");
lcd.print(SetPoint3); //Display Solenoid Counter
}
//Check if Power is on or off
if(SetPoint2 > SetPoint)
{
digitalWrite(CURRENTRELAY,LOW); //Turn off solenoid
digitalWrite(POLRELAY1,LOW); //Turn Polarity changer A off
digitalWrite(POLRELAY2,LOW); //Turn Polarity changer B off
}
//If Power is off then do the following
if(SetPoint2 < SetPoint)
{
SetPoint3++;
digitalWrite(CURRENTRELAY,HIGH); //Turn on solenoid to pull
delay(500);
digitalWrite(CURRENTRELAY,LOW); //Turn off solenoid to release
delay(500);
digitalWrite(POLRELAY1,HIGH); //Switch Polarity A +>-
digitalWrite(POLRELAY2,HIGH); //Switch Polarity B ->+
delay(500);
digitalWrite(CURRENTRELAY,HIGH); //Turn on solenoid to push
delay(500);
digitalWrite(CURRENTRELAY,LOW); //Turn off solenoid to release
digitalWrite(POLRELAY1,LOW); //Turn Polarity changer A off
digitalWrite(POLRELAY2,LOW); //Turn Polarity changer B off
delay(500);
}
}
}
}
I would absolutely love to do something like
else if(SetPoint3>1 && SetPoint2==0 && SetPoint==1 for>3600sec)
{
SetPoint3*=0;
digitalWrite(ERRORSIG,LOW);
}
But I'm very certain I just typed BS and have no clue how to remedy it.