The Planted Tank Forum - Reply to Topic

Thread: Another Arduino LED light schedule sketch Reply to Thread
Title:
Message:
Trackback:
Send Trackbacks to (Separate multiple URLs with spaces) :
Post Icons
You may choose an icon for your message from the following list:
 

Register Now



In order to be able to post messages on the The Planted Tank Forum forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.

User Name:
Password
Please enter a password for your user account. Note that passwords are case-sensitive.

Password:


Confirm Password:
Email Address
Please enter a valid email address for yourself.

Email Address:
OR

Log-in









Human Verification

In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.



  Additional Options
Miscellaneous Options

  Topic Review (Newest First)
10-29-2015 08:15 AM
benjaf
Quote:
Originally Posted by skoram View Post
I just noticed this thread now. Benjaf, thanks for sharing your fantastic code with us! This is just what I have been looking for
Happy to help!
10-29-2015 08:07 AM
skoram I just noticed this thread now. Benjaf, thanks for sharing your fantastic code with us! This is just what I have been looking for
10-28-2015 07:57 AM
boxhead1990
Quote:
Originally Posted by benjaf View Post
Good to hear you got it working!
If you want to have the values back to 'normal' (0 = off) you can change the following line in UpdateLights:
Code:
analogWrite(Channels[channel].GetPin(), Channels[channel].GetLightIntensityInt(now));// Get updated light intensity and write value to pin (update is performed when reading value)
to this:
Code:
analogWrite(Channels[channel].GetPin(), (255 - Channels[channel].GetLightIntensityInt(now)));// Get updated light intensity and write value to pin (update is performed when reading value)
Im not gunna worry about it now as that means I have to set all my values again and its all working sweet so I think il just leave it alone

Sent from my D6653 using Tapatalk
10-28-2015 07:35 AM
benjaf
Quote:
Originally Posted by boxhead1990 View Post
I got it all working properly now had another play with stuff in the code and noticed something I overlooked now its running 3 channels like it should be

And I uave the pwm values reverse as my driver turns the diodes off with an input of 5v and full power on 0v

So value 255 for me is all the way off and 0 being full power

Cheers for keeping this available il definatly be adding to it when I get my touch screen and dosing pumps worked out

Sent from my D6653 using Tapatalk
Good to hear you got it working!
If you want to have the values back to 'normal' (0 = off) you can change the following line in UpdateLights:
Code:
analogWrite(Channels[channel].GetPin(), Channels[channel].GetLightIntensityInt(now));	// Get updated light intensity and write value to pin (update is performed when reading value)
to this:
Code:
analogWrite(Channels[channel].GetPin(), (255 - Channels[channel].GetLightIntensityInt(now)));	// Get updated light intensity and write value to pin (update is performed when reading value)
10-28-2015 05:22 AM
boxhead1990
Quote:
Originally Posted by benjaf View Post
Hi!
Actually, I 'deconstucted' the controller this code ran on more than a year ago. It was a huge mess, and frankly not a design you'd want to follow...
Anyway, the basic idea was as follows:

  • Get a couple of cheap 10W LEDs incl. waterproof drivers from China
  • Use MOSFETs (IRL540 IIRC) between LED and negative terminal on driver to switch lights on or off
  • Connect Arduino PWM pin to MOSFET Gate pin via a 220 Ohm resistor to limit the max power draw
  • Connect high value (~10K) pull-down resistor between MOSFET gate and ground
  • Connect RTC module to Arduino
  • Hope your driver doesn't react too poorly to being switched at very high frequencies


This is the quick and dirty way to dim lights. Not all drivers will react nicely to this. I had one which would knock the Arduino into an 'unresponsive' state several times a day, presumably due to poor shielding. Took me forever to realize it was not a bug in the code!
I got it all working properly now had another play with stuff in the code and noticed something I overlooked now its running 3 channels like it should be

And I uave the pwm values reverse as my driver turns the diodes off with an input of 5v and full power on 0v

So value 255 for me is all the way off and 0 being full power

Cheers for keeping this available il definatly be adding to it when I get my touch screen and dosing pumps worked out

Sent from my D6653 using Tapatalk
10-27-2015 02:12 PM
boxhead1990 I have a light built already and got the code working on my 2560 mega about 2 hours ago but I did notice that when you try to set more then 2 channels it wouldnt add them in even tho I added the code and assigned a pin for that channel maybe I missed something well anyways I noticed the ramp up was sudden and not really a fade in or out

I havent changed the code at all apart from adding the extra channel

Sent from my D6653 using Tapatalk
10-27-2015 01:51 PM
benjaf
Quote:
Originally Posted by boxhead1990 View Post
just wondering if there was a possability that you could draw a pinout/wiring diagram of how you set yours up and list any other parts you didnt list in your original write up ?

just looking to make sure im doing everything corectly when putting mine together
Hi!
Actually, I 'deconstucted' the controller this code ran on more than a year ago. It was a huge mess, and frankly not a design you'd want to follow...
Anyway, the basic idea was as follows:

  • Get a couple of cheap 10W LEDs incl. waterproof drivers from China
  • Use MOSFETs (IRL540 IIRC) between LED and negative terminal on driver to switch lights on or off
  • Connect Arduino PWM pin to MOSFET Gate pin via a 220 Ohm resistor to limit the max power draw
  • Connect high value (~10K) pull-down resistor between MOSFET gate and ground
  • Connect RTC module to Arduino
  • Hope your driver doesn't react too poorly to being switched at very high frequencies


