aquarium auto fertilizer code check

hey guys i have some code i want checked so i dont kill all my fish.

I just made this quick so tell me if theres something i should be worried about.


so i have 4 dosing pumps the 4th one not being used, but i have it defined in the code.

i am using a RTC to keep time, at 8 30 i have pump one turn on delay 5 seconds, turn off, then 2 second pause, repeat for pump 2 and 3. then a 60 second pause to wait for the minute to change so it does not repeat.

please let me know if any changes should be made, if any of these over dose it could be fatal for my fish.

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;

int const motor1 = 9;
int const motor2 = 11;
int const motor3 = 12;
int const motor4 = 13;

void setup () {
   pinMode(motor1, OUTPUT);
 pinMode(motor2, OUTPUT);
 pinMode(motor3, OUTPUT);
 pinMode(motor4, OUTPUT);
#ifdef AVR
  Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));

void loop () {
    DateTime now =;
    Serial.print(now.year(), DEC);
    Serial.print(now.month(), DEC);
    Serial.print(, DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(now.minute(), DEC);
    Serial.print(now.second(), DEC);
    if( (now.hour() == 8 ) && (now.minute() == 10))
      {digitalWrite(motor1, HIGH);
       digitalWrite(motor1, LOW);
       digitalWrite(motor2, HIGH);
       digitalWrite(motor2, LOW);
       digitalWrite(motor3, HIGH);
       digitalWrite(motor3, LOW);

In void setup() put :

digitalWrite(motor1, LOW);
digitalWrite(motor2, LOW);

To make shure that when arduino resets, your pumps don't start accidentally.
Then, look at " Blink without delay" example from Arduino IDE - using delay() here is ok but when you decide to add more things to your code , dalays will give you trouble.

And just a cosmtetics :


int const motor1 = 9;
int const motor2 = 11;
int const motor3 = 12;
int const motor4 = 13;


byte const motor1 = 9;
byte const motor2 = 11;
byte const motor3 = 12;
byte const motor4 = 13;

Just to save a little bit of RAM :slight_smile:

ok sounds great ill keep that in mind, as its going to stay on while im on vacation ill probably leave it for now cause it wont restart unless theres a power outage (please god no).

can you explain why byte is different than int?

meanwhile ill look up blink without delay.

can you explain why byte is different than int?

A byte uses half the memory space of an an int. It may not seem like much of a saving but could be important in a larger program, so it is good practice to get used to using the smallest variable type applicable to the data being held.

You've got a real-time clock and a bunch of delays in your code. I really don't understand that. You know, to the second, when to turn the first pump on and off, when to turn the second pump on and off, and when to turn the third pump on and off.

Make use of now.second() and ditch all those delay()s.