need help for aquarium automation project

hello guys ,
iam now currently building a aurdino project for automating my aquarium very simple stuff like
auto topoff
turning on light with relay
automated water change
i have really no idea about engineering and codes cause im a a doctor
i managed to scavenge codes from other projects and managed to build very basic code for the system and for now i managed to make the auto top off and light relay to work and also an rtc to work was a big headache … :disappointed_relieved:

now i am having problem with the auto top off code, i want the system to turn on at 12 everyday run for 3min. then shutdown itried using delay but it is causing the other systems to halt so can u guys guide me how to make it work
and also i want the auto top off pump to run for an extra 3 sec before it shuts down , heard about using mills. but really i dont know how to use it , dont want to use delay cause it is delaying everything , please help me out with this guys
thanks in advance!

#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68

////Convert normal decimal numbers to binary coded decimal.
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}

////Convert binary coded decimal to normal decimal numbers.
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}

////Stops the clock, but it has the side effect of setting seconds to 0.
/*void stopDs1307()
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.writeWire.writeWire.write(0x80);
Wire.endTransmission();
}*/

////1) Sets date and time on the clock.
////2) Starts the clock.
////3) Sets hour mode to 24 hours.
void setDateDs1307(
byte second, ////0-59
byte minute, ////0-59
byte hour, ////1-23
byte dayOfWeek, ////1-7
byte dayOfMonth, ////1-28/29/30/31
byte month, ////1-12
byte year) ////0-99
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.write(decToBcd(second)); ////0 to bit 7 starts the clock
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour)); ////If you want 12 hours (am/pm) you need to set
////bit 6 (also need to change getDateDs1307)
Wire.write(decToBcd(dayOfWeek));
Wire.write(decToBcd(dayOfMonth));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.endTransmission();
}

////Reads date and time from the clock,
void getDateDs1307(
byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{

////Reset the register pointer.
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

////A few of these need masks because certain bits are control bits.
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f); ////Need to change this for 12 hours (am/pm)
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}

////Define pump pin outs.
int flushpin = 2; //Pump 1 – Flourish Excel
int lightpin = 3; //Pump 2 – Flourish Iron
int flowerpump =4 ; //Pump 3 – Flourish
int plantpump = 5;
int flowersensor = 6;
int plantsensor = 7;
int reservoir = 8;
int actled = 13; //Status Led

void setup() ////One time run at each execution.
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
pinMode(flushpin, OUTPUT);
pinMode(lightpin, OUTPUT);
pinMode(flowerpump, OUTPUT);
pinMode(plantpump, OUTPUT);
pinMode(actled, OUTPUT);
pinMode(flowersensor, INPUT_PULLUP);
pinMode(plantsensor, INPUT_PULLUP);
pinMode(reservoir, INPUT_PULLUP);
Wire.begin();
Serial.begin(9600);

////Set date and time on the clock.
////You only need to run this the first time you setup your RTC.
////Set the correct value below and un comment it to run it.
/*
second = 00;
minute = 10;
hour = 15;
dayOfWeek = 1;
dayOfMonth = 19;
month = 6;
year = 16;
setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
*/

}

void loop()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;




 
   if (hour >= 23 && hour < 9) {
      digitalWrite(lightpin, HIGH);
    } 
    else {
      digitalWrite(lightpin, LOW);
    }
if((digitalRead(reservoir) == HIGH)||(digitalRead(flowersensor) == HIGH))

  {digitalWrite(flowerpump, HIGH);}
  else
  {digitalWrite(flowerpump, LOW);}

if((digitalRead(reservoir) == HIGH)||(digitalRead(plantsensor) == HIGH))

{digitalWrite(plantpump, HIGH);}
  else
  {digitalWrite(plantpump, LOW);}

  if (hour=12)
  {digitalWrite(flushpin, HIGH);}
 
   else
  {digitalWrite(flushpin, LOW);}
}

well the tank is a heavily planted tank looks like a jungle with ricia , so really cant vacuum the substrate and the water used for replacement is pre treated with seachem safe stored in a 100 l container so no problem and the system is a 40 gallon tank running on fluval fx 5 filtration system with seachem purigen reactor and seachem matrix so wont be a problem!
this is the tank btw

Two things come to mind - the first, your timing issue, do a search here for "blink without delay" - the problem you are running into is that the "delay()" function does it's thing by spinning in a tight loop and taking all the processor time so nothing else gets done. What you need is a different approach - basically, you set a timer then go about doing other things until the timer goes off telling the processor it is done.

The second thing that comes to mind is the need to have safety things in series with your automated controls so if something goes wrong and leaves the heat on for example (or the fill), the failsafe switch will shut it down (and even better alert you to the problem). When I did my hot tub control for example, I put my control in series with the original thermostat then set the original thermostat about a degree above my desired control temperature - that way, if the controller failed etc. the original thermostat would keep it from going too high. Even simple looking code can have hidden gremlins in it

gpsmikey:
Two things come to mind - the first, your timing issue, do a search here for “blink without delay” - the problem you are running into is that the “delay()” function does it’s thing by spinning in a tight loop and taking all the processor time so nothing else gets done. What you need is a different approach - basically, you set a timer then go about doing other things until the timer goes off telling the processor it is done.

