Hello everyone,
I'm trying to build a flood and drain controller for my garden and getting stuck on some things and not sure but might not even be on the right track. Soo here's what I want to do I want to make a controller/timer that will turn a pump on for 30 min ( Flood ) then turn it back off and turn another pump on for 3 1/2 hrs ( Drain ) and i would like to have an lcd display that shows how long the cycle has been running but resets every 4 hrs at each new flood. I want the flood cycle to be at the beginning of the program so that way if the power goes out it'll flood again once it comes back on instead of having a longer drain period if that makes sense . Here's what I have so far I have a uno board and a 16x2 lcd shield and a 2 channel relay board i've done all the basic lcd examples hello world, ect... and have the lcd working well and have also done some basic delay programs to fire the relays so now im trying to put it all together as one piece and have found some programs other have written for lcd timers that i like and have been trying to modify to fit my project. I want the lcd to display hours min and seconds since the cycle started and i want to have one pin output a signal to my relays. im going to use the one pin to trigger both relays and just wire one relay as normally open and the other as normally closed so basically they will flip flop when triggered so it will switch from drain to flood that way as a fail safe its always on drain so i don't accidentally overflow anything.
ok soo now on to the code. the code if found basically just counts the time since the arduino was last reset and displays it on the lcd in sec, mins, hrs, and days I have modified it to just display sec, min and hrs and to reset at 4 hrs I also started adding pin 13 led for now which later will be changed to a diffrent pin for the relay and im starting to get stuck. I think i need to add an if statement that states if less than 30 min pin 13 high or else pin 13 low but im not sure how to format it to work properly with the hrs because i dont want it going off for the first 30 min of each hr.
Current code:
/* This sketch is basically a clock function even though it doesn't
"tell" time. I designed it to perform operations at a certain time
of the day. Depending on what time you start the program, you would
have to adjust the time of the operation accordingly. (unless you want
to start the program at midnight) I start by (Scount) counting milli-
seconds, then (Mcount) minutes etc.... It prints to the LCD (4 x 20)
sec, min, hrs, days.
garym
*/
#include <LiquidCrystal.h> // lib. for LCD
int Scount = 0; // count seconds
int Mcount = 0; // count minutes
int Hcount =0; // count hours
int led = 13;
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7); // pins connected to LCD
void setup()
{
pinMode(led, OUTPUT);
lcd.begin(16,2); // open the LCD
// Print a message to the LCD.
lcd.print("hello, world!");
delay(2000);
lcd.clear();
}
void loop()
{
lcd.setCursor(8,0); // sets cursor to 1st line
lcd.print ("Hrs ");
lcd.print (Hcount);
lcd.print (" ");
if ( Mcount == 60) // if Mcount is 60 do this operation
{
delay (32); // good place to fine tune timing
Mcount = 0; // reset Mcount
Hcount ++;
}
if (Hcount> 4)
{
Hcount = 0; // have to reset Hcount to "0" after 4hrs
}
lcd.setCursor (0,1); // sets cursor to 2nd line
lcd.print (Mcount);
lcd.print (" min ");
lcd.setCursor (0,0); // sets cursor to 1st line
lcd.print (Scount);
lcd.print (" SEC ");
if (Scount >59) // if 60 do this operation
{
Mcount ++; // add 1 to Mcount
Scount = 0; // reset Scount
delay (58); // changes ms per min
}
if (Scount < 60) // do this oper. 59 times
// to count the seconds
{
delay (988); // changing by one = 60 ms a min
Scount ++; // add 1 to Scount
}
}
Any help is greatly appreciated
p.s. if im going about this all wrong let me know and maybe give me a little guidance thanks