Arduino Aquarium Controller

Arduino Aquarium Controller

Control aquarium light - sunset, sunrise.

  • 6,973 views
  • 1 comment
  • 12 respects

Components and supplies

About this project

For illumination with 300 liters:

  • 4 channels - LED CREE XT-E (XTEAWT-00-0000-000000H51) - 5W 5000K-8300K - 40 pieces
  • 1 channels - LED CREE XT-E Royal Blue 450-455NM - 5W - 5 pieces
  • 1 channels - LED Red 660nm -3W 10 pieces
  • cooling LEDs - 2 radiator 100 * 300 * 28, 2 fans

To control the light:

  • Arduino nano - 1 pieces
  • RTC S1307 - 1 pieces
  • 2-Channel Relay Module - 1 pieces
  • LED driver Mean Well LDD-1000H - 5 pieces (5 channels)
  • LED driver Mean Well LDD-700H - 1 pieces (1 channels)
  • Power Supply 48v 350w, DC/DC  48v - 12v

And additional components for the assembly of the Aquarium lid.

Control

(PWM) The main task of the control unit - infinitely adjustable levels for each channel individually in accordance with the specified data for each channel in real time (DS1307 library Github):

PWM has a maximum value of 255 - 100%. PWM channels (pins 3, 5, 6, 9, 10, 11) Arduino:

  • The start time of the sunrise
  • The finish time of the sunrise
  • The start time of the sunset
  • The finish time of the sunset
  • The minimum value of the PWM (night-time)
  • The maximum value of the PWM (daytime)

Accordingly, the PWM signal for the channel LED driver is:

  • minimum value at the night-time
  • maximum value at the daytime
  • increases linearly from the minimum to the maximum value during the sunrise
  • decreases linearly from the maximum to the minimum value during the sunset

2-Channel Relay Module for fan control and solenoid valve for supplying CO2

Also I plan to add: sensors of temperature and general hardness of water, a web interface to control the light, a mobile application for convenient operation with the device, and many other things, but that is for another story.

Code

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

RTC_DS1307 RTC;

int Hours_Start_Sunrise[6] = {11, 9, 10, 11, 12, 12};             // начало рассвета по каналам час
int Minutes_Start_Sunrise[6] = {0, 0, 0, 0, 0, 0};              // начало рассвета по каналам минута
int Hours_End_Sunrise[6] = {15, 12, 13, 14, 15, 15};      // окончание рассвета по каналам час
int Minutes_End_Sunrise[6] = {0, 0, 0, 0, 0, 0};                  // окончание рассвета по каналам минута

int Hours_Start_Sunset[6] = {17, 20, 19, 18, 17, 17};    // начало заката по каналам час
int Minutes_Start_Sunset[6] = {0, 0, 0, 0, 0, 0};                // начало заката по каналам минута
int Hours_End_Sunset[6] = {21, 23, 22, 21, 21, 21};        // окончание заката по каналам час
int Minutes_End_Sunset[6] = {0, 0, 0, 0, 0, 0};            // окончание заката по каналам минута

int MinuteDay_Start_Sunrise[6];                                            // день в минутах для начала рассвета
int MinuteDay_End_Sunrise[6];                                                    // день в минутах для окончания рассвета

int MinuteDay_Start_Sunset[6];                                                  // день в минутах для начала заката
int MinuteDay_End_Sunset[6];                                                      // день в минутах для окончания заката

int Current_MinuteDay;                                                                  // текущая минута суток
int Current_Period[6];                                                                  // текущая часть суток 1-рассвет, 2-день, 3-закат, 4-ночь для каждого ШИМ

int Meridian_PWM[6] = {128, 192, 192, 192, 128, 128};    // максимальное значение ШИМ
int Midnight_PWM[6] = {0, 0, 0, 0, 0, 0};                                // минимальное значение ШИМ
int Current_PWM[6] = {0, 0, 0, 0, 0, 0};                                  // текущее значение ШИМ

/* ***************************************************** */
/* *                                                                                               * */
/* *    ШИМ пин для CW                   * */
/* *    Пин - 3  -                                       * */
/* *    Пин - 5  -                                     * */
/* *    Пин - 6  -                               * */
/* *    Пин - 7  -                                                * */
/* *    Пин - 10 -                                            * */
/* *    Пин - 11 -                                     * */
/* *                                                                                               * */
/* ***************************************************** */

int PWM_Pin[6] = {3, 5, 6, 9, 10, 11};                                  // ШИМ пин

int Relay1 = 7; //вент
int Relay2 = 8; //луна
byte Relay1Status=false;
byte Relay2Status=false;

void setup()
{

        Serial.begin(57600);
        Wire.begin();
        RTC.begin();

        if (! RTC.isrunning()) {
           Serial.println("RTC is NOT running!");
           //RTC.adjust(DateTime(2012, 7, 12, 22, 48, 1));
           }
                //RTC.adjust(DateTime(2012, 7, 31, 21, 53, 1));


   for (int i=0; i<=5; i++)
        {
          pinMode(PWM_Pin[i], OUTPUT);                                    // Установка пин для ШИМ
        }

   for (int i=0; i<=5; i++)
        {
          analogWrite(PWM_Pin[i], Midnight_PWM[i]);              // Установка минимального значения ШИМ
          Current_PWM[i]=Midnight_PWM[i];                                       // установка текущих значений ШИМ в минимум
        }

   for (int i=0; i<=5; i++)
        {
          MinuteDay_Start_Sunrise[i]=60*Hours_Start_Sunrise[i] + Minutes_Start_Sunrise[i];               // Расчет минуты суток для начала рассвета
          MinuteDay_End_Sunrise[i]=60*Hours_End_Sunrise[i] + Minutes_End_Sunrise[i];                       // Расчет минуты суток для окончания рассвета
          MinuteDay_Start_Sunset[i]=60*Hours_Start_Sunset[i] + Minutes_Start_Sunset[i];                 // Расчет минуты суток для начала заката
          MinuteDay_End_Sunset[i]=60*Hours_End_Sunset[i] + Minutes_End_Sunset[i];                                 // Расчет минуты суток для окончания заката
        }
  pinMode(Relay1, OUTPUT);       
  pinMode(Relay2, OUTPUT);       
  digitalWrite(Relay1, LOW);   
  digitalWrite(Relay2, HIGH);   

}

