The Planted Tank Forum banner

Calling all DIY LED "Junkies" - Your opinions wanted!

41K views 155 replies 22 participants last post by  O2surplus 
#1 ·
I was bored to death at work today, so I designed this just to keep my brain busy and pass the time. It's a 4 channel LED driver- that's very similar to ones that I built in the past, but with a new twist. I integrated a micro-controller/ real time clock into the design that will allow full programmable control of each channel. The controller features an I2C connection that will enable multiple driver boards to be connected together to communicate with, and act as slaves to a "master controller," or simply wired up to leds and left to run a user defined LED dimming "sketch". The controller is programmed using the standard ARDUINO IDE. I see this design being a really great way to have high resolution control over large groups of leds, or as a "stand alone" driver contoller for Nano Tank led builds. I personally have 90 leds over my tank being driven and controlled in groups of 30. This set up leaves me with only 3 channels of control. If I built this design, I'd have 15 channels of control to play with and be able to create seriously high resolution dimming and other lighting effects. Does anyone else see a value to this design? Thoughts?

Here's a photo/schematic of the driver


 
See less See more
1
#124 ·
one quick question about your drawing. i plan on wiring the red wires to the positive side of the led emitters and the black to the negative side at the end of the string. is this correct? also will the drive work at all without the programming. i would like to see if it will come on even if the dimming doesnt work. i am still waiting on my usb adaptor so i can input the programming.
 
#125 ·
Yes, RED = Positive, BLACK = Negative. You can turn on the individual driver chips by connecting their respective PWM connection to the 5V OUTPUT screw terminal.
 
#126 ·
ok all hooked up but no light so i obviously have a short or bad connection somewhere. will try to get it up and lit this weekend. will play with my meter and see where ive gone wrong. hopefully will be able to show pics of it lit up and over the viv soon. thanks again for getting back to me so quickly.
 
#127 ·
Hello,

I am françai to sadden for my anglai

Would be it possible d utilser this card(map) just for 240 led 3w piloted by a signal pwm and the whole fed by an alim atx 480w any controlé by the arduino?
I just want to feed led 3w 700ma the rest is deja piloted by the arduino

Thank you in advance for your reponce
 
#128 ·
Well Guys, I was messing around with my tank today and had to remove the lighting to gain access. When got everything back together and reconnected the power I noticed something weird. Two out of the three SmartyCats would not turn the leds back on. I rechecked all my connections and could find nothing wrong, so I figured the problem had to be internal to the SmartyCats themselves. I connected them to my PC and soon found that the System time had been reset to an earlier time? I did some further checks and found that the DS1307 RTC's weren't keeping time with the power interrupted. After another hour or so of trouble shooting, this is what I found- There's a defect in the PCB at the DS1307 RTC. Pin #7(SQW), which should have been left "floating" according to the schematic and PCB design files, is in reality grounded . This defect was not caught at the PCB factory and may be present in some of the SmartyCat's that some of you are using. I found the same defect in 2 more of the units that I haven't even built yet.
If any of you guys notice the same problem with the clock, here's the fix- Remove Pin#7 from the DS1307 and the problem will be fixed. I used a fine point soldering iron to heat the pin and a small jeweler's screw driver to lift the pin from it's pad. Here's a photo-



If your unit suffers from this defect and you can't tackle the repair yourself, send me a PM and we'll make other arrangements.
 
#129 ·
ok i have gotten all 3 strings to light up using the 5 volt as the dimming input so the wiring on the strings is now correct. this is the first time i have ever used and ardino and i am confused. i have placed the following files into the libraray file on the ardino, ds1307 cpp file, ds1307 o file, ds1307.h, timer1, but i dont know how to get them to compile. i read the part about restarting the ardino IDE but i dont know how to do that. my red blink button is blinking so there is something going on in there. also i dont know where to go into to do the setting of the timers on the dimmers. thanks in advance, hopefully i will get this thing up and running within the week so i can post some pics.
 
#131 ·
The Libraries don't need to be compiled Per Se. Just insert them into the "Libraries" folder first and then restart the Arduino IDE. The actual program"Sketch" that you're using will reference the needed libraries during the compiling process and pull in the needed information.
Since you're just getting started with Arduino programming, Try some of the simpler programs first, like "blink" ( that's the code that I left running on the unit that you have) The red led is tied to digital pin 13 and that pin is currently programmed to "blink". You can always edit the "Blink" code to add more pins like I've done here. Try this code-
Code:
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain. This copy has been modified to test all 6 PWM output pins.
 */

void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(3, OUTPUT);     
  pinMode(5, OUTPUT); 
  pinMode(6, OUTPUT); 
  pinMode(9, OUTPUT); 
  pinMode(10, OUTPUT); 
  pinMode(11, OUTPUT); 
}

