Build a DIY aquarium lighting system with an automatic timer using an Arduino, LED strip, and real-time clock.
Aquarium plants need light to create energy via photosynthesis, while many fish benefit from a regular light cycle, but how can you provide artificial lighting for them with the DIY electronics tools you already have? Let's build a DIY aquarium lighting system using an Arduino, real-time clock, and LED strip.
Before we get started, it is worth noting that the LEDs we're using in this project are not full-spectrum LEDs that mimic daylight. This means that they don't provide all the light wavelengths that are beneficial to plants, rendering them unsuitable for aquarium plants with heavy light needs and wasting a small amount of the energy produced by the LEDs.
That said, for planted aquariums with low light requirements, LED lighting like this can be an excellent choice that offers faster and healthier plant growth without the cost that comes with many aquarium lighting products; you just won't get the same wattage.
It isn't just the plants in your aquarium that benefit from LED lighting: many fish species enjoy a regular light cycle that imitates day and night to preserve their circadian rhythm, enabling them to rest, look for food, and be active as they would be in the wild.
To build an LED lighting system that powers a day-night cycle for the fish and plants in your aquarium, we will be using an Arduino, a real-time clock (RTC), and an LED strip—as can be used for a wide variety of Arduino LED lighting projects.
You only need a handful of parts to complete this build:
You will also need some tools to complete this project.
Wiring up your DIY aquarium lighting is simple, with just a few connections to make before you can get started with coding your project. The diagram above shows all the connections you need to make, but we have broken this down in the sections below.
The DS3231 RTC in this project acts as a timer for the LED lighting in our aquarium. This module has four pins that we will be using: SCL, SDA, VCC, and GND, all of which can be directly wired to our Arduino Pro Micro.
Wiring your LED strip is more complicated than the RTC, as the LEDs are likely to be some distance from the Arduino and you need to use a separate power adapter to get the full brightness from your LEDs. The diagram above shows how you can connect your LED NeoPixel strip to your Arduino and power source for the best results.
Alongside connecting our LED strip to our Arduino and 12V power source, we will also be modifying our NeoPixel clone to create three smaller LED strips that will be connected in a chain with a long cable. We will be using an insulated triple-core cable for this, along with heat shrink to seal up the joints. Our LED strip came with JST connectors on each end, providing us with a convenient way to make it possible to detach the strip from our Arduino.
The coding element of this project is more complicated than the wiring. You can start with a basic empty Arduino project, as we won't need anything outside of the functions that come with it.
Before adding any code, we need to install some libraries, and all of these can be found within the Arduino IDE Library Manager.
We've added global variables to our code so that we can change the behavior of our lighting with buttons and other inputs in future projects. This isn't essential, but it will make it easier to edit your code when you need to make changes. We added variables for LED brightness and hue, along with a variable to store the color of our LED strip.
Next, we need to declare our LED strip and RTC as objects that can be used by our Arduino, followed by initializing them within our setup loop.
Our LED strips can be declared by first defining the pin being used and setting the number of LEDs on the strip, but then you can use the lines below to make the declaration itself.
The RTC is easier to declare, and you only need to use the line below to get it running; all the important settings are applied by default.
Once this is complete, we just need to initialize our RTC using the following code in our setup class.
Now, it's time to build the main loop for your aquarium LED strips. This is handled within the main loop that came with your empty Arduino project, and this means that it will run continuously.
We begin the loop by checking the current time with our real-time clock and setting a variable to store it, ensuring that daylight is provided during the day. Once we have a DateTime variable to play with, we can assign the current hour and minute to separate variables, enabling us to control our lighting with great precision.
Following this, we used a series of if statements to determine whether to turn on our lights. These if statements check to see if the current hour is equal to or more than 9 AM and equal to or less than 9 PM, giving us a window of 9 AM to 9 PM to have our LED lights on.
If these conditions are met, code within the if statement sets the brightness and color of our LED strips to the global variables we set earlier, along with using a show command to update the LED strip. If the conditions are not met, an else statement is used to set the brightness of the LEDs to 0, effectively turning them off during the night.
Our LED strip came with a handy adhesive strip attached, making it incredibly easy to attach it to the hood/lid of our tank. The same result can be achieved with double-sided tape or superglue, but you need to be careful to ensure that the adhesive you choose will be able to survive condensation build-up. You could also 3D print a stand for your new aquarium light if your tank doesn't have a lid, and a case for the other components you've used.
Aquarium plants and fish benefit from a regular lighting cycle. While our light isn't full-spectrum, it still provides much of the blue light, green light, and red light that your plants need. What's best, though, is that this project is incredibly affordable, simple, and fun to take on.
Samuel is a UK-based technology writer with a passion for all things DIY. Having started businesses in the fields of web development and 3D printing, along with working as a writer for many years, Samuel offers a unique insight into the world of technology. Focusing mainly on DIY tech projects, he loves nothing more than sharing fun and exciting ideas that you can try at home. Outside of work, Samuel can usually be found cycling, playing PC video games, or desperately attempting to communicate with his pet crab.
Join our newsletter for tech tips, reviews, free ebooks, and exclusive deals!