My DIY Led light... dive in! experience, knowledge and inputswelcome

Nice Job, I am in the process of the same DIY project. A question for you or anybody: I see you have long heatsinks like mine. What do you do over the glass support brace. Mine is about 7-8inches wide, The LEDs will be about 4-6 inches above it. Just keep the partern going across brace? Any help would be great.
Daka

I see you are using an ARDUINO too, would be interest in the code and what it does. I have started to work on the code, but any help in this area would be great too.
 
I don't know what other peopledo about the braces... My tank only has a small aluminum support (1") so I just kept the pattern going I would do this for any tank but or example I'm helping a friend with his build and he decided to not place any LEDs over the brace so hell have two clusters of LEDs...

I'm still not done with the code but hopefully I'll be done today and I'll post it, I'm not an expert on the subject so it goin to be very simple
 
what to do about the glass brace

what to do about the glass brace

Thanks for the come back. I think I will just keep on going with patern unless someone has a great reason not too.
I am going to try to have the following in the light code. I think it is in many places ,just have to put it all together.
Sunrise, sunset, lunar, clouds and lighting. There is even some people that load information from a certain area by log and lat. and use that data....
I would like to see your code. When I have full working set I will post it. I have a thread going about my progress of a rebuild of a 90 gal tank. Being a noobie I tought I may get some pointer along the way and maybe , help some other noobies.
Thanks again
 
Im a newbie too! Im just going to have sunrise/sunset and LCD display... I hope to add lunar function some time soon!
 
Last edited:
Here go some more pics! the fixture is now in place... Dont know about the corals but I love it! Im only missing the arduino, right now its just controlled via timers... I have the lights running @300mA (all), Ill ramp them to 50% this weekend to acclimate the corals...

Testing:
IMG_1436.jpg


Two stories high:
IMG_1439.jpg


everything wired up:
IMG_1441.jpg


Green Fans... hehe the lowest dB i could find
IMG_1443.jpg
IMG_1444.jpg


FTS lights @300mA

n2.jpg

n23.jpg
 
Nice Job, I am in the process of the same DIY project. A question for you or anybody: I see you have long heatsinks like mine. What do you do over the glass support brace. Mine is about 7-8inches wide, The LEDs will be about 4-6 inches above it. Just keep the partern going across brace? Any help would be great.
Daka

I see you are using an ARDUINO too, would be interest in the code and what it does. I have started to work on the code, but any help in this area would be great too.

I built mine and split my long 23" heatsink into 2 sections for my 30" long tank. You could skip 2-3" in the center and leave it without LEDs. My theory was because my DIY was very close to the top of tank (2" about), most of the lights in that area would be totally blocked and waisted.
It would be easy to just leave a tiny space and get most of the light from those LEDs.
 
Just finished installing the arduino... I'm having some trouble with the HLG18542B drivers, I followed kcress advice from another forum and added a 1K resistor between the dim + and - wires, but I with a PWM value of 255 I only get 450mA in the 4x blue strings and 600mA in the 3x white strings... Without the resistor the values max out and only have like 200mA play, so it goes from 1.1A in the blues to a min of 850mA

For now I'll leave it like that but I could use some help to get this working, right now I want to acclimate the corals so low currents are better...

I hope I can get this fixed by next week...

Thanks for any input
 
Ah.. You're using the transistor in emitter follower mode. The value you're getting out of the emitter is correct.

Why don't you try this instead:

Hook the emitter to ground and DIM-
Hook the 1k ohm resistor to the DIM+
Hook the collector to the other end of the 1k resistor.

Now when you send the 5V via the base resistor to the transistor the transistor will be ON essentially putting a 1k resistor across the MW leads - maximum dimming. When the transistor is OFF it leaves the MW leads open and the Meanwell at full output.

That should be very effective. Your code needs to invert the sense of the PWM. e.g. 0% duty cycle equals full brightness and 100% duty cycle equals full dimming.