void loop() {
  digitalWrite(3, HIGH);   // set the LED on
  digitalWrite(5, HIGH);   // set the LED on
  digitalWrite(6, HIGH);   // set the LED on  
  digitalWrite(9, HIGH);   // set the LED on 
  digitalWrite(10, HIGH);   // set the LED on 
  digitalWrite(11, HIGH);   // set the LED on
  
  delay(1000);              // wait for a second
  digitalWrite(3, LOW);    // set the LED off
  digitalWrite(5, LOW);    // set the LED off 
  digitalWrite(6, LOW);    // set the LED off 
  digitalWrite(9, LOW);    // set the LED off
  digitalWrite(10, LOW);    // set the LED off 
  digitalWrite(11, LOW);    // set the LED off
  
  delay(1000);              // wait for a second
}
When you've conquered this- try some of the "fading" code.

Like this-

Code:
/*
 Fade
 
 This example shows how to fade an LED on pin 9
 using the analogWrite() function.
 
 This example code is in the public domain. This copy has been modified to test all 6 PWM output pins.
 
 */
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

void setup()  { 
  // declare pin 9 to be an output:
  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);

} 

void loop()  { 
  // set the brightness of pin 9:
  analogWrite(3, brightness);    
  analogWrite(5, brightness);
  analogWrite(6, brightness); 
  analogWrite(9, brightness); 
  analogWrite(10, brightness); 
  analogWrite(11, brightness); 
  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade: 
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ; 
  }     
  // wait for 30 milliseconds to see the dimming effect    
  delay(30);                            
}
Let me know if you have any trouble with the codes and If needed, I'll custom edit some, with the variables you want, to get your system up and running.
At times it's easier to learn when you already have something working to use as an example.
 
#130 ·
This code is confusing to a newbie!! (That's me, too.) I was finally programming my moonlights and it took me three tries to correctly input the start time. Now it's in there and all is well. I reduced my moonlights to 2 emitters and cranked it waaaay down. Still looks good, and hopefully won't kick up the algae. Last time I had 6 emitters at 700mA. You could see everything but it was really bad for algae.

I'm getting some "stepping" on the dimming, and at the end it doesn't just fade out, it clicks off. Normal? It still looks awesome and it is much more tidy and easy to handle than all the other stuff!

PS- Sorry!I haven't forgotten, O2! Holidays and all, you know. Friday!
 
#132 ·
Well I'm glad to read that you've got it up and running. Unfortunately the "6 channel code" that I provided is very basic and does not provide for High resolution dimming ( Dimming "steps" occur once per minute). That's because not all of the PWM pins have the same performance capabilities. Digital pins "9 & 10" can be used for very high resolution dimming, but you'd be left with only 2 channels of control. Those two pins are what "Sinks" code takes advantage of and the dimming "steps" occur once per second. If you'd like to try his code, just reconfigure the jumper wires to provide the dimming signal from those two pins and upload his code. ( I wish "Sink" were around here, but he hasn't logged in in a long time)
Let me know if you need any additional help with your code and I'll do what I can to help.
 
#133 ·
Soooooo... Stop me if I'm wrong here... I could wire one string through two cats (as in your diagram for skanderson) to increase the output (for some reason the light seems dim, my glosso is reflecting that fact - need a bit more light) and use sink's code to control it, if I run them through 8 and 9? I certainly don't want to burn anything out, so no touchy for me until I understand this better. However, this would let me boost the WW a bit, too. It's looking a little cool for my taste. Oh, tinkering. I do believe I will never stop :)
 
#134 ·
Whoa! Unless your running Cree XM-L's don't attempt to wire up your leds like Skanderson is doing. Your particular leds will not be able to handle the additional current. Have you checked the actual current consumed by your strings? The Cat4101's should be putting out 1000ma if the pots are maxed out. If they're not at 1000ma with the pots maxed then there's another possible reason. The "6 channel code" has the PWM value set at 100, which equates to about 300ma through the leds. Change the 100 to a max of 255 and recheck the current. It should now be at 1000ma and your leds should be a heck of a lot brighter. If you'd like to use "Sinks" code, connect the Cats to digital pins #9 & 10. His code uses PWM values between 0 - 1023. 1023 being Maximum.

Here's the section of the 6 channel code that needs to be modified-

Code:
int oneMax = 255;           // max intensity for this channel. Change if you want to limit max intensity.

int twoMax = 255;           // max intensity for this channel. Change if you want to limit max intensity. 

int threeMax = 255;         // max intensity for this channel. Change if you want to limit max intensity.

int fourMax = 255;          // max intensity for this channel. Change if you want to limit max intensity.

int fiveMax = 255;          // max intensity for this channel. Change if you want to limit max intensity.

int sixMax = 255;           // max intensity for this channel. Change if you want to limit max intensity.
Here's the section of "Sink's" code that has the variables for Max & Min led PWM values.
Code:
/*
 * Light "state" represents the PWM duty cycle for each channel This normally
 * dictates light intensity. It is an array { duty_chan_1, duty_chan_2 }.
 * Possible values for duty cycle are 0 - 1023.
 */
