The idea behind this device is to automate my aquarium light. By automation I mean not only switching light on/off but simulating a sun raise/sunset.
The project is build around arduino nano, set of white led( cold and warm), set of RGB leds and a DS3231 real time clock.
The control is possible thanks to rotary encoder with a push button on its axis and a I2C HD44780 16X2 LCD.
This project can be build for every applications that needs to simulate sunrise/sunset daylight, colors etc.
For example you can use it in you terrarium, vivarium or just in the corner of a dark room above the plants.
Step 1: The Schematics
The circuit is divided to few blocks.
- MCU - Arduino Nano 3.0 Atmega328 Ch340
- Real time clock module. It is based on DS3231 chip and it looks like the attached picture. I tried to draw the full schematic, but if possible use prebuild module. It's easier.
- DC-DC converters - this are not necessary. I have a DC24V bus at home and I want to regulate the current through the LEDs (white and RGB) separately. The white leds that I use(3 in series) need ~ 9-10V, but the RGB(3 in series per color) need ~ 11-12V. Yes I can put a resistor, but I decided to be this way cause I want to avoid using resistors due to heat issue.
- Rotary encoder is ED1112S-20 and I use the button on its axis.
- LCD is 16X2 HD44780 but here, like the time keeping module I took it prebuild with the I2C circuit soldered to it.
- There is 5 LED channels - Warm White, Cold White, Red, Green and Blue. Each channel is controlled by different PWM output of arduino. For the MOSFETs I use IRLU024N - logic gate activated mosfet, but again you can use a different ones.
- LEDs - I used pre-fabricated modules. The whites are from cree and the RBGs are from Edison (left over from old projects). Both of them are 3 leds per color connected in series. If you are using your own leds, please consider putting current limiting resistors in series of the leds.
Step 2: The Source Code and Algorithm
First of all I used this example to find the address of my time keeping module. In my case it is on 0x68 and the LCD is on 0x27.
The time algorithm works like this : all events are count on steps and one step is one minute starting from midnight 00:00. For example 08:30 is calculated like 8*60mins + 30min = 510.
Menu 0: it rotates in every 3 sec : Current time, current white leds pwm, current RGB pwm.
Menu 1: setting sunrise, sunset and steps
Setting sunrise : setting the sunrise time.
Setting sunset : setting the sunset time. The time here should be bigger than the sunrise time.
Setting steps : Ok...Lets give an examples. Lets say sunrise is in 08:00, sunset in 18:00 and steps are set to 60. This means that in 08:00 the PWM of the white leds will be switched on with value 1 and will gradually increase until in 09:00 ( 60min ) reach 254 ( max values is 254 ). Same is with the sunset. In 17:00 the white pwm will start to gradually decrease, so in 18:00 the white pwm will be 0 i.e. no light. Steps can be set up from 0 - no transition to 254 - it will take more than 4 hours to reach max intensity of the white leds. The PWM is changing on linear basis. I was thinking for logarithmic way but I left it like this( to save memory :) ).
Menu 2: Day Light and offset
Setting the cold white : here you can manually set up the value of the cold white leds. For example everything from 0 to 254 is accepted as manual value. If the value is 255 - this is accepted as auto mode and the light intensity will be modulated based on sunrise/sunset/step parameters described above.
Setting the warm white : same as the cold white from 0 to 254, 255 is automatic.
Setting the offset : the value of the offset can be chosen in the range -127:+127. For example if you set the cold leds to 255(auto), warm leds to 255 (auto) and the offset to -50 this means that the difference between cold and warm led intensity will be cold_pwm = |warm - 50 |. If offset is +50 this means that warm_pwm = |cold - 50|. The idea here is if you still want to have auto mode, but change the color temperature of the white light...In some cases I want the warm light to be stronger and to give more warm colors to the plants, fish...etc ( I have shrimps only ).
Menu 3: Set RGB
Setting R : setting the red color. Like above 0-254 means manual and the red channel will remains on the selected value until changed. 255 - auto mode.
Setting G : setting the green as above
Setting B : setting the blue as above.
Menu 4 : RaiseSet RGB min
No this is a tricky :). To make a different kind of effects for sunrise, sunset there are 3 settings that have meaning again on steps or minutes. All of them are from 0 to 255 and 255 doesn't mean auto. It's just 255.
Look at the attached graph. Sunrise is set for 07:30 (450min from midnight), Sunset is 19:30 (1170min) and the steps are 90 min. and...remember another value 64!
To create a color effect of sunrise/sunset my idea was to say lets start increasing the red first, then the green then the blue...and increase them in such a way that that when the main white light reach 64, all RGB to remains constant at 64 so not to change dramatically the color temperature, pre-selected with the white leds and offset.
So in the example shown...White leds will be at PWM=64 in 08:22 (sunrise 08:00 with gradually steps 90) and the RED is set here to 90, this means that the red will start PWM = 1 in around 06:00. In 06:10 red PWM =5, in 6:20 PWM = 11 and so on. and in 08:22 the red will be at PWM = 64, equal to the white led pwm and will stay there until the white led PWM doesn't fall below 64. After Sunset the picture repeats but this time its mirrored...starting from 64 for the RED PWM and taking 90mins to go to 0. It is same for the rest of the colors.
By changing those 3 values in this menu it is possible to simulate a different color and duration of sunrise/sunset.
Attached here is the excel file, to better understand the principle. You have to change only the green fields
In the graph - on the X axis is the time in minutes from midnight. On the Y axis is the PWM value of each channel. Here cold and warm whites are with offset 0 that is why they are overlapped, but the values for the R,G,B in RaiseSet RGB menu are clearly visible.
To set up the date/time you have to press and hold the rotary encoder axis during power on. Release it after power on. The first value is for seconds, then press the axis again and set up the minutes, hours, day of the week[1-Monday, 7-Sunday], month, last 2 digits of the year.
All parameters are stored in EEPROM, so you can disconnect the power any time, re-connect it and if the time keeping circuit has a stend-by battery it will continue working as per the current time.
Step 3: Build, Testing and Future Updates
I build everything on a bread board(lazy lazy lazy...), cause it was just an temporary project...but actually like everything temporary, it's running for almost an year till now. The idea for this aquarium was to have something green self sustained in the bathroom. I was thinking only for plants, but then I took few shrimps.
One think that is not included here, but I planned to do it, is to simulate a lightning storm. The software is almost ready but I still can't find a time to implement it...it is working now so why to touch it(lazy again :) ). I was thinking to use AS3935 for that purpose, but we will see :)...
Second think is a library to set up your sunrise/sunset based on geographical coordinates so the sunrise/set to mimic the real light outside.
Currently only 1/3 of the arduino nano memory is used, so there is a possibility for a wide variety of extras.
It is easy to add a Humidity/Temperature sensor so if you have a flowers (vivariums or something) to monitor the humidity and switch on/off a humidifier or something similar.
What else...o yep...moonlight simulation, but may be in the future with another menu - UPDATE - Jandy171 already added this future. Find details here .
I am gathering ideas for DIY automatic fish feeder :), so finally I can be 100% lazy :).