This is the quick and dirty way to dim lights. Not all drivers will react nicely to this. I had one which would knock the Arduino into an 'unresponsive' state several times a day, presumably due to poor shielding. Took me forever to realize it was not a bug in the code!
10-25-2015 10:17 AM
boxhead1990 just wondering if there was a possability that you could draw a pinout/wiring diagram of how you set yours up and list any other parts you didnt list in your original write up ?

just looking to make sure im doing everything corectly when putting mine together
09-27-2015 06:31 PM
benjaf Hi Luka
The rtc.now() function used in that version of the DS1307 library returns the time as a complex type called DateTime. This means minutes, seconds etc can be accessed directly as seen in the UpdateLights method.
The DS3232 library's get() method returns time in a type that is called time_t, and must be treated slightly differently. See http://playground.arduino.cc/Code/Time for some good examples. You will need a slight rewrite of the UpdateLights method to match this way of accessing seconds/minutes/hours, but not much should need changing otherwise!
Good luck

Benjamin

Sent from my D6603 using Tapatalk
09-27-2015 09:52 AM
Luksi
Different RTC library

Hi Benjaf,

Thanks for sharing such a great code with us. I ve tried it and it works great on my test build, wich has DS1307 rtc attached to it. But for my tank I use DS3232 rtc, becose its more accurate and doesent miss minutes after longer periods of time. It needs different RTC library than the one used in your code. I changed your code a litle, but it doesent work, becose i dont undestand what rtc.now() funciton actualy outputs, at least I think thats wrong. I attached my code and library to this post and ask you if you could take a look what I ve done wrong.

Thanks,
Luka
02-03-2014 06:16 PM
AquaPorn I'll let you know what I find.

I'm at the Arduino forum as I don't know wether to increase or decrease the frequency of the pins.
Changing is pretty straight forward.

Truthfully, I've had nothing but issues ever since I changed out the Sainsmart clone for an actual Arduino.

Who would have thought?
02-03-2014 06:08 PM
benjaf
Quote:
Originally Posted by AquaPorn View Post
Hi Benjaf,

Ok, so I'm seriously confused now. I've been fiddling around, and I just can't get it to stop the jerky step up.
I don't understand why it's fine once, and then reverts back to stepping?
I've tried several different things: only using two channel, and I even went back to the old original sketch that I knew worked...I have video to prove it.
Nothing.

Now I'm down to blaming hardware as it is the only thing different since originally starting.
I went from a Sainsmart Mega to an actual Arduino Mega, and from LEDsee drivers to Meanwell LDDs.

I'm starting to question the PWM frequency of the Arduino board.
Do you think adjusting these would help?
At this point I think it is likely that your hardware may be playing you. My experience in the hardware field is somewhat limited so unfortunately I don't think I am the best person to help you here..
02-03-2014 04:58 PM
AquaPorn Hi Benjaf,

Ok, so I'm seriously confused now. I've been fiddling around, and I just can't get it to stop the jerky step up.
I don't understand why it's fine once, and then reverts back to stepping?
I've tried several different things: only using two channel, and I even went back to the old original sketch that I knew worked...I have video to prove it.
Nothing.

Now I'm down to blaming hardware as it is the only thing different since originally starting.
I went from a Sainsmart Mega to an actual Arduino Mega, and from LEDsee drivers to Meanwell LDDs.

I'm starting to question the PWM frequency of the Arduino board.
Do you think adjusting these would help?
02-02-2014 02:34 AM
sketch804 Gonna follow this one!
01-29-2014 05:50 PM
benjaf
Quote:
Originally Posted by AquaPorn View Post
I must be doing something wrong? It won't initialize with .SetPoint().

Using the example sketch I added 8 channels each channel has 4 periods.
It works fine with AddPoint().

I changed all periods to .SetPoint(), indexed each period 0 to 4, and then added variables risehour, risemin, color_max. With the exception of the first and last period where the intensity equals 0.
I then declared each variable with a value.

int RBlue_max =255
int rise hour = 8
ect....

And it failed to initialize. I then changed all the set points back to whole numbers to test, and it again failed to initialize using .SetPoint()

I'm missing something?? Any suggestions?
It may very well be my code that doesn't actually support this.. It was not really something I had thought of originally.

Oh well, new plan:
You initialize it just like the example with AddPoint() and set some generic times and intensities, let's call it InitializeLights(). The actual values don't matter, they will be overwritten anyway.
You then make a second function to set the actual values using SetPoint(), let's call it UpdateLights(). Since the channels are already set up elsewhere you only have to set the points this time, the channel creation with pins and such is not necessary. Example:
Code:
int channelNo = 0;
Channels[channelNo].SetPoint(0, 8, 0, 0);
Channels[channelNo].SetPoint(1, 8, 30, 255);
Channels[channelNo].SetPoint(2, 20, 0, 255);
Channels[channelNo].SetPoint(3, 20, 30, 0);

channelNo = 1;
// ... etc ...
During setup you then first call InitializeLights() to set up the basic structure and then UpdateLights() to set up the actual light values.Any time you need to rewrite the values you just call UpdateLights() again.
This thread has more than 15 replies. Click here to review the whole thread.

Posting Rules  
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

 
For the best viewing experience please update your browser to Google Chrome