const int kDayState[] = { 1023,1023 }; // daytime LED state
const int kNightState[] = { 0, 0 }; // nighttime LED state
You can always lower the max value of one of the channels to alter the color mix of your lighting. E.g. Run your WW leds at max (1023) and the CW leds at a lower level, say (700). Your lighting will then appear "Warmer".(You can also get the same effect by adjusting the pots on the driver board, if you don't want to mess with the code.Just make sure that the code is set for the maximum PWM value first, so that you can override it with the pot adjustment.)
You can also adjust the KnightState value to a number above 0 to emulate moon lights. Remember 0 = Off, 1 = 1/10 of 1%, and 10= 1% duty cycle.
 
#137 ·
Ha, no problem :) I thought there was something I didn't know going on. I swapped in sink's code, and combined my two WW strings and CW strings so that they can run through the same 2 PWMs. Now I have what I needed: too much light, haha! So, I'm using the analog control to dim the CW as much as possible, and I'll be tinkering with light levels over the next few weeks. I also set up the CW to run as moonlights at night - that's kind of neat: the color is much more agreeable than the royal blues I was using before. I'm just hoping that it doesn't cause too much algae trouble, I'll keep it low and see how it goes.

Now, to see how I can use this bad boy to control my CO2 - I'm SO sick of my mechanical timers getting jammed. Do you know of anyone who has a code/setup for this?
 
#138 ·
Now, to see how I can use this bad boy to control my CO2 - I'm SO sick of my mechanical timers getting jammed. Do you know of anyone who has a code/setup for this?
If all you need to do is activate a solenoid- That's easy. Just use a relay that accepts a 5V control signal. You can then switch the power to your solenoid "on/off" with the addition of a little extra code added to your lighting program. Here's some reading material for you-
Controllable Power Outlet - SparkFun Electronics
 
#139 ·
I've decided to "go back to the drawing board" in an effort to create something new. This little project will be aimed at providing a "one stop solution" for DIY Led lighting that electronics/programming novices can tackle with relative ease. Think- "a DIM4 on steroids" LOL.
I've essentially married the "Typhon" Led controller directly to two different types of led drivers. The controller PCB will mount directly on top of the driver PCB and keep all the "guts" of the led lighting system in one small, tidy arrangement. No programming experience will be needed to make this project work, as it will only need to be programmed once and any further tweaks will be made using the buttons and the LCD interface.


First up is the Controller- It's my version of the "Typhon controller" with 4 channels of lighting control. Each channel can be independently programmed for Start time, end time, Max & Min intensity, ect.. I also include two analog inputs for temp sensing/ PAR measurement, whatever is desired.




Next is the first of two styles of led drivers. The first will contain 4 of the band new Meanwell LDD-H drivers. These drivers can be purchased for less than $10 each and are available with different maximum current ratings up to 1000ma each. They can operate in excess of 48 volts, so long strings of 12 -15 leds are possible. Each of the 4 drivers will take it's dimming signals directly from the controller mounted on top.



The next driver is Based on the National Semi-Conductor LN3409. I designed these drivers to utilize components that will allow them to run led loads up to 60 volts/ 3,000 ma. This design will allow the newer Cree XM-L leds to be run at their Max. Each driver's maximum current output can be custom tailored using the on board trim pot. Since each PCB can only hold 2 LM3409's. The driver PCB will be split to create 2 driver sub boards that will mount under the controller. I include selectable jumpers in the design to allow each driver to be addressable by the controller.



That's it for now- the PCB's needed for this project arrive tomorrow. I'll post some pictures of the finished product after it's put together.
 
#140 ·
Nice. :) I'll be following. Hope to work this into a planned full-spectrum build for my 200 gallon! I won't need the controller, but the LM3409 would be great for either XM-L or 100W chinese chip array build.

I've decided to "go back to the drawing board" in an effort to create something new. This little project will be aimed at providing a "one stop solution" for DIY Led lighting that electronics/programming novices can tackle with relative ease. Think- "a DIM4 on steroids" LOL.

The next driver is Based on the National Semi-Conductor LN3409. I designed these drivers to utilize components that will allow them to run led loads up to 60 volts/ 3,000 ma. This design will allow the newer Cree XM-L leds to be run at their Max. Each driver's maximum current output can be custom tailored using the on board trim pot. Since each PCB can only hold 2 LM3409's. The driver PCB will be split to create 2 driver sub boards that will mount under the controller. I include selectable jumpers in the design to allow each driver to be addressable by the controller.

That's it for now- the PCB's needed for this project arrive tomorrow. I'll post some pictures of the finished product after it's put together.
 
#143 ·
By rough estimate - A controller with 4 MeanWell LDD drivers = $100. The Lm3409 drivers would drive the price up another $30.

