Another Arduino LED light schedule sketch - Page 4
Planted Tank Forums
Your Tanks Image Hosting *Tank Tracker * Plant Profiles Fish Profiles Planted Tank Guide Photo Gallery Articles

Go Back   The Planted Tank Forum > Specific Aspects of a Planted Tank > DIY


Reply
 
Thread Tools Display Modes
Old 12-02-2013, 07:00 AM   #46
benjaf
Algae Grower
 
benjaf's Avatar
 
PTrader: (0/0%)
Join Date: Mar 2012
Location: Denmark
Posts: 105
Default

Just read through your build thread - damn, suddenly I'm really appreciating dealing with a small low-tech planted tank! No PH probes with grounding issues, no massive LED driver arrays to burn. Oh, and no touchscreen!
Learning Python and using Qt for GUI is somewhat more forgiving.
Congratulations on getting this far, I'm confident you will be able to complete it at some point

// Benjamin
__________________
benjaf is online now   Reply With Quote
Sponsored Links
Advertisement
 
Old 12-09-2013, 01:56 AM   #47
coonass
Algae Grower
 
PTrader: (0/0%)
Join Date: Dec 2012
Location: Okeechobee, FL
Posts: 12
Default

Thanks for putting this code out there for us!

I'm having a problem that I hope someone can clarify. I would like to have the lights intensify to some medium value (here 150) between 0800 and 1000, then have a midday burst at full intensity from 1200 to 1400 followed by another period of medium intensity from 1500 to 1930 and finally a fade out from 1930 to 2130. With the following schedule the lights go out (0 intensity) at 14:00 and then come back up to 150 at 1500.

// Channel 0:
Channels[0].Pin = 11;
Channels[0].AddPoint(8, 0, 0);
Channels[0].AddPoint(10, 0, 150);
Channels[0].AddPoint(12, 0, 255);
Channels[0].AddPoint(14, 0, 255); Lights go out here instead of fading down
Channels[0].AddPoint(15, 0, 150);
Channels[0].AddPoint(19, 30, 150);
Channels[0].AddPoint(21, 30, 0);

How am I coding this wrong?
coonass is offline   Reply With Quote
Old 12-09-2013, 07:46 PM   #48
benjaf
Algae Grower
 
benjaf's Avatar
 
PTrader: (0/0%)
Join Date: Mar 2012
Location: Denmark
Posts: 105
Default

Well that part looks fine, so my only other guess would be that you have MaxPoints set too low? If that's not the problem it's possible there may be a bug in the intensity calculation.
Does the light come on again after turning off, or does it just stay off?
__________________
benjaf is online now   Reply With Quote
Old 12-09-2013, 10:01 PM   #49
coonass
Algae Grower
 
PTrader: (0/0%)
Join Date: Dec 2012
Location: Okeechobee, FL
Posts: 12
Default

The lights come back on. From 1400 to 1500 they fade from 0-150 rather than from 255-150.

MaxPoints = 10
coonass is offline   Reply With Quote
Old 12-10-2013, 04:08 AM   #50
benjaf
Algae Grower
 
benjaf's Avatar
 
PTrader: (0/0%)
Join Date: Mar 2012
Location: Denmark
Posts: 105
Default

Odd.. I'll try to replicate it and find out why that happens!
__________________
benjaf is online now   Reply With Quote
Old 12-10-2013, 08:01 AM   #51
benjaf
Algae Grower
 
benjaf's Avatar
 
PTrader: (0/0%)
Join Date: Mar 2012
Location: Denmark
Posts: 105
Default

After a quick review I have updated the code.
The old version had several bugs in the intensity calculation, so I have merged the 'old' public version and parts of my experimental branch. This means a few changes will have to be made to fit this in to your code, but I believe the benefits are worth some minor changes.

Major differences:
* Channel boilerplate code moved to a library to reduce mess
* Channels are initialized slightly differently
* A 'Points' array must be defined along with 'Channels'
* You can now choose between linear and exponential fading
* Intensity can be defined as integer (0 - 255) or float (0 - 1), but is handled as a float internally
__________________
benjaf is online now   Reply With Quote
Old 12-10-2013, 10:15 AM   #52
coonass
Algae Grower
 