The second thing that comes to mind is the need to have safety things in series with your automated controls so if something goes wrong and leaves the heat on for example (or the fill), the failsafe switch will shut it down (and even better alert you to the problem). When I did my hot tub control for example, I put my control in series with the original thermostat then set the original thermostat about a degree above my desired control temperature - that way, if the controller failed etc. the original thermostat would keep it from going too high. Even simple looking code can have hidden gremlins in it

since i have a rtc clock is there some sort of if command to start the pump at 12 evaryday and end it at 12.5 everyday if it is possible kindly tell how to do it
thanks!

There are a couple of ways of doing what you are asking - both involve a task that runs every second for example and reads the RTC. In the first case, you would have two times listed in your code (or better a table of timed tasks) with the start time and end time listed. When you reach the "start time" you turn something on and when you reach the end time, you turn it off. The second way (and probably the way I would do it) is to have a list with start_time and run_time listed. At the start time, it turns whatever on and then the run_time is in seconds (or whatever you need) which is loaded into a timer counter - your 1 second timer decrements that counter each time through and when it reaches 0, it turns it back off again. That makes it easier to calculate (and avoids funny surprises when you schedule something across midnight for example). The key is to have something that runs at regular intervals (1 second or whatever) that reads the RTC and checks to see if anything needs to be done. Be very careful when comparing things like time to check for things like "greater than" instead of "equal" - equal gets missed if something else is going on when the count goes past and you then miss doing something you expected. I think many of the RTC chips have a 1 second pulse output you could use to run an interrupt but I don't know if you have access to that with your hardware.

gpsmikey:
There are a couple of ways of doing what you are asking - both involve a task that runs every second for example and reads the RTC. In the first case, you would have two times listed in your code (or better a table of timed tasks) with the start time and end time listed. When you reach the "start time" you turn something on and when you reach the end time, you turn it off. The second way (and probably the way I would do it) is to have a list with start_time and run_time listed. At the start time, it turns whatever on and then the run_time is in seconds (or whatever you need) which is loaded into a timer counter - your 1 second timer decrements that counter each time through and when it reaches 0, it turns it back off again. That makes it easier to calculate (and avoids funny surprises when you schedule something across midnight for example). The key is to have something that runs at regular intervals (1 second or whatever) that reads the RTC and checks to see if anything needs to be done. Be very careful when comparing things like time to check for things like "greater than" instead of "equal" - equal gets missed if something else is going on when the count goes past and you then miss doing something you expected. I think many of the RTC chips have a 1 second pulse output you could use to run an interrupt but I don't know if you have access to that with your hardware.

well the problem is i really dontknow how to implement it, if possible can u please give the code , or type it in my code and provide it , will be really helpful as i have "0" knowledge in coding
thanks!

drashokkumar:
well the problem is i really dontknow how to implement it, if possible can u please give the code , or type it in my code and provide it , will be really helpful as i have "0" knowledge in coding
thanks!

Start by checking out the "blink without delay" information. As far as "0 knowledge in coding" - time to start learning - check out the book "Programming Arduino - getting started with sketches" second edition (just recently published). Download and install the IDE and play with the examples included. Coding is just about telling a fast (but not very smart) entity how to do something in a step by step method.

will this command work ?

if ((hour =12 minute=0)&& (hour =12 minute <3))
{digitalWrite (flushpin, HIGH)}
else
{digitalWrite (flushpin, LOW)}

or will this work out
please help guys really in need to complete the code :slightly_frowning_face:

if ((hour =12,0)&& (hour =12,3))
{digitalWrite (flushpin, HIGH);}
else
{digitalWrite (flushpin, LOW);}

travis_farmer:
Sorry for my earlier comment. as you are probably aware, there are some out there that start fish as a hobby, grow tired of it, and then turn to automation to take over a hobby they don't want anymore.

is the tank glass or acrylic?

I ask because I found this at sparkfun.com.
SST Liquid Level Sensor - SEN-13835 - SparkFun Electronics
it is a solid state liquid level sensor. but it would need to go through the tank. though I suppose you could suspend it above the tank so it dips in.

My line of thought is that you may want a failsafe shutoff for filling the tank back up.

My tank is not nearly as heavily planted, but I do have a healthy batch of lily pads on one end of my 55G freshwater tank.

I found the sensor, and my first thought was to use it to just top-off my tank, as being a tropical tank, the water likes to evaporate. but I didn't want to dump untreated water into the tank. interesting idea, the 100 l storage of pre-treated water. I don't have room for that with my tank, but it gets me thinking...

anyway, I wish you luck with your project.

~Travis

its a glass tank
the think i wanted to do the automation stuff is the hobby is really killing my time , as iam a doctor working in the er have really very little time to take care of the tank , and my heart says dont let go of the fish tank since i managed to build each and everything of the tank myself from scratch even the glass tank was built by me so really have no other choice than to automate the stuff
since i am from India there are really no ready made solutions are readily available , except a simple aurdino , float sensor ,and a simple rtc
and the weather is also very hot and there are cpu fans running over tank tank and evaporation rate is around 9-10l / day so it is simply impractical to sit and top off the tank everytime
hope u understand my situation !
when it comes to hobby or work i want both of them so really cant do anything about it !