Arduino Aquarium LED Controller




Introduction: Arduino Aquarium LED Controller

About: Engineering!

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 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 :).

2 People Made This Project!


  • Furniture Contest 2018

    Furniture Contest 2018
  • Audio Contest 2018

    Audio Contest 2018
  • Metalworking Contest

    Metalworking Contest

18 Discussions

it is possible to change the code for;

set time when should be the expecting time for end of the sunset or sunrise and the expecting power for light, not like it is now:

you have to set how many minutes will be the sunset or sunrise?

for example:

You set time to start sunrise and set power (start power for pwm) 7:00A.M 10%

you set expecting time for end the sunrise and expecting power for pwm 11:00A.M 40%

The project id awesomee!!!

But one question.

Its possibile to add extra menu for example for the "rising sun" before sunrise And "dawn" before moon time?
Also with next change in the PWM parameters And time between.
How to change the code?

2 replies

Why do you need this menu? There is a simillar menu already in the project that will do the job.

In menu Set SUN R/S/Step you can select when you want you main LEDs to be at maximum and Step is how slowly to increase the brighntess of those leds.

If you want to change the color prior sunrise/sun set just slect "RiseSet RGB" min menu different values for the RGB channels.

it will be nice to set another "setpoint" just that

Could I use LED strips, instead the LED modules? There is any change in the project? Thanks.

1 more answer

Yes - with a strip it will be even easier cause you can connect it directly to the logic gate mosfets and power supply without DC-DC converters.

In my case I use 2 different DC-DC supplies and chached their output voltage to correct the LEDs current. If you use LED strips you can connect them directly to 12V(or 24V depending on what you are using) without those DC-DCs.

Thnaks Jandy, I am so glad that I helped someone :).

Please when you finish with code, don't forget to post it here in istructables and send me a link, so I can add it to this article.

2 replies

Hello, I finally found some time and here is the result. I hope, it will be helpful.

Nice :), thanks that you pointed my project ;). Will add your link to my instructable, to help more people in the future.

Hi Melman2,

1- ColdWhite is on pin 5, WardWhite is on pin6 I just named the net LED_C, LED_W

2- you should create your own routines for the temperature sensor reading/display. It is easy, there is a lot of examples in internet.

3-In general, yes you can, but again you have to develop the program to do that. You can add another menu by copy past the last one for example, changing the max number of menus ''#define max_menu_item 5'' to 5 like this...

I can do that, but I am not sure how will test it, casue I don't have internet at home, and the project is disasebled.

Hi! Nice project but i have few questions if you don't mind. I am a beginner and any help will be appreciated.

1- i didn't find in the sketch the pins for warm and cool white (or i didn't pay attention for that?)

2- how could i make it read and display an other temperature sensor (using an DS18B20, LM35 or any other kind)?

3-it is possible to trigger an relay at specified time (like 12:30 for example) for feeding purposes or CO2 generator? How can i do that?

In that case the project will be almost complete for aquarium lovers.

Thank you in advance!

Hi Miciam,

the LCD is powered from 5V, all VDD=5V.

R6 is a trimmer 10kOhms for tuning the viewing angle of the screen ( polarization/ contrast ).

SLC it is a typo, it SCL - I2C Clock.

If you have some issues with the project just send me a message and will try to replay asap :).

1 reply

Thanks for your quick reply. OK, that makes sense now with the trimmer pot. I'm in the process of ordering some parts like the rotary encoder. I will let you know how it goes. It might be awhile though with oversee shipping.

Thanks again


1 year ago

Awesome project! I think I would like to replicate this and add moonlight simulation.

I have a question about the lcd display. I'm assuming it's powered by 5 volts. I don't see it shown on the schematic?

Also, what is the function of R6 PC16S? Is it part of the IC2 module or does it need to be wired in. If it does can you provide more information on the hardware.

One more thing. I see you have an input labeled SLC between the Nano and Display. Is it a typo and should it be SCL instead?

Thanks for posting your project.

That's a neat setup! We've been considering getting an aquarium for our nephew :)