Remember the MW is providing 10V OUT OF IT'S DIM+ lead. For less light you need to bleed this off with something. You don't want to supply power/voltage to this weirdo input. That trips up everyone.
 
Last edited:
Thanks!

Thanks!

Hi Kcress! Thanks for your help!!

Here are some schematics for you to look at... Let me know if I should make the change as you mention in your post... Im guessing you know whats going on which gives me hope hehe because I did not know what was going on, thanks for reading the thead and helping out!

some pics...

Rough schematic, I made it in like 15min and didnt really look fot the correct parts so please disregard the part numbers...

schematics.png


and here is the live deal, next is the 10V regulated circuit, PWM is working good, its the same circuit for both transistors... If you read the thread Im running a 3rd ELN driver but since Im maxing it out @350mA a 5V PWM is enough and is wired directly from the arduino...

Realschematic.png


DIM block, first input is the +10v PWM signal is for the 4x blue strings, 2 input is the ground which is being bridged and shared across, 3 input is the +10v PWM signal for the 3x white strings... 4th is a shared ground... 5th is the PWM signal direct from the arduino for the ELN driver and 6th is the ground...

DIMBlock.png


Ah.. You're using the transistor in emitter follower mode. The value you're getting out of the emitter is correct.

Why don't you try this instead:

Hook the emitter to ground and DIM-
Hook the 1k ohm resistor to the DIM+
Hook the collector to the other end of the 1k resistor.

Now when you send the 5V via the base resistor to the transistor the transistor will be ON essentially putting a 1k resistor across the MW leads - maximum dimming. When the transistor is OFF it leaves the MW leads open and the Meanwell at full output.

That should be very effective. Your code needs to invert the sense of the PWM. e.g. 0% duty cycle equals full brightness and 100% duty cycle equals full dimming.

Remember the MW is providing 10V OUT OF IT'S DIM+ lead. For less light you need to bleed this off with something. You don't want to supply power/voltage to this weirdo input. That trips up everyone.
 
would this schematic represent what you said Kcress? or should I also share the grounds, from DIM- and arduino?

option 1:
SolutionKeith.png


option 2:
solutionkeith2.png
 
Ok! thanks Kcress! ill change the logic in the programming and rewire tomorrow.... Ill post the results,

Thanks again
 
Kcress! it worked like charm! I can go very low on the amps, superdim and max out the drivers as well! I used the code from katchupoy which you can find here n case some one needs it: https://sites.google.com/site/caddnima/myreeftank/led_controller/arduinosketch

its a great code, I only changed the max values of the arrays and fade functions so that it was inverted and added an extra PWM output with regular logic for the ELN driver, for now I maxed out the blues @580mA and whites @500mA just to acclimate the corals... last week they ran @350mA so Im slowly bringing them up... if someone is going to build with HLG drivers you can check the shematics above and let me know if you need the code...

The idea from Kcress is great because I do not need 10v, the arduino 5v PWM is all it needs, Im only worried about the life expectancy of the transistors since they will be running @full PWM cycle most of the day... (at night)... I guess time will tell, maybe I'll add a couple of lines to turn the PWM to 0 at night when the timers power off the drivers...
 
ok... I added the conditional to turn off all PWMs at night, and with the timers powering off the drivers everything should work... Ill double check voltages at night anyway
 
Grrreat! Thanks for the feedback.

You cannot "wear out" the transistors. PWMing them won't bother them in the least. Since we're talking maximum dimming which means maximum PWM duty cycle, i.e. 100% ON, you should not actually ever be turning the transistor OFF. So you won't be cycling them anyway - not that it matters. :)
 
Ok! Thanks Kcress! I removed the conditional just to avoid something happen and have 100% brightness in the middle of the night... Right now to achieve 0% I have them on timers but Im going to add some relays to switch everything off probably next week...

For now I wanted to add Im really enjoying the LEDs, the tank looks amazing in person, hopefully the corals will feel the same way!
 
Hopefully Final Arduino Code

Hopefully Final Arduino Code

