Introduction: Arduino - Digital Clock With Aquarium RGB Light Control
For my new fish tank, I noticed that I sometimes forgot to turn on the lights or kept the lights on too long. Since I'm lazy, I made a simple solution for this, and controlled the lighting of my aquarium using an arduino and a real time clock.
Goal of this project:
1. Let the aquarium lights go on automatically in the morning
2. Let the lights switch to blue lights in the evening
3. Turn the lights of automatically at 1:00am.
Edit on November 9th, 2015:
I dug a bit deeper into the code and made the lights gradually change over a 30 minutes timespan. Link to both codes is placed in the Code chapter.
Step 1: Parts List
The parts that I used are:
- DS3231 Real Time Clock module
- Arduino Mega / Uno
- 5050 RGB Led strip
- 3x BV547 NPN transistor
- 12v-5v voltage regulator
- 12v power supply
- 12v connector for breadboard
If you want to show the time on the LCD display (optional), you also need:
- 16x2 LCD display
- 10k potentiometer
- 220ohm resistor
Step 2: Wiring
Wire everything up as shown in the picture. You can skip the LCD part if you don't want this.
Note that the image shows a different clock module than the DS3231, but there was none available for fritzing.
Important:
If you use an Arduino Mega, wire up as shown in the picture. If you use an Arduino UNO, the SDA and SCL pins are at a different location. Make sure that you use the correct pins.
Step 3: Code
The arduino code can be found here, on Github: click
Note: The first time you use the DS3231, you have to set the time. You do this by uncommenting line 38 and set the current time, as explained in the rows before it. Then upload the code to the arduino, comment this line OUT again and reupload the script. Otherwise, the time will be reset to the time you put there every time the arduino restarts.
Edit v.2:
In the code behind the link mentioned above, the lights will change suddenly. I rewrote the code to make them change more gradually, over the timespan of 30 minutes. This code can be found here: Github
Step 4: Finish
Now make a nice aquarium cover, put in the RGB led strip and hook it all up!
Later on, I'll try to edit the code so that the change between every phase won't be so sudden, but for now at least I don't have to switch the lights manually anymore. ;)

Participated in the
Make It Glow! Contest
24 Comments
Question 4 years ago on Step 3
Hello, I tried to make one of these using your code, but the hour doesn't show up on the display.
Question 5 years ago on Introduction
hello!
I have never worked with arduino, but this is exactly the project I want to do.
My idea is to make an RGB ledstrip do 11 hour "daylight", 1 hour fade over "dusk". 11 hour all blue and then 1 hour "dawn".
How would you go about that?
I want the red and green channels at different fade times as I want dusk and dawn to look more red.
Thank you for a great start anyway and thank you for any help you can provide.
7 years ago
I too made one a about two years back. Almost similar! Has the pump/filter controlled by the clock too. Sadly I lost the code. Anyway this gizmo is running without fault till date.
Reply 5 years ago
can u help me to find the correct code the project you did. i'm trying to do the same thing, but still didn't got any result. thank you.
Reply 7 years ago
Nice! I'm planning to extend this as well. I'm already working on this with an lcd touchscreen, on which I can set the lights color, record temperature and ph and all other cool stuff! This fish tank gave me a lot of new arduino ideas!
5 years ago
Hi, Very interesting. I have been trying to convert this code to work on a nano. Had to use the analogue pins to drive the lcd, which works ok. I am also using a DS1302 rtc so again I've had to alter the coding to suit. It now compiles ok so I'm ready to wire up. I just noticed though, your code includes pin 6 for white light but your diagram hasn't got it in. Is this just an oversight or are you using something else? 'm a bit of a newbie at programming so I have to patch other peoples code together to get where I want,and I intend to have the final program to read temperature and operate a fan (cold water fish) and also switch the air pump on at certain times, possibly control the speed of the fan too. Even doing these things it looks like the nano has enough pins spare even though the DS1302 needs 3 as it doesn't use SDA/SCL.
Just like to thank you for inspiring me to do this project, it has been a most enjoyable learning curve . If everything works I may put the code and circuit on here as my first Instructable.
6 years ago
I succeeded to make it works with an Arduino Mega but I wanted to make it works with my Arduino UNO. I'm able to upload the code to the UNO but nothing is happening. Does anyone know if we need to modify something in the code to make it works on UNO ?
6 years ago
Hey, when i power up the RTC the display is not working. Is this a power issue ? Im using a chines UNO clone.
6 years ago
Awesome!! It worked great. The transitions are perfect and everything looks good! The only thing I'd add is to insert a couple more spaces after "Day " on the LCD printout because after the first "Wake up!" you will get "Day p!" since it isn't long enough to overwrite that part of the previous state.
Thank you very much for posting this!
6 years ago
Glad to see you added white in your v2 as well as added fades! I'm going to be trying this later this weekend when my RTC arrives.
Out of curiosity, how come you didn't use the 5V from the Arduino for the RTC and LCD instead of adding that voltage regulator?
Reply 6 years ago
The power of the arduino is too low for the full RGBW strip. You do need external power. ;)
Reply 6 years ago
Sorry- I don't mean for the RGBW strip, but specifically for the RTC and LCD. Wouldn't the 5V output pin on the arduino be enough for those? Isn't that what the voltage regulator is doing, lowering from 12V to 5V for those items?
Reply 6 years ago
Ah, now I see. Yes, it should be possible to power them from the arduino instead.
7 years ago
I copied and pasted from the link.
I went back and downloaded and opened and it works, thank you!
Reply 7 years ago
Good to hear that. Copy-paste can give some symbol problems sometimes. Enjoy it!
7 years ago
Thanks Azielaan015. The only quotation marks in the eleven expected unqualified-id before numeric constant errors is in line 1. I replaced those quotion marks with 0x22 but it didn't do the trick.
These errors make no sense to me because lines 9,11 and 14 are all blank but only lines 11 and 14 have that error listed. Also the 4 lines where you define REDPIN, WHITEPIN, BLUEPIN and GREENPIN, only GREENPIN gets that error.
What this sketch does is perfect for my tank. If you could help sort this out, I'd be forever grateful.
Reply 7 years ago
Did you copy/paste the code from github, or did you download and open it?
7 years ago
sketch_jan16a:5: error: stray '#' in program And then the same thing except :6:, :9:, :10:, :11:, :12: and :13: for a total of seven of these errors.
sketch_jan16a:6: error: expected unqualified-id before numeric constant
And then then the same thing except :9:, :12:, :5:, :17:, :21:, :28:, :33:, :50:, :65:, and :86: for a total of eleven of these errors.
This is from your edit v.2 code. I'm using the Arduino 1.0.6 program.
Thanks!
Reply 7 years ago
Probably sth like this:
"The problem is that you have Unicode quotation marks instead of ASCII quotation marks; probably your editor automatically changed them, or you copied the text from a site that does this automatically in its authoring software. Replace the quotes with normal ASCII quote (0x22, ") and it should work."
http://askubuntu.com/questions/272741/how-to-fix-compilation-errors-that-mention-stray-342-and-stray-200
7 years ago
First of all, thank you for sharing your project. I thought this would be good for my aquarium lights as well, but when I loaded the code to the Arduino program and clicked 'verify' I got a long list of errors.
I have an UNO and a DS3231 RTC and am having an awful time time trying to get it hooked up. Any help would be appreciated.
Thanks.