PTrader: (0/0%)
Join Date: Dec 2012
Location: Okeechobee, FL
Posts: 12
Default

I am going out of town for the rest of the week. I'll give this another try on Friday and report back.
coonass is offline   Reply With Quote
Old 12-30-2013, 08:31 PM   #53
Pady
Newbie
 
PTrader: (0/0%)
Join Date: Dec 2013
Location: Sweden
Posts: 2
Default

I've looked at this code and it fits my array the most.
Like the idea of "low tech" arduino controlling without LCD displays and so on.
I just need 4 channels and a way to set the starting times... (can't really make sense off the code) I'm pretty noob to this programming bit...

lateron i'm thinking of adding a thunder storm and so on...
can some of you help with the code of adding 2 more channels?
and mabye help me understand the code.
if I want PWM 180 to be 100% and not PWM 255...
Pady is offline   Reply With Quote
Old 12-31-2013, 09:52 AM   #54
benjaf
Algae Grower
 
benjaf's Avatar
 
PTrader: (0/0%)
Join Date: Mar 2012
Location: Denmark
Posts: 105
Default

So just to be sure I got this right before the examples..
You currently want the following:

4 channels
Simple sunrise / sunset for all channels
Max intensity of ~180

To get 4 channels you have to do the following:
Change this:
Code:
const int MaxChannels = 2;
to this:
Code:
const int MaxChannels = 4;
If all you need is simple sunrise / sunset, you don't need more than 4 points in each channel. So you can safely set MaxPoints to 4 in stead of 10:
Code:
const int MaxPoints = 4;
Then you need to set up the schedules for each channel.
Change the pin / times / intensities in Channel 0 to fit your schedule, and then replace this:
Code:
        // Channel 1:
        channelNo = 1;        // Currently editing channel 1
        pin = 11;                // Channel 1 uses pin 11
        Channels[channelNo] = Channel(pin, MaxPoints, fademode_linear, Points[channelNo]);
        Channels[channelNo].AddPoint(8, 0, 0);
        Channels[channelNo].AddPoint(8, 30, 150);
        Channels[channelNo].AddPoint(11, 0, 255);
        Channels[channelNo].AddPoint(11, 15, 0);
        Channels[channelNo].AddPoint(12, 30, 0);
        Channels[channelNo].AddPoint(12, 45, 255);
        Channels[channelNo].AddPoint(19, 30, 150);
        Channels[channelNo].AddPoint(20, 0, 0);
with the following (set the correct pins / times / intensities to match your setup):
Code:
        // Channel 1:
        channelNo = 1;        // Currently editing channel 1
        pin = 11;                // Channel 1 uses pin 11
        Channels[channelNo] = Channel(pin, MaxPoints, fademode_linear, Points[channelNo]);
        Channels[channelNo].AddPoint(8, 0, 0); // 08:00 - Intensity = 0
        Channels[channelNo].AddPoint(8, 30, 180); // 08:30 - Intensity = 180 
        Channels[channelNo].AddPoint(19, 30, 180); // 19:30 - Intensity = 180
        Channels[channelNo].AddPoint(20, 0, 0); // 20:00 - Intensity = 0
		
	// Channel 2:
        channelNo = 2;        // Currently editing channel 2
	pin = 9;                // Channel 2 uses pin 9
        Channels[channelNo] = Channel(pin, MaxPoints, fademode_linear, Points[channelNo]);
        Channels[channelNo].AddPoint(8, 0, 0);
        Channels[channelNo].AddPoint(8, 30, 180);
        Channels[channelNo].AddPoint(19, 30, 180);
        Channels[channelNo].AddPoint(20, 0, 0);
		
		// Channel 3:
        channelNo = 3;        // Currently editing channel 3
        pin = 6;                // Channel 3 uses pin 6
        Channels[channelNo] = Channel(pin, MaxPoints, fademode_linear, Points[channelNo]);
        Channels[channelNo].AddPoint(8, 0, 0);
        Channels[channelNo].AddPoint(8, 30, 180);
        Channels[channelNo].AddPoint(19, 30, 180);
        Channels[channelNo].AddPoint(20, 0, 0);
What you just did by altering and inserting the above, is to configure channels 0 - 3. No more code needs to be changed, now you have a complete 4-channel setup.

The rest of the code (in the main sketch at least) is quite straightforward. Every loop checks if a second has passed since last time the lights were updated, and then calculates the current intensity levels for each channel.
__________________
benjaf is online now   Reply With Quote
Old 01-10-2014, 05:40 PM   #55
HunterX
Planted Tank Obsessed
 
HunterX's Avatar
 
PTrader: (22/100%)
Join Date: May 2012
Location: Springfield MO
Posts: 360
Default

Ben,

Love the light code mate . I doing some comparison with some other light codes to see about working in the storm stuff.

Do you know if scapegoat's wiki is still up? I clicked on the link and page was not available. Thanks again. Great work!
HunterX is online now   Reply With Quote
Old 01-10-2014, 06:44 PM   #56
benjaf
Algae Grower
 
benjaf's Avatar
 
PTrader: (0/0%)
Join Date: Mar 2012
Location: Denmark
Posts: 105
Default

Quote:
Originally Posted by HunterX View Post
Ben,

Love the light code mate . I doing some comparison with some other light codes to see about working in the storm stuff.

Do you know if scapegoat's wiki is still up? I clicked on the link and page was not available. Thanks again. Great work!
Thanks!
You will probably need to make a few changes to enable an 'effect' overlay, but it should be possible.

I think he made some breaking changes to the wiki. Last time I saw it there was some stuff about CO2 and then my code. I think he had trouble getting people to submit content.
__________________
benjaf is online now   Reply With Quote
Old 01-17-2014, 02:26 AM   #57
AquaPorn
Algae Grower
 
PTrader: (0/0%)
Join Date: May 2013
Location: Chicago Suburb
Posts: 26
Default

Hi Benjaf...yep it's me again.

Just having an issue I can't seem to sort, and was hoping you could nudge me in the right direction.

Long story short I am having difficulties with the ramping up of the LEDs. This started happening when I had to undo your nice tidy array in order to integrate my UI.
What is happening is the increasing intensity of the LEDs has become jerky. It ramps up in steps rather than the nice smooth increase from 0 to the max LED vlaue.
Just a rough example...the LEDs come on at about 20%, 40% a few seconds later, and so on. Noticeable increase to the eye.

I've been trying to figure out why this is happening, and correct the issue for some time now, and finally had to bother you yet again.

Funny thing is nothing else is effected. Timing schedules for all the periods is correct with no issues, and the fading from max led value to 0 is still silky smooth.

Do you have any idea what might be causing this?
I could send my code if you need.

Thanks again!
AquaPorn is offline   Reply With Quote
Old 01-17-2014, 04:15 AM   #58
benjaf
Algae Grower
 
benjaf's Avatar
 
PTrader: (0/0%)
Join Date: Mar 2012
Location: Denmark
Posts: 105
Default

Hello again Steve!
That does sound very strange, if you send me your code I will have a look at it as soon as I can.
__________________
benjaf is online now   Reply With Quote
Old 01-17-2014, 01:35 PM   #59
AquaPorn
Algae Grower
 
PTrader: (0/0%)
Join Date: May 2013
Location: Chicago Suburb
Posts: 26
Default

Thanks for taking a look!

Hopefully you can make heads or tails of it....I try to be neat, but it doesnt always work out.

Last edited by AquaPorn; 01-18-2014 at 04:45 PM.. Reason: Remove file
AquaPorn is offline   Reply With Quote
Old 01-17-2014, 04:50 PM   #60
benjaf
Algae Grower
 
benjaf's Avatar
 
PTrader: (0/0%)
Join Date: Mar 2012
Location: Denmark
Posts: 105
Default

That's a lot of code!
I'll take a closer look when I have a bit of time.
__________________
benjaf is online now   Reply With Quote
Reply

Tags
arduino, diy, led

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not 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

Forum Jump


All times are GMT. The time now is 06:47 PM.


Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright Planted Tank LLC 2012