I started and mostly finished the coding for the arduino during lunch today. I added a lot of comments (everything after the //) so hopefully someone other than me can understand how it is operating.
If it is complete gibberish I can type out how it is working.
/*
PHEV Automatic Charger Disconnect
This program monitors a signal from an alarm. Upon
getting a verified signal that the alarm is going off,
the Arduino disconnects power via a relay.
*/
const int AlarmPin = 1; // pin to monitor alarm signal
const int RelayPin = 2; // pin to signal the relay
int AlarmPinStatus = 0; // relays AlarmPin status
boolean RelayPinStatus = true; // RelayPin on/off
boolean AlarmCheck = false; // makes sure alarm goes off before counters can increment again
int AlarmCounter = 0; // counts alarms to verify true/false alarm
unsigned long LastAlarmTime; // time since the last beep
unsigned long ChargerOffTime; // time since the charger was turned off
void setup() {
pinMode(AlarmPin, INPUT);
pinMode(RelayPin, OUTPUT);
digitalWrite(RelayPin, HIGH); // turn relay on
}
void loop() {
AlarmPinStatus = digitalRead(AlarmPin); // read AlarmPin status
if (AlarmPinStatus == HIGH && AlarmCheck == false) { // check for alarm & alarm check
++AlarmCounter; // increment alarm counter
LastAlarmTime = millis(); // set last beep timer
AlarmCheck = true; // prevent AlarmCounter increment until alarm turns off
}
if (AlarmPinStatus == LOW) { // verify alarm is off before counters can increment again
AlarmCheck = false;
}
if (millis() - LastAlarmTime > 20000) { // if it has been more than 20 seconds since the last beep
LastAlarmTime = 0; // reset last beep timer
}
if (AlarmCounter = 15) { // if alarm has gone off 15 times within 20 seconds
AlarmCounter = 0; // reset AlarmCounter
digitalWrite(RelayPin, LOW); // turn charger off
RelayPinStatus = false;
ChargerOffTime = millis(); // set charger off time
}
if (millis() - ChargerOffTime > 3600000 && RelayPinStatus == false) { // wait 60 minutes with charger off
digitalWrite(RelayPin, HIGH); // turn charger back on
RelayPinStatus = true;
}
}
Wow, thats really messy and hard to read on a forum...
|