Jump to content
inTank Media Baskets

LED controllers - dimmers / timers


Waterproof

Recommended Posts

No difference feature wise between the Arduino and Freeduino. You just have to build the Freeduino.

 

Don't bother with the power supply for now. The board will run directly off of the USB port while you are prototyping everything. When/if you get the power supply, you could get either voltage as the DC regulator on the pcb will drop to 5v anyway.

 

http://store.fungizmos.com/index.php?main_...products_id=210

 

Get this LCD. It takes much fewer pins to get the job done, leaving the I/O pins free to do other things.

Link to comment
  • Replies 97
  • Created
  • Last Reply

You guys are sucking me in... I just sent an email to a friend of mine who has made his living programming microcontrollers for various industries asking him what he knows about the arduino platform.

Link to comment

Cool, thanks for the links spark... I hadn't seen his yet. I also like his DIY sump... His controller seems a little more intensive than what I think I am capable of... so I'm going with the arduino, which seems a little more complete from the get go.

 

cdelicath, I noticed that you updated your blog. cool stuff that you got the lights on/off part down. Your successes, no matter how small give me hope that I won't completely #$@% up mine when I get it...

Link to comment

I just ordered my Arduino Duemilanove with the 328 upgrade, a DS1307 Real Time Clock and some other fun toys. I am going to build a controller for my LED project... Sunrise, Sunset etc...Still looking for a descent PWM dimmable LED driver that run 8 LEDs.

 

Check out the Illumionato from Liquidware.. . Very cool and 100% Arduino compatable.

 

I used to be a programmer and have used about every language possible. I have worked with Allen Bradely PLC's for work so once I get moving on the code, I will start posting it.

Link to comment

Cool.... looking forward to reading your progress. I just got one today. For now I just have the arduino & the LCD, but the clock and temp sensor will be coming soon.

Link to comment

MAN! Just when I think I'm out, I get pulled back in! The LED project is done and I sold some spare parts. I guess I might as well buy the arduino & RTC. Maybe I missed it, but what's the point of the LED is you're just doing light control? Would it display the time, maybe the % output to each LED leg? Or is it just for future expansion w/ temp/ph probes and other stuff?

 

Have we (you ;) ) worked out the code yet? I'd love to know when someone gets a fully functional prototype working. A DIY guide would be nice for the lazy people (me).

Link to comment

You will be able to set your max intensity for all LEDs by using the internal pot. External pot will allow you to set your sunrise, sunset and daylight times. This will be entered from the screen. I intend to do a 90 day moon cycle as well. Eventually I will build a function that sets sunrise & sunset times along with the durations based on the date I pull from the real time clock. So I will have the ability to set it how I want or just let it run by itself based on the date (basically just winter, spring summer and fall). I am also going to use it to temp probe on my lights to control the fan speed.

I will have four strings of 6 LEDs on 1000 mA buckpucks. So each puck will be set. So I can offset the startup on all 4 pucks for sunrise and sunset. Lots of possibilities.

2 white - daylight

1 blue - dual use for daylight blue and moonlight

1 blue & white mix - could be dual use as well

I am using rebel 0800 cool whites and the 325 royal blues. 18 whites 8 325 blues . I have 3 extra 525 royal blues I might mix in since they all have the same forward voltage. Once I get my CADD drawing done for the heat sink. I will post more. Just have to find the time between work, business trips, kids volleyball tournaments, basketball, soccer and softball games. NP....

When it is all done, I can burn chips have the boards made. Ready for use with any LED with internal PWM.

This is all retro for my RSM 130D. I currently have a 150W MH with 2X18 actinic & Moonlights I put in the hood.

Honestly, I could do more with it, but I already have my old original reefkeeper that works fine. I am hoping I will not need a chiller any more after the LED's are in.

Link to comment

Here is some code I wrote. They are all functions that will be called on. Eventually I will create a library. Since I don't have my arduino yet, I could not test it. The logic is straight forward, but a couple things I am not sure about like whether I can use the parameter name directly in the function statements or have to assing internally. Not sure if I can use a long integeter with the delay function or not. So I will tweak it to reduce code and take out a lot of the explinations to save space. You get the idea.

 

