Create DIY Aquarium Lighting with Arduino

Aquarium plants need light to create energy through photosynthesis, while many fish benefit from a regular light cycle, but how do you provide them with artificial lighting with the electronic DIY tools you already have? Let’s build a DIY aquarium lighting system using an Arduino, a real-time clock, and an LED strip.

Using a LED Aquarium Light


huy-phan-nJrSZM_OaJg-unsplash

Before we begin, it should be noted that the LEDs we are using in this project are not full-spectrum LEDs that mimic daylight. This means that they don’t provide all of the plant-beneficial light wavelengths, making them unsuitable for aquarium plants with large light requirements and wasting a small amount of energy produced by LEDs.

That said, for planted aquariums that require little light, LED lighting like this can be a great choice that provides faster, healthier plant growth without the cost associated with many aquarium lighting products; you just won’t get the same power.

It’s not just the plants in your aquarium that benefit from LED lighting: many species of fish benefit from a regular light cycle that mimics day and night to maintain their circadian rhythm, allowing them to rest, foraging for food and being active as they would. to 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’ll use an Arduino, a real-time clock (RTC), and an LED strip, as can be used for a wide variety of Arduino LED lighting projects.

USE VIDEO OF THE DAY

What do you need?


aquarium lighting parts

You only need a handful of parts to complete this build:

  • 1x Arduino microcontroller with SDA/SCL pins (Uno, Leonardo, Micro, etc.; we use a Pro Micro)
  • 1 DS3231 PSTN module
  • 1x WS2812/WS2812B NeoPixel RGB LED strip with IP65 or higher rating (we use a 1 meter 60 LED WS2812 strip that has been sealed with silicon; you may benefit from using more LEDs if you have a tank over 20 gallons)
  • 1x 12v AC to DC power adapter with female barrel connector
  • 1x 1000uF capacitor (optional)
  • Assortment of wires and heat-shrink parts
  • Superglue/double sided tape
  • 3D printer filament (optional)

You will also need a few tools to complete this project.

  • A soldering iron
  • Wire Cutters/Strippers
  • A heat gun
  • A 3D printer (optional)

Wiring Your DIY Aquarium LED Light Setup


complete aquarium light circuit

Wiring up your DIY aquarium lighting is simple, with just a few connections to make before you can start coding your project. The diagram above shows all the connections you need to make, but we’ve detailed them in the sections below.

Real-time clock wiring


aquarium light rtc circuit

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 wired directly to our Arduino Pro Micro.

  • SCL to 3 on Arduino
  • SDA to 2 on Arduino
  • VCC to 5V on Arduino
  • GND to GND on Arduino

LED strip wiring


led strip circuit aquarium light

Wiring your LED strip is more complicated than 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 of your LEDs. The schematic above shows how you can connect your NeoPixel LED strip to your Arduino and power source for best results.


  • DIN to digital pin 7 on Arduino
  • GND to GND on Arduino and negative (-) power source terminal
  • VDC/5V+/12V to positive (+) power terminal
  • It is highly recommended to use a 1000uF capacitor across the negative (-) and positive (+) power source terminals to prevent damage to your LEDs.

In addition to connecting our LED strip to our Arduino and 12V power source, we will also modify our NeoPixel clone to create three smaller LED strips that will be daisy-chained together with a long cable. For this we will use an insulated triple conductor cable, as well as a heat shrink to seal the joints. Our LED strip comes with JST connectors on each end, giving us a convenient way to detach the strip from our Arduino.

Coding Your Arduino DIY Aquarium NeoPixel Lights

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 apart from the functions that come with it.

Adding libraries

Before adding code, we need to install some libraries, and all of them are in the Arduino IDE library manager.

  • Fil.h: This library comes with the Arduino IDE and allows you to communicate with I2C components, like our RTC.
  • Adafruit_NeoPixel.h: This library adds functions/classes to control NeoPixel LEDs, but it works just as well with our usual WS2812 LED strip.
  • RTClib.h: This library allows us to control our DS3231 RTC module.
#include  //LED Strip library
#include
#include //RTC Library

Adding global variables (optional)

We’ve added global variables to our code so that we can change how our lighting behaves with buttons and other inputs in future projects. It’s not essential, but it will make it easier to modify your code when you need to make changes. We added variables for LED brightness and tint, and a variable to store the color of our LED strip.


Declaration and initialization of LED strip/RTC objects

