Hi Guys,
I have written a Dual Battery Controller which i have had working great, I am trying to add a function that will give me a delay (without stopping the whole program ) before the “voltage” output goes high, to stop relay debounce. Once the voltage is over 13.2 v the output goes high. I have tried everything i can think of and find to add this delay prior to output.
Can anyone help me with the following program and point out what i am doing wrong ?
/*CREATED BY CHRIS COBLEY PROJECT REV6, 26,March,2011
This Script has 2 analog inputs ( Volt Meters ).
Displays Dual battery voltage on LCD Display 2x16.
Turns on a Digital output to join Main and Aux Battery together, also lights an LED.
Controls charging and timing curcuit, joining and disconnecting batteries as required.
LCD Connections:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* Red to +5V
* Black to ground
*/
// includes the library code, so LCD diaplay works.
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int ledPin = 9; // Select pin for LED and Relay
int ledPin1 = 8; // Select pin for LED/override
int sensorPin = A1; // Selects Analog input 0 as sensor
int sensorPin1 = A0; // Selects Analog input 1 as sensor
void setup() {
lcd.begin(16, 2); // Sets the number of rows & columns on LCD
pinMode(ledPin, OUTPUT); // Sets LED as an output.
pinMode(ledPin1, OUTPUT); // Sets LED as an output.
}
float voltage = 0; // setup some variables
float voltage1 = 0; // Float variable
float sensor = 0;
float sensor1 = 0;
long delaytime = 10000;
long previousmillis =0;
void loop() { // let's get measurin'
unsigned long currentmillis = millis();
sensor = analogRead(1); // Analog input 0
sensor1 = analogRead(0); // Analog input 1
voltage = (sensor*19.99)/1024; // convert raw sensor value to millivolts
voltage1 = (sensor1*19.99)/1024; // convert raw sensor value to millivolts
// Rev 6 19.53 change to 19.99 for accuracy.
if (voltage >= 13.2 && previousmillis > delaytime) // Sets voltage level that LED and RELAY turns ON.
{
digitalWrite(ledPin, HIGH); // Turns on LED and RELAY
}
if (voltage <= 12.6) // Sets minimum voltage level that LED and RELAY turns ON.
{
digitalWrite(ledPin, LOW); // Turns off LED and RELAY disconnects batteries
}
if (voltage1 <= 5.0) // Sets Safety for Aux Batt (in case not connected)
{
digitalWrite(ledPin, LOW);
}
previousmillis = currentmillis;
lcd.print("MAIN BATT:"); // Prints "Main Batt" on LCD Display
lcd.setCursor(12,0);
lcd.print(voltage,1); // Prints voltage from Sensor 1 (Analog Input 0)
lcd.setCursor(0, 1); // Selects line 2 on LCD Display
lcd.print("AUX BATT:"); // Prints "Aux Batt:" on LCD Display
lcd.setCursor(12,1);
lcd.print(voltage1,1); // Prints voltage from sensor 2 (Analog Input 1)
lcd.setCursor(0, 0); // Resets LCD display for next loop
}
Thank You
Chris