// Процедура расчета текущего периода и значения PWM по каналам
void Led_Dim_PWM()
{
  DateTime now = RTC.now();
  Current_MinuteDay = (now.hour() * 60) + now.minute();
 
  for (int i=0; i<=5; i++)
   {
         Current_Period[i]=4;
         if (Current_MinuteDay>=MinuteDay_Start_Sunrise[i] && Current_MinuteDay<=MinuteDay_End_Sunrise[i]) {Current_Period[i]=1;}
         if (Current_MinuteDay>MinuteDay_End_Sunrise[i] && Current_MinuteDay<MinuteDay_Start_Sunset[i]) {Current_Period[i]=2;}
         if (Current_MinuteDay>=MinuteDay_Start_Sunset[i] && Current_MinuteDay<=MinuteDay_End_Sunset[i]) {Current_Period[i]=3;}

         if (Current_Period[i]==1)
           {
                   Current_PWM[i]=(float)(((float)Current_MinuteDay-MinuteDay_Start_Sunrise[i])/((float)MinuteDay_End_Sunrise[i]-MinuteDay_Start_Sunrise[i]))*((float)Meridian_PWM[i]-Midnight_PWM[i]);
                   if (Current_PWM[i]<Midnight_PWM[i]) {Current_PWM[i]=Midnight_PWM[i];}
                   analogWrite(PWM_Pin[i], Current_PWM[i]);                                                                                                                                                                                       
           }

         if (Current_Period[i]==2)
           {
                 if (Current_PWM[i]!=Meridian_PWM[i])
                  {
                        Current_PWM[i]=Meridian_PWM[i];
                        analogWrite(PWM_Pin[i], Current_PWM[i]);
                  }
           }

         if (Current_Period[i]==3)
           {
                   Current_PWM[i]=(float)(((float)MinuteDay_End_Sunset[i]-Current_MinuteDay)/((float)MinuteDay_End_Sunset[i]-MinuteDay_Start_Sunset[i]))*((float)Meridian_PWM[i]-Midnight_PWM[i]);
                   analogWrite(PWM_Pin[i], Current_PWM[i]);
           }
           
          if (Current_Period[i]==4)
                {
                  if (Current_PWM[i]!=Midnight_PWM[i])
                  {
                        Current_PWM[i]=Midnight_PWM[i];
                        if (Current_PWM[i]<Midnight_PWM[i]) {Current_PWM[i]=Midnight_PWM[i];}
                        analogWrite(PWM_Pin[i], Current_PWM[i]);
                  }
                }
          }
         
        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.print(" Current_MinuteDay: ");
        Serial.print(Current_MinuteDay, DEC);
        Serial.println();
         
        for (int i=0; i<=5; i++)
         {
          Serial.print("Channel #");     
          Serial.print(i, DEC);
          Serial.print(", Current Period: ");   
          if (Current_Period[i]==1) {Serial.print("Sunrise");}   
          if (Current_Period[i]==2) {Serial.print("Meridian");} 
          if (Current_Period[i]==3) {Serial.print("Sunset");}   
          if (Current_Period[i]==4) {Serial.print("Midnight");}
          Serial.print(", Current PWM: ");
          Serial.print(Current_PWM[i], DEC);
          Serial.println();
         }
         Serial.println();
}

void RalayOnOff()
  {
  int SumPWM=0;

  for (int i=0; i<=5; i++)
        {
         SumPWM=SumPWM+Current_PWM[i];
        }
        if (SumPWM>=50 && Relay1Status==false)
          {
                Relay1Status=true;
                Relay2Status=false;
                digitalWrite(Relay1, HIGH);
                digitalWrite(Relay2, LOW);
          }

        if (SumPWM<50 && Relay1Status==true)
          {
                Relay1Status=false;
                Relay2Status=true;
                digitalWrite(Relay1, LOW);
                digitalWrite(Relay2, HIGH);
          }
  }
void loop () {

       
        Led_Dim_PWM();
        RalayOnOff();
   
        delay(60000);

}

Schematics

scheme
sprint layout
002
ldd1.lay6
ldd1.lay6

Comments

Similar projects you might like

Making a Cheap Aquarium Parameters Controller

Project tutorial by Boisse Martin

  • 5,046 views
  • 3 comments
  • 16 respects

IoT Aquarium Light Controller

Project in progress by Neto Carrer

  • 8,654 views
  • 2 comments
  • 26 respects

Reef Controller

Project showcase by Shawn Leclair

  • 13,546 views
  • 0 comments
  • 19 respects

Simple DALI Controller

Project in progress by NabiyevTR

  • 32,437 views
  • 55 comments
  • 35 respects

IR Controller for Air Conditioner

Project in progress by BuddyC

  • 32,433 views
  • 8 comments
  • 22 respects

Soldering Iron Controller for Hakko 907

Project tutorial by Alexander

  • 30,358 views
  • 22 comments
  • 67 respects
Add projectSign up / Login