Hello everyone,
I've been working on a little script that is supposed to turn my home server on and off after a while. I tested it a couple of times with timeframes of 30 and 60 minutes, and all worked fine. But now that I have bigger numbers, for a 24hour schedule, it doesn't work anymore.
Can you guys help me please?
Thanks in advance,
Dorus
PS: Sorry for my English
This is what it looks like:
int LedPin = 13;
int SensorPin = 9;
int RelayPin = 8;
int time = 0;
int val;
void setup() {
pinMode(SensorPin, INPUT);
pinMode(LedPin, OUTPUT);
pinMode(RelayPin, OUTPUT);
digitalWrite(LedPin, HIGH);
}
void loop(){
while(time < 960){
digitalWrite(RelayPin, LOW);
delay(60000);
time ++;
}
if (time == 960 ) {
val = digitalRead(SensorPin);
if (val == HIGH){
delay(60000);
time ++;
}
else{
digitalWrite(RelayPin, HIGH); //This gives a high signal to the relay, which switches ON the server
delay(1000);
digitalWrite(RelayPin, LOW);
delay(59000);
time ++;
}
}
val = digitalRead(SensorPin);
if (time >= 1440){
if (val == HIGH){
digitalWrite(RelayPin, HIGH); //This gives a high signal to the relay, which switches OFF the server
delay(1000);
digitalWrite(RelayPin, LOW);
time = 0;
}
else{
time = 0;
}
}
else{
time ++;
delay(60000);
}
} // end loop
Moderator edit: Code tags added and duplicate post deleted.