Next, we need to declare our LED strip and our RTC as objects that can be used by our Arduino, and then initialize them in our configuration loop.

Our LED strips can be declared by first defining the pin used and defining the number of LEDs on the strip, but then you can use the lines below to make the declaration itself.

#define LED_PIN 7 // Sets our LED strip to pin 7
#define LED_COUNT 60 // Sets the NeoPixel LED count
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); //Declares our LED strip object

RTC is easier to declare and you just need to use the line below to make it work; all important settings are applied by default.

RTC_DS3231 rtc;

Once this is done, we just need to initialize our RTC using the following code in our configuration class.

 Serial.begin(57600); //Begins our serial connection

#ifndef ESP8266
while (!Serial); // Wait for serial port to connect
#endif

if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (1) delay(10);
} //This tests to make sure that our RTC is connected

Build the timer loop

Now is the time to build the main loop for your aquarium LED strips. This is handled in the main loop that comes with your empty Arduino project, which means it will run continuously.

We start the loop by checking the current time with our real-time clock and setting a variable to store it, ensuring daylight is provided during the day. Once we have a Date hour variable to play with, we can assign the current hour and minute to separate variables, allowing us to control our lighting with great precision.

 DateTime now = rtc.now(); //Collects the current time
int hh = now.hour(); //Applies the current our to a variable

Then we used a series of if statements to determine whether to turn on our lights. these if Check if the current time is equal to or greater than 9am and equal to or less than 9pm, which gives us a 9am to 9pm window to turn on our LED lights.

If these conditions are met, code in the if sets the brightness and color of our LED strips to the global variables we defined earlier, while using a To display command to update the LED strip. If the conditions are not met, a other The statement is used to set the brightness of the LEDs to 0, effectively turning them off at night.

 strip.begin(); //Turns on the LED strip
strip.show(); //Shows the LED changes from each loop

if (hh <= 8) { //If the time is equal or less than 8AM, the LED strip is cleared
strip.clear();
}
if ((hh > 8) && (hh < 21)) { //If the time is between 9AM and 9PM, the LEDs turn on
strip.setBrightness(255);
strip.fill(yellowWhite, 0, 59);
}

if (hh >= 21) { //If the time is equal or greater than 9PM, the LED strip is cleared
strip.clear();
}

The complete code

#include //LED Strip library
#include
#include //RTC Library
#define LED_PIN 7 // Sets our LED strip to pin 7
#define LED_COUNT 60 // Sets the NeoPixel LED count
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); //Declares our LED strip object
uint32_t yellowWhite = strip.Color(255, 251, 201); //Creates a light color variable
RTC_DS3231 rtc; //Declares our RTC object
void setup() {
Serial.begin(57600); //Begins our serial connection
#ifndef ESP8266
while (!Serial); // Wait for serial port to connect
#endif
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (1) delay(10);
} //This tests to make sure that our RTC is connected
}
void loop() {
DateTime now = rtc.now(); //Collects the current time
int hh = now.hour(); //Applies the current our to a variable
strip.begin(); //Turns on the LED strip
strip.show(); //Shows the LED changes from each loop
if (hh <= 8) { //If the time is equal or less than 8AM, the LED strip is cleared
strip.clear();
}
if ((hh > 8) && (hh < 21)) { //If the time is between 9AM and 9PM, the LEDs turn on
strip.setBrightness(255);
strip.fill(yellowWhite, 0, 59);
}
if (hh >= 21) { //If the time is equal or greater than 9PM, the LED strip is cleared
strip.clear();
}
delay(1000); //Delay for stability
}


Installation of your LED aquarium lighting

Our LED strip comes with a handy adhesive strip attached making it incredibly easy to attach to our tank hood/lid. The same result can be achieved with double-sided tape or superglue, but you need to be careful that the adhesive you choose can survive condensation buildup. You can also 3D print a stand for your new aquarium light if your tank doesn’t have a cover, and a case for the other components you used.

DIY Arduino Aquarium Lights

Aquarium plants and fish benefit from a regular light cycle. Although our light is not full spectrum, it still provides much of the blue light, green light, and red light your plants need. What’s best, however, is that this project is incredibly affordable, simple, and fun to tackle.


The pet store aquarium
Best Smart Aquarium Tank Accessories

Automate your aquarium by investing in smart accessories that will reduce the need for manual intervention, keeping your fish healthy and happy.

Read more


About the Author

Comments are closed.