Code:
#define DS1307_I2C_ADDRESS 0x68   // address used for clock
#include "Wire.h"                 // library used for I2C
#include <LiquidCrystal.h>        // library used
#include <avr/wdt.h>              //watchdog timer to avoid infinite loop



/* ******************************************************************************************************************** */
/* *                                                                                                                  * */
/* *                                 R E L A Y   P A R T                                                              * */
/* *                                 S I M P L E   O N   A N D   O F F   F E A T U R E                                * */
/* *                                                                                                                  * */
/* ******************************************************************************************************************** */


const int relayPin1 =  9;         // arduino pin (non pwm) used for wavemaker    

int relayState1 = LOW;             
int fans = 8; //Fans
int driver1 = 0; //Driver
int driver2 = 1; // Driver

long previousMillis1 = 0;        

long interval1 = 15000;           // how many milliseconds to turn it on and off for RELAY1

//TEMP Variables
float tempC;
int reading;
int tempPin = A0;               //analog pin where the LM35 datapin is connected
int mt = 55;                    //max temp if over this value the lights will shutdown
const int numReadings = 40;     //num of reading for average value
int readings[numReadings];      // the readings from the analog input
int index = 0;                  // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average

/* ******************************************************************************************************************** */
/* *                                                                                                                  * */
/* *                                 L E D   D I M M I N G   P A R T                                                  * */
/* *                                 F A D E S   I N   A N D   O U T                                                  * */
/* *                                                                                                                  * */
/* ******************************************************************************************************************** */



/* ********************************************************************************* */
/* *     									   * */
/* *     Note: time for ramp down is the same as time for ramp up.                 * */
/* *     									   * */
/* ********************************************************************************* */
int ontime =7;   // what time do you want the blue to start to ramp up?
int night = 19;
int blueramptime = 60 ;           // how many minutes do you want the blue to ramp up?
int whiteramptime = 120 ;         // after the blue, how many minutes do you want the white to ramp up?
int photoperiod = 360 ;           // after the white, how many minutes do you want it to stay at max intensity?
int blue = 3;                     // which arduino pwm pin are you using for the blue?
int white = 10;                   // which arduino pwm pin are you using for the white?
int var = 11;                    //third PWM

int bluemin = 255 ;      //inverted logic    
int whitemin = 255 ; 
int varmin = 0 ;  //regular logic


int bluepercent[11] = { 255, 240, 225, 210, 195, 180, 165, 150, 135, 120, 105 }; //inverted for PWM
int whitepercent[11] = { 255, 242, 229, 216, 203, 190, 177, 164, 151, 138, 125 };  
int varpercent[11] = { 0, 26, 52, 78, 103, 128, 154, 180, 205, 230, 255 };  //regular for PWM


LiquidCrystal lcd(12, 13, 4, 5, 6, 7);   
                                         



/* ******************************************************************************************************************** */
/* *                                                                                                                  * */
/* *                                 R T C   C L O C K   D S 1 3 0 7                                                  * */
/* *                                                                                                                  * */
/* ******************************************************************************************************************** */
byte decToBcd(byte val)           // Convert normal decimal numbers to binary coded decimal
{
  return ( (val/10*16) + (val%10) );
}


byte bcdToDec(byte val)           // Convert binary coded decimal to normal decimal numbers
{
  return ( (val/16*10) + (val%16) );
}

                                  // 1) Sets the date and time on the ds1307
                                  // 2) Starts the clock
                                  // 3) Sets hour mode to 24 hour clock
                                  // Assumes you're passing in valid numbers