I'm in the process of building the first one right now. When I'm done testing it and make any needed changes, I'll post the revised build files along with the Bill of Materials ( with links for purchasing) and the Software.
 
#144 ·
ok been too busy with other projects to mess with the coding and get it working. is there a way that i could download someone elses dimming and timing code to get it up and working. all im looking for is a 1 to2 hour ramp up and down with a 12 hour on/off cycle for all 6 channels. and i will definately be interested in the new build you are putting together. thanks again in advance, steve
 
#145 ·
Here's some code that will get you up and running. Just adjust the variables to your liking and let-her-rip.

Code:
/*
// ATMEG328P-AU Microcontroller LED lighting controller for aquarium use. 
// The programming code uses a DS1307 Real Time clock to set the LED lighting schedule. Current date and time can be accessed with the serial monitor set to 9600 baud.
// sunrise/sunset time,length of fade duration, and the length of the day are selectable via the programmed schedule.  
//  Circuit description
// PWM pins described below connected to dimming circuits on drivers spread among 6 seperate channels.
// DS1307 RTC ( real time clock) connected via I2C protocol.
*/



// Pins to control each channel LEDs. Change these if you're using different pins.

int oneLed = 3;       // LED PWM arduino pin for channel one.

int twoLed = 5;       // LED PWM arduino pin for channel two 

int threeLed = 6;     // LED PWM arduino pin for channel three

int fourLed = 9;      // LED PWM arduino pin for channel four

int fiveLed = 10;     // LED PWM arduino pin for channel five

int sixLed = 11;      // LED PWM arduino pin for channel six


#include <WProgram.h>
#include <DS1307.h> 
// written by  mattt on the Arduino forum and modified by D. Sjunnesson



// Set up RTC

#include "Wire.h"

#define DS1307_I2C_ADDRESS 0x68



// RTC variables

byte second, rtcMins, oldMins, rtcHrs, oldHrs, dayOfWeek, dayOfMonth, month, year;



// Other variables. These control the behavior of lighting. Change these to customize behavior.

int minCounter = 0;         // counter that resets at midnight. Don't change this.



int oneStartMins = 540;     // minute to start channel 1. Change this to the number of minutes past midnight you want to start

int twoStartMins =420;      // minute to start channel 2. Change this to the number of minutes past midnight you want to start                         

int threeStartMins =540;    // minute to start channel 3. Change this to the number of minutes past midnight you want to start 

int fourStartMins =420;     // minute to start channel 4. Change this to the number of minutes past midnight you want to start 

int fiveStartMins =420;     // minute to start channel 5. Change this to the number of minutes past midnight you want to start 

int sixStartMins =420;      // minute to start channel 6. Change this to the number of minutes past midnight you want to start 


int onePhotoPeriod = 720;   // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int twoPhotoPeriod = 960;   // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day                           

int threePhotoPeriod = 720; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int fourPhotoPeriod = 960;  // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int fivePhotoPeriod = 960;  // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int sixPhotoPeriod = 960;   // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day


int fadeDuration = 180;      // duration of the fade on and off for sunrise and sunset. Change
                            
//    this to alter how long the fade lasts.

int oneMax = 255;           // max intensity for this channel. Change if you want to limit max intensity.

int twoMax = 255;           // max intensity for this channel. Change if you want to limit max intensity. 

int threeMax = 255;         // max intensity for this channel. Change if you want to limit max intensity.

int fourMax = 255;          // max intensity for this channel. Change if you want to limit max intensity.

int fiveMax = 255;          // max intensity for this channel. Change if you want to limit max intensity.

int sixMax = 255;           // max intensity for this channel. Change if you want to limit max intensity.

/****** LED Functions ******/

/***************************/

//function to set LED brightness according to time of day

//function has three equal phases - ramp up, hold, and ramp down

void setLed(int mins,    // current time in minutes
            
int ledPin,  // pin for this channel of LEDs
            
int start,   // start time for this channel of LEDs
            
int period,  // photoperiod for this channel of LEDs
            
int fade,    // fade duration for this channel of LEDs
            
int ledMax   // max value for this channel
            
)  {
  
if (mins <= start || mins <= mins > start + period)  {
    
analogWrite(ledPin, 0);
  
}// This is when the led's are off, thus ledVal =0
  
if (mins > start && mins <= start + fade)  {
    
analogWrite(ledPin, map(mins - start, 0, fade, 0, ledMax));
  
}// This is sunrise. Leds slowly brighten to full intensity
    
if (mins > start + fade && mins <= start + period - fade)  {
   
analogWrite(ledPin, ledMax);
  
}//This is when the led's are at maximum intensity
    
if (mins > start + period - fade && mins <= start + period)  {
    
analogWrite(ledPin, map(mins - start - period + fade, 0, fade, ledMax, 0));
  
}// This is sunset. LEDs slowly fade out.

}



