|
||||||||||||||||
|
||||||||||||||||
|
|
#1 |
|
Algae Grower
|
Here is the Arduino code I use to control the schedule of my LED lights.
Back story: I've been redoing my 14G low-tech and wanted to try out LED, so I ordered a 10W ebay-special and planned to hook it up to an Arduino I had lying around. While waiting for it to arrive, I looked around for examples of how others had handled the software side of things. None of the code I found seemed to fit my needs. I realize a lot of people have done the same, but I wanted something that allowed for individual schedules for any number of channels, including siesta and different length sunrise/sunset. So in the end, I wrote my own code to control the lights. Some things that need to be addressed before looking at the code: 1: This is not a complete sketch to control aquarium lights! While it would work on a setup identical to mine, it wouldn't on much else. The code is meant as a helping hand for those that are not overly comfortable with programming, and find handling more complicated schedules difficult. I have removed all but the essentials in this sketch. 2: This has nothing to do with your hardware! Ok, that may not be strictly true. But my point is: There are a lot of great guides out there regarding the hardware side of things, I will only be dealing with the software. This is the part that I have found relatively little of on these forums, whereas the hardware gurus seem very active. I provide a way to control the PWM signal, the rest is up to you. Now, let's get started! Features: - Any number of individual channels (limited by you Arduino's number of PWM pins) - Pretty much any light schedule that repeats every 24 hours - Suitable for RGB lights - Reasonably smooth fading w. a resolution of 1/255 updated every second Hardware requirements: - Arduino (Uno in my case) - RTC module (DS1307 is used in the example) - PWM outputs wired CORRECTLY to your LED drivers Other requirements: - Some (not necessarily a lot) proficiency with Arduino coding There are a lot of comments in the code, and I hope it is not too difficult to understand. Concept explained: A lot of this is explained in the code, but I'll try to summarize it here. To define a schedule for a channel, you set up a 'matrix'. The format for a single row is as follows: -------------------------------------------------------------- | Start Hour | Start Minute | End Hour | End Minute | Intensity | -------------------------------------------------------------- Intensity is a value in the range 0-255. 0 = OFF, 255 = Fully ON Example: ----------------------- | 8 | 0 | 10 | 30 | 255 | ----------------------- Explanation: From 08:00 to 10:30 channel is fully ON Each channel has it's own schedule, each consisting of a number of these rows. If there is a gap between two rows like this: ----------------------- | 8 | 0 | 10 | 30 | 255 | | 11 | 0 | 12 | 30 | 0 | ----------------------- ( 08:00 to 10:30 light ON, 11:00 to 12:30 light OFF) the gap will be used to gradually fade from one value to the other. In this case going from 255 to 0 over the course of 30 minutes. Enough rambling, here is the code. Let me know if you have questions or find it useful! Link to source: EDIT: New location of source: https://github.com/benjaf/LightController Last edited by benjaf; Today at 06:29 AM.. Reason: me not write good.. |
|
|
|
| Tags |
| arduino, diy, led |
| Thread Tools | |
| Display Modes | |
|
|