This program assumes that the settings for the duration will only be able to be entered in 15 minute increments for a maximum of 3 hour sunrise or sunset – value will be controlled by another function for the menu input. Will toggle time 1-4 hours in increments of 15. The 255 is the maximum PWM signal and so I spread the pause based on the time that will be entered on the screen. Otherwise we are limited to I have not done this part yet as they are global setting that have to be stored from entries on the menu system. Those values are passed as parameters to the functions. I do a long sunrise because we know that the sun gets more intense until the astronomical noon, then gradually decreased until setting. (Yes it changes with seasons and where you are on the planet, but I am not ready for those calcs yet. I may build a function that sets sunrise & sunset times along with the durations based on the date I pull from the real time clock. But one step at a time. I don’t even have my arduino yet.

 

You will notice there are no void loop() or setup() functions in any of these. That is because they are functions that are called on from a main program like this:

 

 

DISCLAIMER - First arduino code I have ever written and it has not been run, so there could be some syntax issues. I will run it all next week and complete the code and repost bug free.

 

Void Setup(){

int pwm_pin=10

float sunrise_dur = 2.25 //15 minute increments in decimal form

float sunset_dur = 3.75

moon_dur = 11

day_dur = 1 //max intensity length

}

Void loop()

{

Sunrise(sunrise_dur, pwm_pin) \\ these will eventually be in a nested If as each will return a TRUE value when the cycle is completed

Sunset(sunset_dur, pwm_pin)

}

 

These function should be put in a library

*************

int getdelayVal(sun_duration)//Function accepts parameter for duration and calcs delay-pause and returns the value

{

float durms = 0; //calculated duration in ms

float duration= sun_duration //set value to input parameter

int retduration =0

 

durms = (((duration*60)/255)*1000) //takes the minutes to seconds and spreads pause value since we only have 255 steps

retduration = int(durms) // changes the float to an integer – will cut off the decimals – shouldn’t be any

return durms; // return final value

} // FUNCTION END

************

boolean turnoffLED(ledpin) //Function that turns off the LED string

{ //FUNCTION START

boolean completed=FALSE

analogWrite(ledpin, LOW); // outputs PWM signal to led - turns off;

completed - TRUE

return completed

}

************

Boolean Daylight (sun_duration, ledpin)

{ //FUNCTION START

int LEDstrng= ledpin; //sets which PWM pin is controlling led brightness (I am using 4 buckpucks)

int pwm_value =0; // value 0-255 sent for PWM Volts

int pause = 0; //delay value represents the amount of time a PWM setting will run step

float daylight_dur= sun_duration; //stores sunrise duration

boolean completed = False

pause= getdelayvalue(daylight_dur); //call function to get the calculated delay-pause between V increase

 

analogWrite(LEDstrng, HIGH); // outputs PWM signal to led;

delay(pause);

completed - TRUE

return completed

} // FUNCTION END

 

 

 

************

boolean Sunrise(sun_duration, ledpin)

{ //FUNCTION START

 

//Declare Variables

 

int LEDstrng= ledpin; //sets which PWM pin is controlling led brightness (I am using 4 buckpucks)

int pwm_value =0; // value 0-255 sent for PWM Volts

int pause = 0; //delay value represents the amount of time a PWM setting will run step

float sunrise_dur= sun_duration; //stores sunrise duration

boolean completed = False

pause= getdelayvalue(sunrise_dur); //call function to get the calculated delay-pause between V increase

 

while (pwm_value <= 255)

{

analogWrite(LEDstrng, pwm_value); // outputs PWM signal to led;

delay(pause);

pwm_value++; // increments by 1

}

completed - TRUE

return completed

} // FUNCTION END

 

 

 

int Sunset(sun_duration, ledpin)

{ //FUNCTION START

//Declare Variables

int LEDstrng= ledpin; //sets which PWM pin is controlling the fade (I am using 4 buckpucks)

int pwm_value =0; // value 0-255 sent for PWM Volts

long pause = 0; //delay value represents the amount of time a PWM setting will run step

int sunrise_dur= sun_duration; //stores sunrise duration from parameter

boolean completed = False

 

pause= getdelayvalue(sunrise_dur); //call function to get the calculated delay between V increase

 

while (pwm_value >= 0)

analogWrite(LEDstrng, pwm_value); // outputs PWM signal to led;

delay(pause);

pwm_value --; // decreases by 1

}

int turnoffLED(ledpin) // Make sure the lights are off -time for this led string

completed - TRUE

return completed

} // FUNCTION END