/***** RTC Functions *******/

/***************************/

// Convert normal decimal numbers to binary coded decimal

byte decToBcd(byte val)

{
  
return ( (val/10*16) + (val%10) );

}



// Convert binary coded decimal to normal decimal numbers

byte bcdToDec(byte val)

{
  
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.



/* //remove the forward slash and asterisk at the far left to activate the time date setting code




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.send(0);
   
Wire.send(decToBcd(second));
   
Wire.send(decToBcd(minute));
   
Wire.send(decToBcd(hour));
   Wire.send(decToBcd(dayOfWeek));
   
Wire.send(decToBcd(dayOfMonth));
   
Wire.send(decToBcd(month));
   
Wire.send(decToBcd(year));
   
Wire.endTransmission();
     
                             

}

*/ //remove the forward slash and asterisk at the far left to activate the time date setting code



// Gets the date and time from the ds1307 via the I2C protocol.

void getDateDs1307(byte *second,
          
byte *minute,
          
byte *hour,
          
byte *dayOfWeek,
          
byte *dayOfMonth,
          
byte *month,
          
byte *year)

{
  
Wire.beginTransmission(DS1307_I2C_ADDRESS);
  
Wire.send(0);
  
Wire.endTransmission();

  

Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  
*second     = bcdToDec(Wire.receive() & 0x7f);
  
*minute     = bcdToDec(Wire.receive());
  
*hour       = bcdToDec(Wire.receive() & 0x3f);
  
*dayOfWeek  = bcdToDec(Wire.receive());
  
*dayOfMonth = bcdToDec(Wire.receive());
  
*month      = bcdToDec(Wire.receive());
  
*year  = bcdToDec(Wire.receive());

}



void setup()  { 
    


// init I2C  
  
Serial.begin(9600);
  
Wire.begin();
} 
// these functions only occur once.



/***** Main Loop ***********/

/***************************/

void loop() { 

 
 
  

// get time from RTC and put in hrs and mins variables
  
getDateDs1307(&second, &rtcMins, &rtcHrs, &dayOfWeek, &dayOfMonth, &month, &year);
  
minCounter = rtcHrs * 60 + rtcMins;
 
Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true
  
Serial.print(":");
  
Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)
  
Serial.print(":");
  
Serial.print(RTC.get(DS1307_SEC,false));//read seconds
  
Serial.print("      "); // some space for a more happy life
  
Serial.print(RTC.get(DS1307_MTH,false));//read month
  
Serial.print("/");
  
Serial.print(RTC.get(DS1307_DATE,false));//read date
  
Serial.print("/");
  
Serial.print(RTC.get(DS1307_YR,false)); //read year 
  
Serial.println();


//set LED values
  
setLed(minCounter, oneLed, oneStartMins, onePhotoPeriod, fadeDuration, oneMax);
  
setLed(minCounter, twoLed, twoStartMins, twoPhotoPeriod, fadeDuration, twoMax);
  
setLed(minCounter, threeLed, threeStartMins, threePhotoPeriod, fadeDuration, threeMax);
  
setLed(minCounter, fourLed, fourStartMins, fourPhotoPeriod, fadeDuration, fourMax);
 
setLed(minCounter, fiveLed, fiveStartMins, fivePhotoPeriod, fadeDuration, fiveMax);
   
setLed(minCounter, sixLed, sixStartMins, sixPhotoPeriod, fadeDuration, sixMax);
 
// Get ready for next iteration of loop
  
delay(1000);

}
 
#150 ·
I just noticed something in the code, for those that had a hard time with the code.

This is a release note from the arduino app last year.

* The WProgram.h file, which provides declarations for the Arduino API,
has been renamed to Arduino.h. To create a library that will work in
both Arduino 0022 and Arduino 1.0, you can use an #ifdef that checks
for the ARDUINO constant, which was 22 and is now 100. For example:

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
 
#151 ·
ok i pasted it into my ardino oo23. when i try to verify or upload i get the following message/*
// ATMEG328P-AU Microcontroller LED lighting controller for aquarium use.
// The programming code uses a DS1307 Real Time clock to set the LED lighting schedule. Current date and time can be accessed with the serial monitor set to 9600 baud.
// sunrise/sunset time,length of fade duration, and the length of the day are selectable via the programmed schedule.
// Circuit description
// PWM pins described below connected to dimming circuits on drivers spread among 6 seperate channels.
// DS1307 RTC ( real time clock) connected via I2C protocol.
*/



// Pins to control each channel LEDs. Change these if you're using different pins.

int oneLed = 3; // LED PWM arduino pin for channel one.

int twoLed = 5; // LED PWM arduino pin for channel two

int threeLed = 6; // LED PWM arduino pin for channel three

int fourLed = 9; // LED PWM arduino pin for channel four

int fiveLed = 10; // LED PWM arduino pin for channel five

int sixLed = 11; // LED PWM arduino pin for channel six


