automatic voltage stabilizer

i was trying to build an automatic stabilizer circuit. An the code is here

const byte relaypin1 =3;
const byte relaypin2 =4;
const byte relaypin3 =5;
const byte relaypin4 =6;
boolean temp =0;
int involtage =A0;
const byte ledPin = 13;

volatile byte state = LOW;
void setup() {
Serial.begin(9600);

pinMode (relaypin1,OUTPUT);
pinMode (relaypin2,OUTPUT);
pinMode (relaypin3,OUTPUT);
pinMode (relaypin4,OUTPUT);
pinMode (ledPin,OUTPUT);
pinMode (involtage,INPUT);
}

void loop() {
int involtage = analogRead (A0);
int cutoff =analogRead (A1);

if (cutoff<=99 || cutoff>=1001){
digitalWrite( relaypin4,LOW);
digitalWrite (relaypin3, LOW);
digitalWrite (relaypin2, LOW);
digitalWrite (relaypin1, LOW);
}

if (involtage>=100 && involtage<=250)
{
digitalWrite( relaypin4,HIGH);
digitalWrite (relaypin1, HIGH);
digitalWrite (relaypin2, LOW);
digitalWrite (relaypin3, LOW);
}else if
(involtage>=250 && involtage<=500)
{
digitalWrite( relaypin4,HIGH);
digitalWrite (relaypin2, HIGH);
digitalWrite (relaypin1, LOW);
digitalWrite (relaypin3, LOW);
}
else if
(involtage>=501 && involtage<=1000)
{
digitalWrite( relaypin4,HIGH);
digitalWrite (relaypin3, HIGH);
digitalWrite (relaypin2, LOW);
digitalWrite (relaypin1, LOW);
}
else{
digitalWrite (relaypin1, LOW);
digitalWrite (relaypin2, LOW);

digitalWrite (relaypin3, LOW);
digitalWrite( relaypin4,LOW);
}

}

i need to switch on the relaypin4 when the voltage is between 100 and 1000 (in the analog range). i need a delay of 5 seconds to start the relay when i switch on the stabilizer. Can anyone help?

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Until we get some technical information, there isn't much we can do.

Thanks.. Tom. :slight_smile:

For the delay part: record when your reading went over 100 (record the millis() value when that happens), then 5 seconds (so when storedMillis - millis() > 5000) later you can take your action.

This requires state tracking: you have to store the old voltage reading to compare to the new one, as you need to know when the voltage goes over 1000.

Also you have to think of what to do when the voltage goes over 100 for 3 seconds, than dips for a 0.1 seconds below, then another 2 seconds above. Trigger the relay or not? Wait until it's 5 seconds uninterrupted above 100?