Hi,
I am developing a project for automatic watering system for my garden. I'm using an Arduino Yun and some relay shields.The garden is divided into 6 sprinklers zones, that can run individually.
I wrote a webpage from where I can control all my sprinklers from my smartphone/tablet. For each zone I added 3 buttons on my website: ON - OFF - TIMER. The ON & OFF functions are working perfectly, but I'm having problems with my TIMER. The idea is when you click the TIMER button, the sprinkler will run for a programmed time and then shuts off again.
A part of my sketch looks like this:
void loop() {
YunClient client=server.accept();
if(client){
String command = client.readString();
command.trim();
Console.println(command);
if(command == "z1on"){
z1on();
}
else if(command == "z1off"){
z1off();
}
else if(command == "z1timer"){
z1timer();
}
....
The function z1timer() looks like this:
void z1timer(){
digitalWrite(9,LOW);
delay(5000);
digitalWrite(9,HIGH);
}
And here is the problem: when the function is running the project is paused and waits for the delay to finish. So I can't use 2 zones at the same time, the first has to finish before the next is working. I know this is caused by the delay(), but I tried to fix it with a mills() solution. This also doesn't work because the command from the webpage is issued only once when clicking so it won't run continuously in the loop section.
Sorry for the long explanation, if you made it this far THX!
Anyone has a solution ?