#include <WProgram.h>
#include <DS1307.h>
// written by mattt on the Arduino forum and modified by D. Sjunnesson



// Set up RTC

#include "Wire.h"

#define DS1307_I2C_ADDRESS 0x68



// RTC variables

byte second, rtcMins, oldMins, rtcHrs, oldHrs, dayOfWeek, dayOfMonth, month, year;



// Other variables. These control the behavior of lighting. Change these to customize behavior.

int minCounter = 0; // counter that resets at midnight. Don't change this.



int oneStartMins = 540; // minute to start channel 1. Change this to the number of minutes past midnight you want to start

int twoStartMins =420; // minute to start channel 2. Change this to the number of minutes past midnight you want to start

int threeStartMins =540; // minute to start channel 3. Change this to the number of minutes past midnight you want to start

int fourStartMins =420; // minute to start channel 4. Change this to the number of minutes past midnight you want to start

int fiveStartMins =420; // minute to start channel 5. Change this to the number of minutes past midnight you want to start

int sixStartMins =420; // minute to start channel 6. Change this to the number of minutes past midnight you want to start


int onePhotoPeriod = 720; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int twoPhotoPeriod = 960; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int threePhotoPeriod = 720; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int fourPhotoPeriod = 960; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int fivePhotoPeriod = 960; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int sixPhotoPeriod = 960; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day


int fadeDuration = 180; // duration of the fade on and off for sunrise and sunset. Change

// this to alter how long the fade lasts.

int oneMax = 255; // max intensity for this channel. Change if you want to limit max intensity.

int twoMax = 255; // max intensity for this channel. Change if you want to limit max intensity.

int threeMax = 255; // max intensity for this channel. Change if you want to limit max intensity.

int fourMax = 255; // max intensity for this channel. Change if you want to limit max intensity.

int fiveMax = 255; // max intensity for this channel. Change if you want to limit max intensity.

int sixMax = 255; // max intensity for this channel. Change if you want to limit max intensity.

/****** LED Functions ******/

/***************************/

//function to set LED brightness according to time of day

//function has three equal phases - ramp up, hold, and ramp down

void setLed(int mins, // current time in minutes

int ledPin, // pin for this channel of LEDs

int start, // start time for this channel of LEDs

int period, // photoperiod for this channel of LEDs

int fade, // fade duration for this channel of LEDs

int ledMax // max value for this channel

) {

if (mins <= start || mins <= mins > start + period) {

analogWrite(ledPin, 0);

}// This is when the led's are off, thus ledVal =0

if (mins > start && mins <= start + fade) {

analogWrite(ledPin, map(mins - start, 0, fade, 0, ledMax));

}// This is sunrise. Leds slowly brighten to full intensity

if (mins > start + fade && mins <= start + period - fade) {

analogWrite(ledPin, ledMax);

}//This is when the led's are at maximum intensity

if (mins > start + period - fade && mins <= start + period) {

analogWrite(ledPin, map(mins - start - period + fade, 0, fade, ledMax, 0));

}// This is sunset. LEDs slowly fade out.

}



/***** RTC Functions *******/

/***************************/

// Convert normal decimal numbers to binary coded decimal

byte decToBcd(byte val)

{

return ( (val/10*16) + (val%10) );

}



// Convert binary coded decimal to normal decimal numbers

byte bcdToDec(byte val)

