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.

explanation:

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);
  
  Serial.begin(57600);
#ifdef AVR
  Wire.begin();
#else
  Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
#endif
  rtc.begin();

  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 = rtc.now();
    
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    
    if( (now.hour() == 8 ) && (now.minute() == 10))
      {digitalWrite(motor1, HIGH);
       delay(5000);
       digitalWrite(motor1, LOW);
       
       delay(2000);
       
       digitalWrite(motor2, HIGH);
       delay(5500);
       digitalWrite(motor2, LOW);
       
       delay(2000);
       
       digitalWrite(motor3, HIGH);
       delay(5000);
       digitalWrite(motor3, LOW);
       
       delay(60000);
      }   
      
      
    
    
    delay(1000);
}

In void setup() put :

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

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 :

Change

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

to

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.