void setDateDs1307(byte second,   // 0-59
byte minute,                      // 0-59
byte hour,                        // 1-23
byte dayOfWeek,                   // 1-7
byte dayOfMonth,                  // 1-28/29/30/31
byte month,                       // 1-12
byte year)                        // 0-99
{
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(0);
  Wire.write(decToBcd(second));    // 0 to bit 7 starts the clock
  Wire.write(decToBcd(minute));
  Wire.write(decToBcd(hour));      // If you want 12 hour am/pm you need to set
                                  // bit 6 (also need to change readDateDs1307)
  Wire.write(decToBcd(dayOfWeek));
  Wire.write(decToBcd(dayOfMonth));
  Wire.write(decToBcd(month));
  Wire.write(decToBcd(year));
  Wire.endTransmission();
}

                                  // Gets the date and time from the ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  // Reset the register pointer
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(0);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  // A few of these need masks because certain bits are control bits
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f); // Need to change this if 12 hour am/pm
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}



/* ******************************************************************************************************************** */
/* *                                                                                                                  * */
/* *                                 D E F I N E  :  O N E S E C O N D                                                * */
/* *                                                                                                                  * */
/* ******************************************************************************************************************** */

void onesecond() //function that runs once per second while program is running
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  lcd.setCursor(0, 0);
  if(hour>0)
  {
    if(hour<=12)
    {
      lcd.print(hour, DEC);
    }
    else
    {
      lcd.print(hour-12, DEC);
    }
  }
  else
  {
    lcd.print("12");
  }
  lcd.print(":");
  if (minute < 10) {
    lcd.print("0");
  }
  lcd.print(minute, DEC);
  lcd.print(":");
  if (second < 10) {
    lcd.print("0");
  }
  lcd.print(second, DEC);
  if(hour<12)
  {
    lcd.print("am");
  }
  else
  {
    lcd.print("pm");
  }
  lcd.print(" ");
  wdt_reset(); //every second bite back, to let the arduino know everything is running
  temperature(); //always check temp
  delay(1000);
}


//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  D E F I N E  :  L U N A R P H A S E |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

void moonPhase(int year, int month, int day)
{
  int ml[29] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,13,12,11,10,9,8,7,6,5,3,2,0}; //PWM values for moonlight channel, where 15 is FULL MOON

  int Y = (year-2000);
  int R = Y%19;
  int N = R-19;
  int n = N*11;

  while (n > 29 || n < -29){
    
    if (n > 29 && n > 0){
      n = n-30;
    }
    if (n < -29 && n < 0){
      n = n + 30;
    }
  }
  
  int t = n + day + month;
  int P = abs(t - 8); // current MoonPhase from 0-29, where 15 is full moon
  
  if ( ((P >= 0) && (P <= 3)) || ((P >= 26) && (P <= 29))){		//new moon 
       analogWrite(var, ml[P]);
       lcd.setCursor(11,0);
       lcd.print("NM:");
       lcd.print(P);
  }
  else if ( ((P >= 4) && (P <= 7)) || ((P >= 23) && (P <= 25)) ){	//cresent
       analogWrite(var, ml[P]);
       lcd.setCursor(11,0);
       lcd.print("CM:");
       lcd.print(P);
  }
  else if ( ((P >= 8) && (P <= 11)) || ((P >= 19) && (P <= 22)) ){	//half moon
       analogWrite(var, ml[P]);
       lcd.setCursor(11,0);
       lcd.print("HM:");
       lcd.print(P);
   }
   else if ( ((P >= 12) && (P <= 15)) || ((P >= 16) && (P <= 19)) ){	//gibbous //full moon is full intensity 
       analogWrite(var, ml[P]);
       lcd.setCursor(11,0);
       lcd.print("FM:");
       lcd.print(P);
   }
    else  {                                                            //in case it doesnt find a case, show on LCD to correct code
       analogWrite(var, 0);
       lcd.setCursor(11,0);
       lcd.print("NIGHT");
   }
   
}
  
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  D E F I N E  :  T E M P E R A T U R E |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
void temperature() //checks the LM35 temp and averages to smooth the value
{
  reading = analogRead(tempPin);
  tempC = reading / 9.31;
  total= total - readings[index];
  readings[index] = tempC;
  total= total + readings[index]; 
  index = index + 1;
  
  if (index >= numReadings) index = 0;
  average = total / numReadings;
  
  lcd.setCursor(12,1);
  lcd.print("T:");
  lcd.print(average);
}

