Hi,
I made a plant watering system using arduino.
There are four outputs.
output1 remains high for 10 seconds and then remains low for 2hrs
output2 remains high for 10 seconds and then remains low for 8hrs
output3 remains high for 10 seconds and then remains low for 12hrs
output4 remains high for 10 seconds and then remains low for 24hrs
This is in a loop, so it should keep happening in an infinite loop.
Idea is that plants get watered periodically.
In addition to this I have a 'debugMode' where I made low time from 2hrs to 10seconds, 8hrs to 70seconds, 12hrs to 110 seconds and 24hrs to 230seconds. This is there to quickly enable checking if the program is fine.
Everything works fine. Except that after about 2 days, something is going wrong and the system pipe which is on, stays ON even after 10 seconds. This is leading to a lot of water wastage.
I re-checked the code multiple times, but cannot see why this is happening.
Please help!!
/*
Water Controller
4 outputs are given out at 2hrs, 8hrs, 12hrs and 24 hr gaps
1 input is to determine if it is in debug mode or not.
In debug mode instead of OFF time being (2hrs - 10s), it will be (20s - 10s).
Similarly instead of (8hrs - 10s), it will be (80s - 10s)
*/const int NUMOUTPINS = 4;
const int OUTPINS[NUMOUTPINS] = {
5, 6, 7, 8};
const int INPIN = 9;
unsigned long int currMillis;
unsigned long int prevMillis[4];
int pipeStatus[NUMOUTPINS];
const unsigned long int ONTIME = 10000UL;
unsigned long int offTime[4];
int isDbgMode;// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
for(int i=0 ; i<NUMOUTPINS; i++)
{
pinMode(OUTPINS*, OUTPUT); *
_ pipeStatus* = LOW;_
_ }_
_ pinMode(INPIN, INPUT); _
_ isDbgMode = 0;_
_ for(int i=0 ; i<NUMOUTPINS; i++)_
_ {_
_ prevMillis = 0;
offTime = 0;
}
currMillis = 0;
}
void invertOutPin(int pin){
if(digitalRead(pin) == LOW)
{
digitalWrite(pin, HIGH);
}
else*
* {
digitalWrite(pin, LOW);
}
}
// the loop routine runs over and over again forever:
void loop() {
//read dbg switch status*
* isDbgMode = digitalRead(INPIN);
if(isDbgMode == HIGH)
{
offTime[0] = 10000UL;
offTime[1] = 70000UL;
offTime[2] = 110000UL;
offTime[3] = 230000UL;
}
else {
offTime[0] = 7200000UL; //2hrs : 7200s*
* offTime[1] = 28800000UL; //8hrs : 28800s*
* offTime[2] = 43200000UL; //12hrs: 43200s*
* offTime[3] = 86400000UL; //24hrs: 86400s*
* }
//read current Millis:
currMillis = millis();
//check for overflow:
for(int i=0; i<NUMOUTPINS; i++)
{
prevMillis = (prevMillis > currMillis) ? 0 : prevMillis;
}
for(int i=0; i<NUMOUTPINS; i++)
{
//is pipe ON?
if(pipeStatus == HIGH)
{
if((currMillis - prevMillis) > ONTIME)
{
pipeStatus = LOW; //turn off the pipe*
digitalWrite(OUTPINS*, LOW);
prevMillis = currMillis;
}
}
//else pipe is OFF:
else*
* {
if((currMillis - prevMillis) > offTime)
{
pipeStatus = HIGH; //turn ON the pipe*
digitalWrite(OUTPINS*, HIGH);
prevMillis = currMillis;
}
}
} //for*
}
[/quote]
PS: please note that I tried changing "unsigned long int" to "unsigned long", but the hex files generated in both the cases is the same._
