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.


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

<p>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.</p><p> 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.</p>
<p>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 ?</p>
<p>Hey, when i power up the RTC the display is not working. Is this a power issue ? Im using a chines UNO clone.</p>
<p>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 &quot;Day &quot; on the LCD printout because after the first &quot;Wake up!&quot; you will get &quot;Day p!&quot; since it isn't long enough to overwrite that part of the previous state.</p><p>Thank you very much for posting this!</p>
<p>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.</p><p>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?</p>
The power of the arduino is too low for the full RGBW strip. You do need external power. ;)
<p>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?</p>
<p>Ah, now I see. Yes, it should be possible to power them from the arduino instead. </p>
<p>I copied and pasted from the link. </p><p>I went back and downloaded and opened and it works, thank you!</p>
Good to hear that. Copy-paste can give some symbol problems sometimes. Enjoy it!
<p>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.</p><p>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.</p><p>What this sketch does is perfect for my tank. If you could help sort this out, I'd be forever grateful.</p>
Did you copy/paste the code from github, or did you download and open it?
<p>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.</p><p>sketch_jan16a:6: error: expected unqualified-id before numeric constant</p><p>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.</p><p>This is from your edit v.2 code. I'm using the Arduino 1.0.6 program. </p><p>Thanks!</p>
Probably sth like this: <br><br>&quot;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, &quot;) and it should work.&quot;<br><br>http://askubuntu.com/questions/272741/how-to-fix-compilation-errors-that-mention-stray-342-and-stray-200
<p>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. </p><p>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.</p><p>Thanks.</p>
Can you post the errors somewhere?
<p>Do you think this CNC would work to engrave/mill names in wood and acrylic pens? I turn pens on my lathe and have had lots of requests to engrave initials or names on them. Thanks</p>
<p>Great project! I'm looking forward to your next instructable!</p>
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.
<p>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!</p>
<p>cool instructable I like it!!</p>

About This Instructable




More by Azielaan015:Personalised Kinder Surprise gift Homebuilt (DIY) CNC router - Arduino based (GRBL) Arduino wireless (433MHz) Time-Control switch for multiple devices 
Add instructable to: