Introduction: Aquarium LED Light Controller Based on Raspberry Pi
Having a fish tank is good for a hobby and good for a profession.
One of the key components of a fish tank is the proper lighting system (among others).
There's much literature on the internet about this theme, from the very basic on-off timer switch until the sophisticated sunrise-sunset-season controllers.
Step 1: Starting
Neon lights are commonly used, but only permits using of on-off lighting of an aquarium.
In case some wants sunrise-sunset controlling, LED lighting is a must.
LED strips are easily controllable through PWM (pulse-width-modulation) signals, can be bought with up to IP67 protection...
There are a lot of aquarium lighting systems which controls the amount of illumination by varying the LED strip’s power. Even the sunrise-sunset-season controllers are using this, but in a time controlled way (they ramp up the power from zero to max and then down to zero…).
All these systems consist of the following three components: a PSU, a controller and the LED strip. The only thing that I cannot find is a truly light controlling system which measures the actual light intensity and control the LED strip's power based on the illuminance.
This „only” needs the use of a light sensor.
This was the point when the idea of the "Aquarium LED light controller with RPi" was born.
Step 2: True Light Control
The starting points of an easily usable, programmable light
controller were the followings:
- Full light control with PWM capable of 0-100% control
- Exact light measurement (no LDR or other inaccurate techniques)
- Easily programmable through PC or smart phone
- Can be used with almost every LED lighting or insead of existing controllers
- Accurate timing (not suffering from RTCs' long term time shift)
The first 4 points would point to a microcontroller based system, but the 5. point needs internet connection and NTP protocol. The choice of using Raspberry Pi was the need for rapid, simple development, and easy upgradeability.
Step 3: Main Components
Firstly the light sensor was chosen. The BH1750 based light sensor module communicates through I2C bus, measures with very wide range and high accuracy, and is a cheap one.
Secondly the PWM signal - which comes out of the RPi - must be amplified to drive the LED strip. A simple "noname" 3 channel LED amplifier / repeater was chosen.
And lastly - the Raspberry Pi - can be any of its sub types (model A-B-B+-B2-B3-zero...). Actually the very first edition of RPi model B (with 256 MB RAM) was used, because it was at hand with a 4 GB SD card.
The controlling software runs on it, with its own graphical user interface, so the development took place on the RPi, no other programming device needed.
Since no one would like to have a monitor next to a fish tank, there is a need for remote accessing the RPi. The actual screen of the RPi can be seen through VNC connection either from PC or smart phone.
Step 4: Hardware
The following compontents needed for the light control system:
- Raspberry Pi
- BH1750 light sensor
- LED amplifier
- fuses
- thermal switch
- 12V power supply
Fuses are used to protect the 12V line (each segment of LED strip is fused, so if one segment goes to short circuit then it will not cause a total short of the power supply).
Thermal switch is normally closed and is glued (with thermal grease) to the LED strip’s heat sink. If the temperature of the heat sink rises above 50°C then it simply opens the circuit and protects the LED strip from overheating. KSD9700 type (50°C) was used. If its temperature rises above 50°C, the thermal switch opens and remains opened until the temperature falls below 35°C.
This feature is just for safety, under normal conditions it will not operate (open) at all.
The 12V power supply is a generally used one, 12V/6A type.
Step 5: Software
As mentioned, the software runs on the Raspberry Pi.
The main concept was to easily and rapidly develop the controlling software.
Since the initial setup of the aquarium light system takes place only occasionally (1-3 times), the appearance of the software is minimalistic: only the main informations shown and the input elements are only buttons to be smart phone friendly.
The software was written in python, uses tkinter as the graphic user interface.
The program starts after the Pi boots, reads its settings from config file. In order to have exact time, the Pi needs internet connection (actal time comes from network time protocol).
Remote connection takes place through vnc (virtual network computing) protocol, via x11vnc, no encryption, no password, just simple remote display and control.
The light control has 9 time steps, each step has its illuminance setpoint. The intermediate points (between two setpoints) are calculated with linear interpolation.
There are 2 additional time switches, which can control for eg. pump, CO2 infeed…
The software is what you can see, everything is obvious, with all the (necessary) informations shown. The base resolution is set to 1024x768 to fit for phone screens.
The control schema is a simple integrating controller with a deadband. The power level control has 1000 steps, so 0.1% is the least change in the output, which is perfectly fine enough.
Raspberry Pi has only one hardware PWM output, which is used in this project. The maxium PWM frequency (with 1000 step resolution) is 9600 Hz, but real world experiments (done with oscilloscope) showed that anything above 1000 Hz is useless (simply the LED strip is not fast enough), actually 960Hz was set.
When the actual time equals a time setpoint, the program stores the actual power level in the configuration file.
If the light sensor fails, then a blinking red LED shows this, but the light control continues with the previously saved power level datas.
Step 6: Arrangement, Setup
The light sensor is a bare PCB module (as can be seen), which proved to be very difficult to make waterproof, so actually the light level of the water surface is measured.
Some additional notes: formerly the aquarium had neon lights switched on for 10 hours interval.
The light level at the surface was 15800 lux, so the luminous exposure is roughly 158000 lux.h daily.
The LED lighting must produce approximately the same luminous exposure than the neon lights, with sunrise-sunset control.
The actually used pattern was taken from:
http://www.pveducation.org/pvcdrom/properties-of-...
To sum it up: the aquarium really looks different with sunrise sunset being used, the nature wakes up in the morning… the whole looks better…
Step 7: Code, Setup
Rasbian Jessie was used as the operating system, so at first this is to be downloaded:
https://www.raspberrypi.org/downloads/raspbian/
Atfer writing the Jessie image to the RPi's SD card, connect a HMDI monitor, a keyboard, a mouse, an ethernet cable and plug the SD card to the raspberry, then switch ON.
The following steps needed to set up the light controller:
- Start a Terminal window
To enable the I2C interface on the Pi, type:
sudo raspi-config
Then go to the menu: Advanced / I2C / Yes
Then exit from raspi-config.
A few modification is needed in the config.txt file, so type:
sudo sed -i 's/^#hdmi_force_hotplug/hdmi_force_hotplug=1/g' /boot/config.txt
sudo sed -i 's/^#hdmi_group/hdmi_group=2/g' /boot/config.txt
sudo sed -i 's/^#hdmi_mode/hdmi_mode=16/g' /boot/config.txt
Then copy the 'Aquarium_LED_light_control.py', the 'LED_PWM_wiringpi.py' and the 'Light_control.ini' files to /home/pi.
(The 'Aquarium_LED_light_control.py' is the main program, while the 'LED_PWM_wiringpi.py' is for testing. The testing can be done via directly modifying the power output, while seeing the change in the illuminance. 'Light control.ini' file is neccesary to run the main program.)
Then type the followings:
sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt-get install -y python-dev python-pip
sudo apt-get install -y python-smbus i2c-tools
sudo pip install wiringpi2
sudo apt-get install -y python-tk
sudo apt-get install x11vnc -y
sudo cd /home/pi/.config/autostart
echo [Desktop Entry] >x11vnc.desktop
echo Encoding=UTF-8 >>x11vnc.desktop
echo Type=Application >>x11vnc.desktop
echo Name=X11VNC >>x11vnc.desktop
echo Comment= >>x11vnc.desktop
echo Exec=x11vnc -forever -display :0 >>x11vnc.desktop
echo StartupNotify=false >>x11vnc.desktop
echo Terminal=false >>x11vnc.desktop
echo Hidden=false >>x11vnc.desktop
echo [Desktop Entry] >lxterminal.desktop
echo Type=Application >>lxterminal.desktop
echo Name=LEDaqua >>lxterminal.desktop
echo Exec=lxterminal -e 'sudo python /home/pi/Aquarium_LED_light_control_wiringpi_fullscreen.py' >>lxterminal.desktop
echo StartupNotify=false >>lxterminal.desktop
echo Hidden=false >>lxterminal.desktop
sudo reboot
After the reboot the light controller is ready to use, with or without monitor, can be accessed through VNC.
Enjoy!