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.

Using an LED Aquarium Light

huy-phan-nJrSZM_OaJg-unsplash

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.

What Do You Need?

aquarium light parts

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

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

You will also need some 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

aquarium light full circuit

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.

Wiring the Real-Time Clock

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 directly wired 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

Wiring the LED Strip

aquarium light led strip circuit

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.

  • DIN to Digital Pin 7 on Arduino
  • GND to GND on Arduino and Negative (-) Power Source Terminal
  • VCC/5V+/12V to Positive (+) Power Source Terminal
  • It is highly recommended that you use a 1000uF capacitor across the Negative (-) and Positive (+) Power Source Terminals to prevent damage to your LEDs

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.

Coding Your DIY Arduino 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 outside of the functions that come with it.

Adding the Libraries

Before adding any code, we need to install some libraries, and all of these can be found within the Arduino IDE Library Manager.

  • Wire.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 regular WS2812 LED strip.
  • RTClib.h: This library enables us to control our DS3231 RTC module.
        #include <Adafruit_NeoPixel.h> //LED Strip library

#include <Wire.h>

#include <RTClib.h> //RTC Library

Adding Global Variables (Optional)

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.

Declaring & Initializing LED Strip/RTC Objects

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.

        #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

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.

        RTC_DS3231 rtc;
    

Once this is complete, we just need to initialize our RTC using the following code in our setup 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

Building the Timer Loop

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.

          DateTime now = rtc.now(); //Collects the current time

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

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.

          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 Full 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
}

Fitting Your LED Aquarium Lighting

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.

DIY Arduino Aquarium Lights

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.