Link to comment
"directly in the function statements or have to assing internally"
What does that mean?!? Haha.

 

Okay, in all seriousness thank you for posting some code spark. My arduino shipped today from CA Fedex, so it will probably be here on Tuesday. Who knows when my LCD will get here though (ebay).

 

Waterproof, I think that I got the LCD 1) because it looks cool and I can put random stuff on there 2) I'll eventually need it to read the temps & use it to set the lights 3) It just seems more complete with an LCD.

 

After my poor patience has worn off I will be able to purchase an RTC and temp probe. Besides, getting everything in pieces allows me to dominate/master one part before I go on to the next challenge (haven't programmed since high school).

Link to comment

I used to be a programmer and have exprerience with Allen Bradely controllers . have designed and implemented NC applications on a shop floor. It has been a while but I still can do it. I am not an an EE, but can help on with the logic side.

Link to comment
This program assumes that the settings for the duration will only be able to be entered in 15 minute increments for a maximum of 3 hour sunrise or sunset – value will be controlled by another function for the menu input. Will toggle time 1-4 hours in increments of 15.

 

spark, does this mean you can only change the LED output every 15 minutes? Let's say you wanted a 1-hr sunset. You'd be at 100% then drop to 75% in 15min, then 50%, then 25%, then off? If I'm envisioning this correctly, I think the changes will be abrupt.

 

I was thinking we could program the equivalent to an if/then loop. You'd set a ticker at a value of 100 at a predefined time (let's say 8pm), then continue to decrease the lights by about 1% brightness until your ticker reaches zero, at which point you'd bounce out of the loop. You'd have to set the loop to delay every 1 minute or 45 seconds. The same would occur with sunrise, in reverse. You could have multiple loops for each LED leg. When I refer to 1% brightness, I mean the PWM signal equivalent (maybe 2.5 PMW value).

 

My programming is limited to a single C++ class in college 7 years ago, so I may be way off on this.

Link to comment

SunriseSunsetCode.docmenu_example_CASE.doc

 

 

Waterproof. Sorry the code is harder to read as when I cut and paste all the indenting goes away. I uploaded a Word file.

 

The 15 minutes is just what I picked to use for setting some rules on the input screen for the duration the sunset/sunrise would run. 15 minutes is the minimum and 4 hours being the max duration. It will toggle in 15 minute increments to choose from.

 

The do while loop just loops through incrementing or decreasing the light intensity via PWM. Arduino limits you to 0-255 for increasing and decreasing voltage for PWM. It is done with the analogWrite(LEDstrng, pwm_value); statement. An if then statement would not accomplish this and I would not have much control over spreading a gradual increase in a specific time period. If you use a do/while or even a for/next loop you can utilize a single step over the the duration you want the light to be increasing in brightness or fading. So a do while start at 0, which is off and increments 1 step at a time until it reaches 255, which is 100%. By incrementally increasing brightnes (or fading) by steps of 1, it is more natural and a nicer smooth transition.

0% = 0

25% brightness would be the number 64

50% - 128

75% - 192

100% - 255

 

In terms of % brightness, each single increase of the 0-255 is .39215682% increase in brightness.

 

 

So for example:

