I need help to finish this code and willing to pay for your help, it is already half of the way done:
This is a school project for growing Microgreens automated.
1- A Water Pump has to turn ON at 8:00, 16:00, and 22:00 every day for some seconds starting on day 1, I need to be able to insert in the code the seconds I have to leave the pump ON.(let's say 15 seconds ON each of the times above.)
2 -Turn the LED Strip for 15 hours every day from 07:30 to ON and 22:30 to OFF, starting on Day 4 - the LED Strip has to start its cycle after day 4.
3-System has a water float switch that turn-ON a LED when the level of the water reservoir is low.
4-Need to implement two push buttons to test Water Pump and LED Strip Lights. When button1 is pressed activate the water pump until the button is released, When button2 is pressed activate the LED SDtrip Lights until the button is released
5- The cycle can be from 14 to 30 days depending on the type of seed to grow so better make a cycle of 30 days and when the seeds are ready it is possible to turn OFF and some time to clean everything and then push a Button to Start the cycle again.
6- In case of power failure, a way to continue the cycle from the point of the power failure.
Note:
The water pump, LED Stripe Lights, Water Float, and the LED light to inform low level, are already working in this code made with help from the internet and some posts from the Arduino forum, water pump and LED Strip lights are activated by two separated normal Arduino relays.
What is missing: I tried already but I can not make it is:
1- The activation of the LED lights daily after 4th day of the cycle starts
2- The buttons for testing the pump and the LED
3- The power failure continuation
4- A way to read the Serial Monitor to check if all the phases of the daily cycle have been done correctly,
#include <DS3231.h>
int RelayIN1 = 4;
int RelayIN2 = 5;
int Water_Float_LED = 8;
int Water_Float_Switch = 3;
DS3231 rtc(SDA, SCL);
Time t;
struct HMS
{
byte Hour;
byte Minute;
byte Second;
unsigned long AsSeconds()
{
return (((Hour * 60ul) + Minute) * 60) + Second;
}
};
struct Interval
{
int relayPin;
HMS onTime;
HMS offTime;
const char *message;
boolean isOn;
boolean shouldBeOn(unsigned long seconds)
{
return seconds >= onTime.AsSeconds() && seconds < offTime.AsSeconds();
}
void update(byte hour, byte minute, byte second)
{
HMS time = {hour, minute, second};
boolean nowOn = shouldBeOn(time.AsSeconds());
if (nowOn == isOn)
return; // no change
digitalWrite(relayPin, nowOn);
isOn = nowOn;
Serial.print(message);
if (nowOn)
Serial.println(" ON");
else
Serial.println(" OFF");
}
};
Interval IntervalList[] =
{
{RelayIN1, {08, 00, 00}, {08, 00, 15}, "Morning Spray", false},
{RelayIN1, {16, 00, 00}, {16, 00, 15}, "Afternoon Spray", false},
{RelayIN1, {22, 00, 00}, {22, 00, 15}, "Evening Spray", false},
{RelayIN2, {07, 00, 00}, {23, 00, 00}, "LED Growing Light", false},
};
const size_t IntervalCount = sizeof IntervalList / sizeof IntervalList[0];
void setup()
{
Serial.begin(115200);
rtc.begin();
for (size_t i = 0; i < IntervalCount ; i++)
{
IntervalList[i].isOn = false;
digitalWrite(IntervalList[i].relayPin, LOW);
pinMode(IntervalList[i].relayPin, OUTPUT);
}
// Water Float Level Sswitch
pinMode(Water_Float_LED, OUTPUT);
pinMode(Water_Float_Switch, INPUT_PULLUP);
}
void loop()
{
t = rtc.getTime();
Serial.print(t.hour);
Serial.print(" hour(s), ");
Serial.print(t.min);
Serial.print(" minute(s)");
Serial.print(t.sec);
Serial.print(" seconds(s)");
Serial.println(" ");
delay (1000);
for (size_t i = 0; i < IntervalCount ; i++)
{
IntervalList[i].update(t.hour, t.min, t.sec);
}
if(digitalRead(Water_Float_Switch) == HIGH)
{
digitalWrite(Water_Float_LED, HIGH); //Turn Water_Float_LED ON
}
else
{
digitalWrite(Water_Float_LED, LOW); //Water_Float_LED OFF
}
}