View Single Post
Old 01-11-2010, 03:24 PM   #113 (permalink)
Daox
Administrator
 
Daox's Avatar
 
Join Date: Dec 2007
Location: Germantown, WI
Posts: 11,203

CM400E - '81 Honda CM400E
90 day: 51.49 mpg (US)

Daox's Grey Prius - '04 Toyota Prius
Team Toyota
90 day: 49.53 mpg (US)

Daox's Insight - '00 Honda Insight
90 day: 64.33 mpg (US)

Swarthy - '14 Mitsubishi Mirage DE
Mitsubishi
90 day: 56.69 mpg (US)

Daox's Volt - '13 Chevrolet Volt
Thanks: 2,501
Thanked 2,586 Times in 1,554 Posts
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...
__________________
Current project: A better alternator delete
  Reply With Quote
The Following 2 Users Say Thank You to Daox For This Useful Post:
dave77 (01-11-2010), lacertus (04-14-2011)