I set the duration for a sunsrise at 1:15 minutes or 75 minutes. That is 4500 seconds. If I divide that by 255(max number of PWM step to make the transition as smooth as possible) then I get 17.65 seconds. Since the Wait command will only take integers, and there is no good way to round in arduino code, I just concatinate to 17 seconds. So the code run through the 255 increases of .3922 % increases waits at that level for 17 seconds and increments again and again until it hits 255 (or 100% brightness). (.39215682*255=100 %))

 

I have to convert that to ms for the pause Wait statement. The Wait statement sets how long each level from 0-255 runs at given the duration. I hope this makes more sense.

 

I will post the rest of the rules for the system and maybe it will make more sense. I have to do this way if I want to be able to automatically go into the correct mode based on the time of day.

 

Gotta run, but will post more tonight...

 

 

Menu Switch Case for cdelicath

sunrise_sunset_code.doc

menu_example_CASE.doc

Link to comment
I have to convert that to ms for the pause Wait statement. The Wait statement sets how long each level from 0-255 runs at given the duration. I hope this makes more sense.

 

Using wait (_delay_ms()) would be extremely inefficient since that command is blocking and the microcontroller wouldn't be able to do anything else for the duration of the sunset/sunrise. You'd be better off using a timer and interrupts to do this non blocking. It's not that much harder coding wise, and frees the controller up for other tasks, like checking temperature, pH, checking the auto refill, updating stuff on LCD etc...

Link to comment

Keli,

 

Thanks for pointing that out. I did not realize that the delay() was a polling delay to the processor. So the delay() statement in itself is very inefficient. I cannot think of anwhere I would want to use it. I am new to the entire arduino envronment and expect there are some areas that I can improve my code to make it run effeciently.

 

I read up on the timer2 code concepts and will incorporate it into my code and will repost. Not sure if this will work well in a do while loop or if I will be generating too many interrupt. I also found the timer1 PWM control library which has all sort of good controls for setting the pwm duty etc.... That will make this much easier having the library already

 

I will figure it all out this week.

 

If you have any more advice, it all helps...

Link to comment

5 buckpucks isn't much of a problem, you could f.e. use a sipo shift register (74hc164xx) to make better use of outputs - that would effectively make 8 outputs from 2 avr io ports, and the rest of the ports would be free for other stuff. shift registers are extremely cheap ($1-2) and fast enough for use in PWM.

 

Another thing to think about with interrupts is don't do the actual work in the interrupt routine. Just have the interrupt set some variable (f.e. TimerActivated = 1), and have your main loop check for that variable in every iteration. That'll make the actual interrupt only take a tiny fraction of a second and other stuff can resume and finish almost as if nothing stopped it.

 

 

Pseudocode would be something like this:

 

var shouldIDoTheTimerStuffNow = false

 

main program loop {

GetTemperature()

GetPH()

 

if shouldIDoTheTimerStuffNow {

DoTimerStuff() // Like dim the lights down one notch

shouldIDoTheTimerStuffNow = false

}

 

updateLCD()

}

 

Timer activated interrupt {

shouldIDoTheTimerStuffNow = true

}

 

 

Shouldn't be too hard to transform this into c for the arduino.

 

P.s.

Sorry the code looks horrid.. It's hard to indent here :)

Link to comment

Thanks Keli,

 

I am learning how this chip works with arduino code. I have some familiarity with interrupts from pc's, but it is a more automated with the higher level languages like c.

 

I saw from reading that I only have 8.3 second per interrupt before they will freeze up the device. On a linear digital pulse, that exceeds a 24 hour cycle which will work fine. But not sure how smooth the fade will be.

 

I am also looking at teh possiblility of using some sort of digital smoother to make the dimming smooth with no jitters, but I may have to rethink this enture thing since I was trying to spread the gradual increments in PWM over such a long period of time.

 

I am wondering if I might have to move to using sine and cosine to do that. I was going to see if I could just use the digitalsmooth(), which uses sin/cos functions, but it stores all the values in an array for analog wave and that could make for a huge array for a 2 or 4 hour increase.

Link to comment

Archived

This topic is now archived and is closed to further replies.

  • Recommended Discussions


×
×
  • Create New...