{

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.



/* //remove the forward slash and asterisk at the far left to activate the time date setting code




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.send(0);

Wire.send(decToBcd(second));

Wire.send(decToBcd(minute));

Wire.send(decToBcd(hour));
Wire.send(decToBcd(dayOfWeek));

Wire.send(decToBcd(dayOfMonth));

Wire.send(decToBcd(month));

Wire.send(decToBcd(year));

Wire.endTransmission();



}

*/ //remove the forward slash and asterisk at the far left to activate the time date setting code



// Gets the date and time from the ds1307 via the I2C protocol.

void getDateDs1307(byte *second,

byte *minute,

byte *hour,

byte *dayOfWeek,

byte *dayOfMonth,

byte *month,

byte *year)

{

Wire.beginTransmission(DS1307_I2C_ADDRESS);

Wire.send(0);

Wire.endTransmission();



Wire.requestFrom(DS1307_I2C_ADDRESS, 7);


*second = bcdToDec(Wire.receive() & 0x7f);

*minute = bcdToDec(Wire.receive());

*hour = bcdToDec(Wire.receive() & 0x3f);

*dayOfWeek = bcdToDec(Wire.receive());

*dayOfMonth = bcdToDec(Wire.receive());

*month = bcdToDec(Wire.receive());

*year = bcdToDec(Wire.receive());

}



void setup() {



// init I2C

Serial.begin(9600);

Wire.begin();
}
// these functions only occur once.



/***** Main Loop ***********/

/***************************/

void loop() {





// get time from RTC and put in hrs and mins variables

getDateDs1307(&second, &rtcMins, &rtcHrs, &dayOfWeek, &dayOfMonth, &month, &year);

minCounter = rtcHrs * 60 + rtcMins;

Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true

Serial.print(":");

Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)

Serial.print(":");

Serial.print(RTC.get(DS1307_SEC,false));//read seconds

Serial.print(" "); // some space for a more happy life

Serial.print(RTC.get(DS1307_MTH,false));//read month

Serial.print("/");

Serial.print(RTC.get(DS1307_DATE,false));//read date

Serial.print("/");

Serial.print(RTC.get(DS1307_YR,false)); //read year

Serial.println();


//set LED values

setLed(minCounter, oneLed, oneStartMins, onePhotoPeriod, fadeDuration, oneMax);

setLed(minCounter, twoLed, twoStartMins, twoPhotoPeriod, fadeDuration, twoMax);

setLed(minCounter, threeLed, threeStartMins, threePhotoPeriod, fadeDuration, threeMax);

setLed(minCounter, fourLed, fourStartMins, fourPhotoPeriod, fadeDuration, fourMax);

setLed(minCounter, fiveLed, fiveStartMins, fivePhotoPeriod, fadeDuration, fiveMax);

setLed(minCounter, sixLed, sixStartMins, sixPhotoPeriod, fadeDuration, sixMax);

// Get ready for next iteration of loop

delay(1000);

all that is in red under a message that says RTC was not declared in this scope . what am i doing wrong? thanks again for the help.
 
#152 ·
ok i pasted it into my ardino oo23. when i try to verify or upload i get the following message/*
Code:
// ATMEG328P-AU Microcontroller LED lighting controller for aquarium use. 
// The programming code uses a DS1307 Real Time clock to set the LED lighting schedule. Current date and time can be accessed with the serial monitor set to 9600 baud.
// sunrise/sunset time,length of fade duration, and the length of the day are selectable via the programmed schedule.  
//  Circuit description
// PWM pins described below connected to dimming circuits on drivers spread among 6 seperate channels.
// DS1307 RTC ( real time clock) connected via I2C protocol.
*/



// Pins to control each channel LEDs. Change these if you're using different pins.

int oneLed = 3;       // LED PWM arduino pin for channel one.

int twoLed = 5;       // LED PWM arduino pin for channel two 

int threeLed = 6;     // LED PWM arduino pin for channel three

int fourLed = 9;      // LED PWM arduino pin for channel four

int fiveLed = 10;     // LED PWM arduino pin for channel five

int sixLed = 11;      // LED PWM arduino pin for channel six


#include <WProgram.h>
#include <DS1307.h> 
// written by  mattt on the Arduino forum and modified by D. Sjunnesson



// Set up RTC

#include "Wire.h"

#define DS1307_I2C_ADDRESS 0x68



// RTC variables

byte second, rtcMins, oldMins, rtcHrs, oldHrs, dayOfWeek, dayOfMonth, month, year;



// Other variables. These control the behavior of lighting. Change these to customize behavior.

int minCounter = 0;         // counter that resets at midnight. Don't change this.



int oneStartMins = 540;     // minute to start channel 1. Change this to the number of minutes past midnight you want to start

int twoStartMins =420;      // minute to start channel 2. Change this to the number of minutes past midnight you want to start                         

int threeStartMins =540;    // minute to start channel 3. Change this to the number of minutes past midnight you want to start 

int fourStartMins =420;     // minute to start channel 4. Change this to the number of minutes past midnight you want to start 

int fiveStartMins =420;     // minute to start channel 5. Change this to the number of minutes past midnight you want to start 

int sixStartMins =420;      // minute to start channel 6. Change this to the number of minutes past midnight you want to start 


int onePhotoPeriod = 720;   // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int twoPhotoPeriod = 960;   // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day                           

int threePhotoPeriod = 720; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int fourPhotoPeriod = 960;  // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int fivePhotoPeriod = 960;  // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int sixPhotoPeriod = 960;   // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day


int fadeDuration = 180;      // duration of the fade on and off for sunrise and sunset. Change
                            
//    this to alter how long the fade lasts.

int oneMax = 255;           // max intensity for this channel. Change if you want to limit max intensity.

int twoMax = 255;           // max intensity for this channel. Change if you want to limit max intensity. 

int threeMax = 255;         // max intensity for this channel. Change if you want to limit max intensity.

int fourMax = 255;          // max intensity for this channel. Change if you want to limit max intensity.

int fiveMax = 255;          // max intensity for this channel. Change if you want to limit max intensity.

int sixMax = 255;           // max intensity for this channel. Change if you want to limit max intensity.

/****** LED Functions ******/

/***************************/

//function to set LED brightness according to time of day

//function has three equal phases - ramp up, hold, and ramp down

void setLed(int mins,    // current time in minutes
            
int ledPin,  // pin for this channel of LEDs
            
int start,   // start time for this channel of LEDs
            
int period,  // photoperiod for this channel of LEDs
            
int fade,    // fade duration for this channel of LEDs
            
int ledMax   // max value for this channel
            
)  {
  
if (mins <= start || mins <= mins > start + period)  {
    
analogWrite(ledPin, 0);
  
}// This is when the led's are off, thus ledVal =0
  
if (mins > start && mins <= start + fade)  {
    
analogWrite(ledPin, map(mins - start, 0, fade, 0, ledMax));
  
}// This is sunrise. Leds slowly brighten to full intensity
    
if (mins > start + fade && mins <= start + period - fade)  {
   
analogWrite(ledPin, ledMax);
  
}//This is when the led's are at maximum intensity
    
if (mins > start + period - fade && mins <= start + period)  {
    
analogWrite(ledPin, map(mins - start - period + fade, 0, fade, ledMax, 0));
  
}// This is sunset. LEDs slowly fade out.

}



/***** RTC Functions *******/

/***************************/

// Convert normal decimal numbers to binary coded decimal

byte decToBcd(byte val)

{
  
return ( (val/10*16) + (val%10) );

}



// Convert binary coded decimal to normal decimal numbers

byte bcdToDec(byte val)

{
  
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.



/* //remove the forward slash and asterisk at the far left to activate the time date setting code




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.send(0);
   
Wire.send(decToBcd(second));
   
Wire.send(decToBcd(minute));
   
Wire.send(decToBcd(hour));
   Wire.send(decToBcd(dayOfWeek));
   
Wire.send(decToBcd(dayOfMonth));
   
Wire.send(decToBcd(month));
   
Wire.send(decToBcd(year));
   
Wire.endTransmission();
     
                             

}

*/ //remove the forward slash and asterisk at the far left to activate the time date setting code



// Gets the date and time from the ds1307 via the I2C protocol.

void getDateDs1307(byte *second,
          
byte *minute,
          
byte *hour,
          
byte *dayOfWeek,
          
byte *dayOfMonth,
          
byte *month,
          
byte *year)

{
  
Wire.beginTransmission(DS1307_I2C_ADDRESS);
  
Wire.send(0);
  
Wire.endTransmission();

  

Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  
*second     = bcdToDec(Wire.receive() & 0x7f);
  
*minute     = bcdToDec(Wire.receive());
  
*hour       = bcdToDec(Wire.receive() & 0x3f);
  
*dayOfWeek  = bcdToDec(Wire.receive());
  
*dayOfMonth = bcdToDec(Wire.receive());
  
*month      = bcdToDec(Wire.receive());
  
*year  = bcdToDec(Wire.receive());

}



void setup()  { 
    


// init I2C  
  
Serial.begin(9600);
  
Wire.begin();
} 
// these functions only occur once.



/***** Main Loop ***********/

/***************************/

void loop() { 

 
 
  

// get time from RTC and put in hrs and mins variables
  
getDateDs1307(&second, &rtcMins, &rtcHrs, &dayOfWeek, &dayOfMonth, &month, &year);
  
minCounter = rtcHrs * 60 + rtcMins;
 
Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true
  
Serial.print(":");
  
Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)
  
Serial.print(":");
  
Serial.print(RTC.get(DS1307_SEC,false));//read seconds
  
Serial.print("      "); // some space for a more happy life
  
Serial.print(RTC.get(DS1307_MTH,false));//read month
  
Serial.print("/");
  
Serial.print(RTC.get(DS1307_DATE,false));//read date
  
Serial.print("/");
  
Serial.print(RTC.get(DS1307_YR,false)); //read year 
  
Serial.println();


//set LED values
  
setLed(minCounter, oneLed, oneStartMins, onePhotoPeriod, fadeDuration, oneMax);
  
setLed(minCounter, twoLed, twoStartMins, twoPhotoPeriod, fadeDuration, twoMax);
  
setLed(minCounter, threeLed, threeStartMins, threePhotoPeriod, fadeDuration, threeMax);
  
setLed(minCounter, fourLed, fourStartMins, fourPhotoPeriod, fadeDuration, fourMax);
 
setLed(minCounter, fiveLed, fiveStartMins, fivePhotoPeriod, fadeDuration, fiveMax);
   
setLed(minCounter, sixLed, sixStartMins, sixPhotoPeriod, fadeDuration, sixMax);
 
// Get ready for next iteration of loop
  
delay(1000);
all that is in red under a message that says RTC was not declared in this scope . what am i doing wrong? thanks again for the help.
You probably don't have the needed "DS1307" Library installed in your arduino's library folder. Here's the library- just place the unzipped folder into your "library" folder and try again.
 

Attachments

#156 ·
I sent you a PM. Have you tried uploading some simpler code, like the "blink" sketch? I'm just trying a little remote trouble shooting here.
 
This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.
Top