/* ******************************************************************************************************************** */
/* *                                                                                                                  * */
/* *                                 D E F I N E  :  R E L A Y 1                                                      * */
/* *                                                                                                                  * */
/* ******************************************************************************************************************** */

void relay1()  			                //FUNCTION TO TURN ON AND OFF RELAY 1.
{ 
  
  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis1 > interval1) 
  { 
    previousMillis1 = currentMillis;   
    if (relayState1 == LOW){
      relayState1 = HIGH;
    }
    else
      relayState1 = LOW;
      digitalWrite(relayPin1, relayState1);
  }
}

/* ******************************************************************************************************************** */
/* *                                                                                                                  * */
/* *                                 S E T U P                                                                        * */
/* *                                                                                                                  * */
/* ******************************************************************************************************************** */

void setup() {
  pinMode(relayPin1, OUTPUT);     // set the digital pin as output:
  pinMode(fans, OUTPUT); 
  pinMode(driver1, OUTPUT);    
  pinMode(driver2, OUTPUT); 
  wdt_enable(WDTO_2S); //watchdog timer value is set for 2 seconds, if the main loop doesnt complete in 2 seconds the arduino will reset
  delay(100);
  analogReference(INTERNAL); //for lm35 reference
  
  for (int thisReading = 0; thisReading < numReadings; thisReading++)
    readings[thisReading] = 0;   


/* ******************************************************************************************************************** */
/* *                                                                                                                  * */
/* *                                 S E T U P - D I S P L A Y                                                        * */
/* *                                                                                                                  * */
/* ******************************************************************************************************************** */

  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  Wire.begin();
  second = 0;
  minute = 50;
  hour = 22;
  dayOfWeek = 6;  		              // Sunday is 0
  dayOfMonth = 19;
  month = 01;
  year = 13;


/* ********************************************************************************* */
/* *                                                                               * */
/* *     this is where you set your time...                                        * */
/* *     1) change the second, minute, hour, etc above                             * */
/* *     2) remove // below                                                        * */
/* *     3) and load this sketch to your arduino                                   * */
/* *     4) after loading the sketch, put the // back again                        * */
/* *     5) and load this sketch again to your arduino, and save                   * */
/* *                                                                               * */
/* ********************************************************************************* */
//setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);


  analogWrite(blue, bluemin);
  analogWrite(white, whitemin);
  analogWrite(var, varmin);
  lcd.begin(16, 2); // set up the LCD's number of rows and columns: 
  lcd.setCursor(0, 1);
  lcd.print("B:S");
  lcd.print(0);
  lcd.setCursor(5, 1);
  lcd.print("W:S");
  lcd.print(0); 
 
  digitalWrite(fans, HIGH); //inverted logic HIGH=OFF
  digitalWrite(driver1, HIGH);
  digitalWrite(driver2, HIGH);

delay(1000);

  
}






/* ******************************************************************************************************************** */
/* *                                                                                                                  * */
/* *                                 L O O P                                                                          * */
/* *                                                                                                                  * */
/* ******************************************************************************************************************** */




