This sketch is for a controller i'm working on and is currently running 24-7 for the past two weeks on my Mega with a 20x4 LCD and DS1307 RTC.Currently I am running two banks of (3w)White LED's and two banks of (3w)Blue LED's along with one bank of moonlights (1w Blue LED's).Both of these are run straight from the date and time set to the RTC without any input from me to turn on/off.There are weather patterns that will dim and brighten the 4 (3w) banks at random and the moonlights will dim and brighten for the current moon phase calculation.I am also running two temp probes,one for the heatsink and one for the tank.Each probe will control a relay to either turn the heatsink fan on/off or the tank heater on/off.For now i'd like to share it and hope someone else will help add new features like pH,ORP,ATO,Salinity,fuge lighting,and wavemaker if I don't get to it first.So please add what you can and add your info to the sketch and re-post it please and thank you.
/*******************************************************************************
*
* Purpose: Aquarium Controller
*
*
* Arduino Version 022
*
*
*
* Originally written by Martin, liquidartstattoos@gmail.com
*
* Initial version 1.0 5.21.2011
*
* Changes Date Details
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*******************************************************************************/
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68 //set rtc
#include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 9 //Define the pin of the DS18B20
int moon = 2; // moon light
int fan = 49; // Fan power relay connected to analog pin 0
int heater = 31; // heater
int iBlueIntensity; //declare the integer of blue intensity
float fBlueIntensity; //declare the floating point version of blue intensity
// RTC variables
byte second, rtcMins, oldMins, rtcHrs, oldHrs, dayOfWeek, dayOfMonth, month, year, psecond;
LiquidCrystal lcd(22,23,24,25,26,27);
//LiquidCrystal lcd(12,13,4,5,6,7); // typically 8, 9, 4, 5, 6, 7
// Set up the custom fish icon
byte newChar[8] = {
B00000,
B00000,
B10001,
B11011,
B11111,
B11111,
B11001,
B10000
};
byte newChar1[8] = {
B00001,
B00010,
B11101,
B11010,
B11111,
B11110,
B11100,
B00000
};
byte newChar2[8] = {
B00000,
B00000,
B10001,
B11011,
B11111,
B11111,
B10011,
B00001
};
byte newChar3[8] = {
B10000,
B01000,
B10111,
B01011,
B11111,
B01111,
B00111,
B00000
};
byte newChar4[8] = {
B00111,
B01110,
B11100,
B11000,
B11000,
B11100,
B01110,
B00111
};
byte newChar5[8] = {
B01010,
B10000,
B00010,
B01001,
B00100,
B10000,
B00100,
B10001
};
byte newChar6[8] = {
B01010,
B00100,
B00001,
B11011,
B00011,
B00001,
B01000,
B10010
};
byte newChar7[8] = {
B10010,
B00100,
B10000,
B11011,
B11000,
B10000,
B00010,
B01001
};
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// LED variables (Change to match your needs)
byte bluePins[] = {3,4}; // PWM pins for blues - if you plan to use the photo stagger, please place the pins in the order you would like them to start
byte whitePins[] = {5,6}; // PWM pins for whites - if you plan to use the photo stagger, please place the pins in the order you would like them to start
byte blueChannels = 2; // how many PWMs for blues (count from above)
byte whiteChannels = 2; // how many PWMs for whites (count from above)
int photoStagger = 0; // offset for east - west delay on each channel in minutes
int startOffset = 0; // offset for start times in minutes - used if you want to change the start and finish time of the cycle. i.e move it to a later time in the day
int colourOffset = 30; // offset for whites to start after blues start in minutes
byte blueLevel[] = {255,255}; // max intensity for Blue LED's
byte whiteLevel[] = {255,255}; // max intensity for White LED's
// Month Data for Start, Stop, Photo Period and Fade (based off of actual times, best not to change)
int daysInMonth[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //Days in each month
int minMinuteStart[12] = {310, 332, 348, 360, 372, 386, 394, 387, 364, 334, 307, 298}; //Minimum start times in each month
int maxMinuteStart[12] = {331, 347, 360, 372, 386, 394, 388, 365, 335, 308, 298, 309}; //Max start time in each month
int minMinuteFade[12] = {350, 342, 321, 291, 226, 173, 146, 110, 122, 139, 217, 282}; //Minimum fade time in each month
int maxMinuteFade[12] = {342, 321, 291, 226, 173, 146, 110, 122, 139, 217, 282, 350}; //Max fade time in each month
int minMinuteStop[12] = {1122, 1120, 1102, 1073, 1047, 1034, 1038, 1050, 1062, 1071, 1085, 1105}; //minimum stop times each month
int maxMinuteStop[12] = {1121, 1103, 1074, 1048, 1034, 1038, 1050, 1061, 1071, 1084, 1104, 1121}; //maximum stop times each month
// Weather variables
int weather = 1; // 0 off, 1 on
int clearDays[12] = {15, 12, 20, 23, 28, 37, 43, 48, 51, 41, 29, 23};
int cloudyDays[12] = {60, 61, 62, 60, 64, 63, 68, 66, 63, 54, 52, 53};
float clearDay = 0.25; // Max cloud value on clear day (percent of max string value)
float cloudyDay = 0.75; // Max cloud value on cloudy day (percent of max string value)
float normalDay = 0.5; // Max cloud value on normal day (percent of max string value)
byte value;
int day, fadeOn, fadeOff, time, pause, count, cloud;
long start, finish;
// Other variables - Do not need to be changed.
int minCounter; // counter that resets at midnight
long secCounter; // counter for seconds - needed for weather
int fadeDuration; // minutes to fade - calculated by map above
int ledStartMins; // minute to start led’s - calculated by map above
int ledStopMins; // minute to stop led’s - calculated by map above
byte blueMax[] = {0}; // used for over temp protection
byte whiteMax[] = {0}; // used for over temp protection
byte valueBlue[] = {0}; // value for clouds
byte valueWhite[] = {0}; // value for clouds
/****** LED Functions ******/
/***************************/
//function to set LED brightness according to time of day
byte setLed(
int mins, // current time in minutes
byte ledPin, // pin for this channel of LEDs
int start, // start time for this channel of LEDs
int fade, // fade duration for this channel of LEDs
int stop, // stop time for this channel of LEDs
byte ledMax, // max value for this channel of LEDs
long begin, // time cloud cycle begins in seconds
long secs, // current time in seconds
int on, // time for cloud to fade on in seconds
int off, // time for cloud to fade off in seconds
long time, // time of cloud
byte value // value for cloud
// max value for this channel
) {
byte ledVal = 0;
if (mins <= start || mins >= stop) //this is when the LEDs are off, thus ledVal is 255;
{
ledVal = 0;
}
if (mins > start && mins <= start + fade) //this is sunrise
{
ledVal = map(mins, start, start + fade, 0, ledMax);
}
if (mins > start + fade && mins < stop - fade && weather == 1)
{
ledVal = ledMax;
if (count == 1){
if (secs >= begin && secs < begin + fadeOn)
{
ledVal = map(secs, begin, begin + on, ledMax, value);
}
if (secs >= begin + on && secs < begin + on + time)
{
ledVal = value;
}
if (secs >= begin + on + time && secs < begin + on + time + off)
{
ledVal = map(secs, begin + on + time, begin + on + time + off, value, ledMax);
}
if (secs >= begin + on + time + off)
{
ledVal = ledMax;
}
if (secs >= finish)
{
count = 0;
}
}
}
if (mins > start + fade && mins < stop - fade && weather == 0)
{
ledVal = ledMax;
}
if (mins < stop && mins >= stop - fade) //this is the sunset
{
ledVal = map(mins, stop - fade, stop, ledMax, 0);
}
analogWrite(ledPin, ledVal);
return ledVal;
}