I have started Arduino based aquarium controller. At the moment I got stuck with the time controlled outputs. I am sorry for my English but I'll try to explain.
I am working on Arduino PRO MINI. Also using Tiny RTC DS1307 and I2C 20x4 LCD booth on the same I2C line. For RTC I am using RTClib.h librarry. Dallas temperature sensor, DH11. Everything is working good but time control. I have time on display, I can adjust time by 3 buttons.
I want to control aquarium light, air pump, 2 filters by time. For instance: I want that aquarium lights could light on right on 7.30 and turns off on 21.30. Nearly the same with other stuff (filters, air etc.) The important thing is that after power failure during ON time (day time) controller should turn on light again when power comes on again.
Here is part of my code for time controller:
//define
unsigned int LightStartHr = 7; // light on hour
unsigned int LightStartMin = 30; // light on minute
unsigned int LightEndHr = 21; // light off hour
unsigned int LightEndMin = 30; // light of minute
void loop()
{
if ((hours >= LightStartHr && minutes >= LightStartMin) && (hours <= LightEndHr && minutes < LightEndMin))
{
// turn on light
lcd.setCursor(0, 3);
digitalWrite(LightLED, HIGH);
digitalWrite(NightLED, LOW);
lcd.print("Day ");
}
else
{
// turn off light
lcd.setCursor(0, 3);
digitalWrite(LightLED, LOW);
digitalWrite(NightLED, HIGH);
lcd.print("Night");
}
}
I hope this helps you to understand what I want and figure out my mistake.
I must tell you that if I remove minutes and stay with only hours - everything is working fine. Light is turning on in round about hour set. The same if I remove hour and stay only with minutes. How to force controlling with booth hour and minute: "if ((hours >= LightStartHr && minutes >= LightStartMin) && (hours <= LightEndHr && minutes < LightEndMin))"
I am not good in Arduino programming :~ so I need support here.
By the way I have searched a lot unsuccessfully. A lot of examples are based on mills. They counting time from midnight. This is not good for me. I want control outputs by 24H time. Thanks.