Share My Creation aquarium LED light controller with raspberry pi

My current fun project is a controller for our small familiy aquarium (fish tank) we bought last christmas.

The light for the aquarium was 20 years old and I decided to replace it with LED stripes. Since the LED stripes I bought were far too bright I started to build a controller based on a raspberry pi with a B4J software to dim them. This controler can currently be used to slowly dim on and off the light. Since I have 3 LED stripes, two white ones and one RGB, it is possible to create very realistic surise and sunset simulations and even a nice moonlight. It is planned to develop the software further to support cloud simulations etc.

The Hardware:
The whole thing is based on a raspberry pi. The LED stripes can be dimmed with PWM so I first tried to use jPi4J library with software PWM. I was not satisfied with the result because the LED stripes were flickering because the software pwm uses a very low PWM frequency. A test on the hardware PWM port of the raspberry pi was much better. So I decided to order the ADAFruit 16 channel PWM board for the raspberry pi which has 16 hardware PWM channels. This board uses the i2c bus to communicate with the pi so I had to write a small wrapper library to access it easily.

This is the Raspberry pi with a custom built LED driver module and the Adafruit PWM board. I can currently use 6 of the 16 PWM Channels but I only need 5 so far (1 for each white stripe and 3 for the RGB):
IMG_20160131_233022.jpg IMG_20160131_233040.jpg

Here you can see the LED stripes:
IMG_20160131_231710.jpg IMG_20160131_231754.jpg

The whole project "in use":
IMG_20160214_162009.jpg

I can't show much of the software because it is in an very early state. I started with the controller part which now can smoothly dim the LEDs between any value. In the moment schedule times are hardcoded in the B4J program so I could use the controller as early for the aquarium as possible.

Currently I'm working on the user interface which is done with ABMaterial. So if all is finished it will be possible to control the Aquarium lights with every web browser even from the smartphone.

The first idea was to use MQTT for cummunication with an B4A app. Maybe I will do this later so I can check the status of the lights even if I'm not at home. But that are future thoughts.

So I can only say that the B4X products are absolutely great and very flexible in its usage.
 
Last edited:

Siam

Active Member
Licensed User
Longtime User
cool!
i work at a similar project for my two Aquarium.
i plan the following functions

- Controll 1 (2) Led Bar's with 11 Cree High Power led's (it's working to access this led's b4j i Use the PiGPIOD)
- Controll one Bar RGB Led with ws2812b Leds (it's working with this as daemon needs the Hardware PWM port)
- One LCD Display (working)
- One Temperature sensor DS1820 to controll the wather Temp.(working)
- Controll The Power for Heater, Air, Pump etc. with solid state relays (working)
- Controll PH and EC from the wather (in progress)

All this functions i controll over the mqtt Protocoll.

aquapi2.png aquapi1.png

Andy
 

woniol

Active Member
Licensed User
Longtime User
cool!
i work at a similar project for my two Aquarium.
i plan the following functions

- Controll 1 (2) Led Bar's with 11 Cree High Power led's (it's working to access this led's b4j i Use the PiGPIOD)
- Controll one Bar RGB Led with ws2812b Leds (it's working with this as daemon needs the Hardware PWM port)
- One LCD Display (working)
- One Temperature sensor DS1820 to controll the wather Temp.(working)
- Controll The Power for Heater, Air, Pump etc. with solid state relays (working)
- Controll PH and EC from the wather (in progress)

All this functions i controll over the mqtt Protocoll.

View attachment 41920 View attachment 41921

Andy
Nice projects.
How do you read DS1820 temperature. Do you have 1wire library for b4x.
 

Siam

Active Member
Licensed User
Longtime User
hi,

no at the moment is no Library for B4J aviable i work with the standard Kernel Module and open the file which will be created by this Kernel Module.

here a sample code the Value = 28-0000073c14fa = Adress from the Sensor

B4X:
'************************************************************************************************************************************************
'**                                                                                                                                            **
'***                                                 Temperaturfühler einlesen                                                                ***
'**                                                                                                                                            **
'************************************************************************************************************************************************

Sub gettemp As String
    Dim tempraw As String
    If File.Exists("/sys/bus/w1/devices/28-0000073c14fa/","w1_slave") Then
        tempraw= File.ReadString("/sys/bus/w1/devices/28-0000073c14fa/","w1_slave")
        Log ("temperatur: "& tempraw)
        Return readtempCompleted (tempraw)
    Else
        Log ("Keine Temperatur daten vorhanden")
        Return "-.--"
    End If
End Sub   

'************************************************************************************************************************************************
'**                                                                                                                                            **
'***                                              Temperatur auf gültigkeit prüfen                                                                ***
'**                                                                                                                                            **
'************************************************************************************************************************************************

Sub readtempCompleted (StdOut As String) As String
    Private BeckenTemperatur As String
    Private req() As String
    Private temperatur As Float
        req = Regex.Split("=",StdOut)
        If req(1).Contains("YES") Then
            temperatur=req(2)
            temperatur = temperatur/1000
            BeckenTemperatur=temperatur
            If BeckenTemperatur.IndexOf(".") <> -1 Then
                BeckenTemperatur=BeckenTemperatur.SubString2(0,BeckenTemperatur.IndexOf(".")+2)
            End If
        Else
            Log("temp. fehler "&DateTime.Date(DateTime.Now)&" "&DateTime.Time(DateTime.now))   
        End If
    Return (BeckenTemperatur)
End Sub
 

woniol

Active Member
Licensed User
Longtime User
hi,

no at the moment is no Library for B4J aviable i work with the standard Kernel Module and open the file which will be created by this Kernel Module.

here a sample code the Value = 28-0000073c14fa = Adress from the Sensor

B4X:
'************************************************************************************************************************************************
'**                                                                                                                                            **
'***                                                 Temperaturfühler einlesen                                                                ***
'**                                                                                                                                            **
'************************************************************************************************************************************************

Sub gettemp As String
    Dim tempraw As String
    If File.Exists("/sys/bus/w1/devices/28-0000073c14fa/","w1_slave") Then
        tempraw= File.ReadString("/sys/bus/w1/devices/28-0000073c14fa/","w1_slave")
        Log ("temperatur: "& tempraw)
        Return readtempCompleted (tempraw)
    Else
        Log ("Keine Temperatur daten vorhanden")
        Return "-.--"
    End If
End Sub  

'************************************************************************************************************************************************
'**                                                                                                                                            **
'***                                              Temperatur auf gültigkeit prüfen                                                                ***
'**                                                                                                                                            **
'************************************************************************************************************************************************

Sub readtempCompleted (StdOut As String) As String
    Private BeckenTemperatur As String
    Private req() As String
    Private temperatur As Float
        req = Regex.Split("=",StdOut)
        If req(1).Contains("YES") Then
            temperatur=req(2)
            temperatur = temperatur/1000
            BeckenTemperatur=temperatur
            If BeckenTemperatur.IndexOf(".") <> -1 Then
                BeckenTemperatur=BeckenTemperatur.SubString2(0,BeckenTemperatur.IndexOf(".")+2)
            End If
        Else
            Log("temp. fehler "&DateTime.Date(DateTime.Now)&" "&DateTime.Time(DateTime.now))  
        End If
    Return (BeckenTemperatur)
End Sub

Thanks for the code example.
I'll give it a try as soon as i get thermometer.
New pi4j 1.1 supports 1 wire. I hope for the wraper update as it get officially relesed.
 
Top