As always, plans change. I started this thread almost a year ago! My 60 gallon tank is still running, but on it's last leg. I've all but let it go because of an unexplained contamination issue. I basically top off the water and feed my fish.
In the last several months, I've been acquiring new equipment for the next build. I've been transitioning my livestock to a 20 gallon tall tank over the last few months and I have been using the LEDs, power supply, and drivers from this thread.
I thought it was time for an update!
I adapted the fixture to be smaller and just LEDs. I've setup two of the 30w chips and 6 of the blue 3 watt LEDs. After using this setup for a number of months now, I can tell you that two of the 30w chips is way over kill for my application. In fact, I've actually only had power going to one of the 30w chips since day one and I've been ramping it up to a lower maximum intensity ever since. I do, however, think I've finally arrived at a decent lighting schedule (time + intensity). Which brings me to the next logical step of this process. Programming the Arduino.
I've already posted links to youtube videos as an introduction to the Arduino environment. I think they are an excellent place to start for those interested.
I've posted my code below. After some googling, and experimenting with different codes, this is the best I could come up with. The code is very basic. The controller's only purpose is to ramp up and down the LEDs on a specified schedule while referencing the clock. Yes, in order to adjust the light schedule and intensity, I have to connect the Arduino to my computer. While I thought this would be a pain, it hasn't been that bad. How often do we really adjust our lighting schedule? As this project progresses, I'll have to consider whether or not it is worth the time, money, and effort to build in some sort of user interface that is more convenient (display, way to adjust the schedule, etc.).
I welcome any feedback on ways to make the code more efficient. Thanks in advance!
<pre class="code">// Date and time functions using a DS1307 RTC connected via I2C and Wire library
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
// PINS 8-10 have an LED connected to it for PWM control
int LED1 = 8;
int LED2 = 9;
int LED3 = 10;
// Set controllable inputs to initial value
// The LED drivers need a full 255 PWM signal to turn off.
int onHour = 0;
int onMin = 15;
int rampPeriod = 90;
int whiteDelay = 90;
int offHour = 9;
int offMin = 30;
int LEDBlueHigh = 150;
int LEDBlueLow = 254;
int LEDWhiteHigh = 220;
int LEDWhiteLow = 253;
int blueLevel = LEDBlueLow;
int whiteLevel = LEDWhiteLow;
int minutes = 0;
// The setup routine runs one time
void setup () {
// Start serial communication for the RTC
Serial.begin(57600);
#ifdef AVR
Wire.begin();
#else
Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino
#endif
rtc.begin();
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!"
;
// The following line sets the RTC to the date & time this sketch was compiled (uncomment to initially set the clock)
// rtc.adjust(DateTime(__DATE__, __TIME__));
delay (50);
}
//Set pin modes for LED PWM control
pinMode (LED1, OUTPUT);
pinMode (LED2, OUTPUT);
pinMode (LED3, OUTPUT);
// Should lights be on?
DateTime now = rtc.now(); // What time is it?
delay (20);
minutes = now.hour()*60 + now.minute(); // Compute the number of minutes since 0:00
delay (20);
// Should Blue Lights Be On?
if (minutes > ((onHour * 60) + onMin + rampPeriod) && minutes < ((offHour * 60) + offMin - rampPeriod)){
analogWrite (LED2, LEDBlueHigh);
}
else {
analogWrite (LED2, LEDBlueLow);
}
// Should White Lights Be On?
if (minutes > ((onHour * 60) + onMin + rampPeriod + whiteDelay) && minutes < ((offHour * 60) + offMin - rampPeriod - whiteDelay)){
analogWrite (LED1, LEDWhiteHigh);
analogWrite (LED3, LEDWhiteHigh);
}
else {
analogWrite (LED1, LEDWhiteLow);
analogWrite (LED3, LEDWhiteLow);
}
}
// The loop routine runs over and over again forever
void loop () {
//What is the time now?
DateTime now = rtc.now();
delay (20);
minutes = now.hour() * 60 + now.minute(); //Compute the number of minutes since 0:00
delay (20);
//BLUE RAMP UP
if (minutes >= ((onHour * 60) + onMin) && minutes <= ((onHour * 60) + onMin + rampPeriod)) {
blueLevel = map(minutes,(onHour * 60) + onMin,((onHour * 60) + onMin + rampPeriod),LEDBlueLow,LEDBlueHigh);
analogWrite (LED2, blueLevel);
delay(20);
}
//BLUE RAMP DOWN
if (minutes >= ((offHour * 60) + offMin - rampPeriod) && minutes <= ((offHour * 60) + offMin)) {
blueLevel = map(minutes,(offHour * 60) + offMin - rampPeriod,(offHour * 60) + offMin,LEDBlueHigh,LEDBlueLow);
analogWrite (LED2, blueLevel);
delay(20);
}
//WHITE RAMP UP
if (minutes >= ((onHour * 60) + onMin + whiteDelay) && minutes <= ((onHour * 60) + onMin + rampPeriod + whiteDelay)) {
whiteLevel = map(minutes,(onHour * 60) + onMin + whiteDelay,((onHour * 60) + onMin + rampPeriod + whiteDelay),LEDWhiteLow,LEDWhiteHigh);
analogWrite (LED1, whiteLevel);
analogWrite (LED3, whiteLevel);
delay(30);
}
//WHITE RAMP DOWN
if (minutes >= ((offHour * 60) + offMin - rampPeriod - whiteDelay) && minutes <= ((offHour * 60) + offMin - whiteDelay)) {
whiteLevel = map(minutes,(offHour * 60) + offMin - rampPeriod - whiteDelay,(offHour * 60) + offMin - whiteDelay,LEDWhiteHigh,LEDWhiteLow);
analogWrite (LED1, whiteLevel);
analogWrite (LED3, whiteLevel);
delay(30);
}
//Print the lighting levels and number of minutes to the serial monitor for troubleshooting
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Serial.print(minutes);
Serial.println();
Serial.print(blueLevel);
Serial.print(" BLUE"
;
Serial.print(whiteLevel);
Serial.print(" WHITE"
;
Serial.println();
//
delay(50);
}</pre>