void loop()
{
  onesecond();
  temperature();
  relay1();
  lcd.setCursor(0, 1);
  lcd.print("B:");
  lcd.setCursor(5, 1);
  lcd.print("W:");
  

/* ******************************************************************************************************************** */
/* *                                                                                                                  * */
/* *                                 L O O P - D I M   F U N C T I O N                                                * */
/* *                                                                                                                  * */
/* ******************************************************************************************************************** */

  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  int daybyminute = ((hour * 60) + minute); //converts time of day to a single value in minutes
      

  int bluerampup;
     if (daybyminute >= (ontime*60)) 
       bluerampup = (((ontime*60) + blueramptime) - daybyminute);
     else
       bluerampup = blueramptime;
       
  int whiterampup;
    if (daybyminute >= (ontime*60 + blueramptime)) 
       whiterampup = (((ontime*60) + blueramptime + whiteramptime) - daybyminute);
     else
       whiterampup = whiteramptime;

  int whiterampdown;
    if (((ontime * 60) + photoperiod + blueramptime + whiteramptime) <= daybyminute)
      whiterampdown = (((ontime*60) + photoperiod + blueramptime + 2*whiteramptime) - daybyminute);
    else
      whiterampdown = whiteramptime;
      
  int bluerampdown;
    if (((ontime * 60) + photoperiod + blueramptime + 2*whiteramptime) <= daybyminute)
      bluerampdown = (((ontime*60) + photoperiod + 2*blueramptime + 2*whiteramptime) - daybyminute);
    else
      bluerampdown = blueramptime;



/* ******************************************************************************************************************** */
/* *                                                                                                                  * */
/* *                                 L O O P - F A D E  I N                                                           * */
/* *                                                                                                                  * */
/* ******************************************************************************************************************** */
if (average < mt){
 if (daybyminute >= (ontime*60))
  { 
    if (daybyminute <= ((ontime*60) + blueramptime + (whiteramptime - 1))) //if time is in range of fade in, start fading in + (whiteramptime/10*9)
    {
      
      digitalWrite(fans, LOW);
      digitalWrite(driver1, LOW);
      digitalWrite(driver2, LOW);
      
      // fade blue LEDs in from min to max.
      lcd.setCursor(11,0);
      lcd.print(" ");  
      lcd.print("RISE");
      for (int i = 1; i <= 10; i++) // setting ib value for 10% increment. Start with 0% 
      { 
          analogWrite(blue, bluepercent[i]);
          analogWrite(var, varpercent[i]); 
          lcd.setCursor(2, 1);
          lcd.print(i);
          lcd.print(" "); 
          lcd.setCursor(7, 1);
          lcd.print("0");
        
          int countdown = ((bluerampup*60)/10); // calculates seconds to next step
          while (countdown>0)
          {
          onesecond(); // updates clock once per second
          temperature();
          countdown--;
          relay1();
        }
      }      

      // fade white LEDs in from min to max.
      for (int i = 1; i <= 10; i++) // setting i value for 10% increment. Start with 0%
      { 
          analogWrite(white, whitepercent[i]); 
          lcd.setCursor(7, 1);
          lcd.print(i);
          lcd.print(" "); 
          lcd.setCursor(2, 1);
          lcd.print("10");
          int countdown = ((whiterampup*60)/10); // calculates seconds to next step
          while (countdown>0)
          {
            onesecond(); // updates clock once per second
            temperature();
            countdown--;
            relay1();
        }
      } 
    }
  }
}

  
/* ******************************************************************************************************************** */
/* *                                                                                                                  * */
/* *                                 L O O P - M A X  V A L U E                                                       * */
/* *                                                                                                                  * */
/* ******************************************************************************************************************** */

if (average < mt){
 if (daybyminute >= ((ontime * 60) + blueramptime + whiteramptime)) 
  { 
    if ( daybyminute <= ((ontime * 60) + blueramptime + whiteramptime + photoperiod)) // if time is in range of photoperiod, turn lights on to maximum fade value
    {

      
        digitalWrite(fans, LOW);
        digitalWrite(driver1, LOW);
        digitalWrite(driver2, LOW);
    
        lcd.setCursor(11,0);
        lcd.print(" "); 
        lcd.print(" "); 
        lcd.print("MAX");
        
        analogWrite(blue, 105);
        analogWrite(var, 255);
        lcd.setCursor(2, 1);
        lcd.print(10);
        lcd.print(" ");
        analogWrite(white, 125); 
        lcd.setCursor(7, 1);
        lcd.print(10);
        lcd.print(" "); 
        
        temperature();
      
    } 
  }
}

/* ******************************************************************************************************************** */
/* *                                                                                                                  * */
/* *                                 L O O P - F A D E  O U T                                                         * */
/* *                                                                                                                  * */
/* ******************************************************************************************************************** */

if (average < mt){
  if (((ontime * 60) + photoperiod + blueramptime + whiteramptime) <= daybyminute)
  { 
    if (((ontime * 60) + photoperiod + whiteramptime + 2*blueramptime + (blueramptime/10*9)) >= daybyminute)
    {
     
      
      digitalWrite(fans, LOW);
      digitalWrite(driver1, LOW);
      digitalWrite(driver2, LOW);
   
      lcd.setCursor(11,0);
      lcd.print(" "); 
      lcd.print(" "); 
      lcd.print("SET");
      
      // fade white LEDs out from max to min in increments of 1 point:
      for (int i = 10; i >= 0; i--) // setting i value for 10% increment. Start with 10%
      { 
        analogWrite(blue, 52);
        analogWrite(var, 255);
        lcd.setCursor(2, 1);
        lcd.print(10);
        lcd.print(" "); 
        
        analogWrite(white, whitepercent[i]); 
        lcd.setCursor(7, 1);
        lcd.print(i);
        lcd.print(" ");  

        int countdown = ((whiterampdown*60)/10); // calculates seconds to next step
        while (countdown>0)
        {
          onesecond(); // updates clock once per second
          temperature();
          countdown--;
          relay1();
        }

      } 

      // fade blue LEDs out from max to min in increments of 1 point:
      for (int i = 10; i >= 0; i--) // setting i value for 10% increment. Start with 10%
      { 
        analogWrite(blue, bluepercent[i]);
        analogWrite(var, varpercent[i]);
        lcd.setCursor(2, 1);
        lcd.print(i);
        lcd.print(" ");
        lcd.setCursor(7, 1);
        lcd.print("0");
        lcd.print(" "); 

        int countdown = ((bluerampdown*60)/10); // calculates seconds to next step
        while (countdown>0)
        {
          onesecond(); // updates clock once per second
          temperature();
          countdown--;
          relay1();
        }
      }
    } 
  }
}

Here is what I hope a final code.... it has 3 PWM channels, blues, whites, and various colors... also integrates a max temp for the LEDs or tank and a function that calculates the current moon phase based on the date..

for my build I used the var channel for the moonlights, it would be nicer to have a different channel with just a couple of LEDs...


:bounce1:
 
Chunk of code missing... didnt fit in one post

Chunk of code missing... didnt fit in one post

Code:
/* ******************************************************************************************************************** */
/* *                                                                                                                  * */
/* *                                           N I G H T                                                              * */
/* *                                                                                                                  * */
/* ******************************************************************************************************************** */

   if((daybyminute >= ((night * 60) + 15)) || (((ontime*60) - 2) >= daybyminute)) {          
 
          digitalWrite(fans, HIGH);
          digitalWrite(driver1, HIGH);
          digitalWrite(driver2, HIGH);
          analogWrite(blue, 255);
          analogWrite(white, 255);

          lcd.setCursor(2, 1);
          lcd.print("N");
          lcd.print(" ");
          lcd.setCursor(7, 1);
          lcd.print("N");
          lcd.print(" "); 
          onesecond(); // updates clock once per second
          relay1(); 
          temperature(); 
          moonPhase(year, month, dayOfMonth);

  
    }
    
    if(average > mt) {   //shutdown lights and leave fans ON, in order to reduce temp
      
          digitalWrite(fans, LOW);
          digitalWrite(driver1, HIGH);
          digitalWrite(driver2, HIGH);
          analogWrite(blue, 255);
          analogWrite(white, 255);
          analogWrite(var, 0);
          lcd.setCursor(11,0);
          lcd.print(" "); 
          lcd.print("HOT!");
          lcd.setCursor(2, 1);
          lcd.print("H!");
          lcd.setCursor(7, 1);
          lcd.print("H!");
          temperature();                //keep checking the temp
          relay1();
          onesecond();
    }
    
  }  // END LOOP
 
Back
Top