Aquarium Controller, Guidance to start needed

Hi everybody,

I need you to give me some push in the right direction. I want to do some automation for my aquarium. Commercial aquarium computers are very expensive, especially if I take into account the "complete" solution. I would also need to do a lot of workarounds and adaptions. Therefore I think the better solution would be to build a computer on my own. The arduino platform looks to me best suited as I could use a lot already existing circuits as well as program code.
I want to control the lights (4 channels), inject fertilizer, measure some values (pH, Temperature, ...), control the CO2 injection, log some data, ...
Maybe I also want to add some remote control/observation in case I am not at home for some time.

To sum it up I will need 9 analog inputs, 9 PWM outputs and 16 ditial I/O pins for all the sensors and controls. Plus all the things I could have forgotten at the momement.

I am not sure what would be the best setup for this. I was thinking about the following variants:

  • Every task gets its own little arduino and then I add some master control. That way I would be very flexible but I would need a lot of individual boards that need to be connected somehow. As several tasks will be cross connected (e.g. no CO2 injection when the light is off, ...) the communication between the boards can get quiet complex. What do you think. Can I get that to work reliable as a first Arduino project?
  • I am using one arduino board that controls everything. In this scenario I will get a hugh sketch and I will need to stack many shields. But all this inter task communication and the synchronisation would become much easier. I would also need to choose between a Mega and a DUE (Pro Mega: 5V, Pro DUE everything else especially the 12bit ADC and the far bigger RAM would be nice). The difficult thing would be to do extensions as I won't be able to include everything from the start. I would need to build this twice in order to be able to do an extension while the other system keeps the aquarium running.

I would seperate the remote control and observation from the rest as its a completely different thing. Actually I think to do everything important for the aquarium on the Arduino side and everything else on a small computer like a Raspberry Pi. The Arduino would be the reliable part that keeps the aquarium running. On the computer I could run a webserver to do the remote control and include a webcam far easier than on an Arduino. But that way I will need to establish some communication between the two systems.

For my background. I am a phyicist that has some experience in building (analog) circuits for controlling lab setups. I also have some experience in programming (mainly evaluation algorithms for the lab). My experience in C is long past but I don't think that the programming part will give me a headache. I have a lack of experience in digital electronics. Everything beyond following circuits from datasheets or examples on the web might be beyond my skills.

What do you think. How should I try to realize my "little" project.
Any suggestions?
Thank you
Daniel

Your IO needs are not that intense. I believe a Mega2560 has all the IO pins needed, nothing needs blazing speeds for monitoring or control. A screw sheild like mine will let you easily connect things.
Why do you inject fertilizer into an aquarium? Seems like that would be bad for the fish. I never had more than a simple 1-2 fish tank with a filter tho, am sure there is plenty I don't know about more complex systems.
http://www.crossroadsfencing.com/BobuinoRev17/

I certainly would not use an arduino per task - a single controller will be much easier. The Mega could serve up your web page, but I prefer your idea of using a Pi - it can handle logging and render a more complex site with graphs & the like.

Just remember to divide & conquer - don't try to do it all at once or debugging will be hell.

Thanks for the advice. The mega was my first thought. I was just wondering about the problem if I want to add something. As soon as the system is installed with a limited amount of features it needs to be kept running. Therefore I would need a second system to add new features and then switch the systems. This would be easier with individual arduinos as new featuers would be independent. But as you already pointed out a single arduino is much easier to handle.

Regarding the question Mega vs. Due. As you already pointed out by you guys I do not need the calculation power of the Due and its 3.3V layout wil make trouble with a lot of the existing shields. But some aspects of the Due would really help. First of all the higher precission DACs. I started to think about this project as I have the need to control the pH value of my aquarium by injecting CO2. Measuring the pH with a probe is most probably the most complicated task in this project. The probes have a huge internal impedance (>100GOhm) and they generate a voltage of 30-80mV/pH (depending on the probe, the probe age, ...). I would need to calibrate the measurement using two sample liquids of know pH-value (4 and 7) or better 4 and 9 and measure the pH value with an accuracy of 1.5 or better 2 decimals. A 10 bit ADC is at its limit here. Therefore the 12 bit ADCs of the DUE would help (I know that I will need a carefully designed analog circuit to really achieve 12bit reolution).
I am also worried about the 8kB RAM of the Mega. I didn't check my demand yet, but as a lot of the tasks are time triggered with several trigger points per day and at least for some of them I need the possibility to have different settings on different week days 8kB might be tight. The 96kB of the DUE would be most certainly sufficient. Is there a way to increase the RAM of the mega in any way?

Regarding the fertilizer question: You need special aquarium fertilizer and even then you have to check if it is not poisnous to some of the inhabitants. It is needed to provide the plants with nutrients. If I forget it for one or two days (e.g. beacuse I am out of town) I get a huge problem wiht algae. Basically you need to provide the plants with everything in the right amount to grow well so they use up everything algae could use for growing. If the plants don't grow well algae will grow for sure.

Daniel

I can't imagine how you would fill 8KB RAM with an aquarium controller, even a complex one like a planted tank or reef tank. If you're doing things with Ethernet and SD cards, then the typical 2KB Arduino Uno can struggle with RAM consumption due to the buffers those things require, but 8KB is just gobs, even for that.

To be clear, the Mega is able to address an external RAM chip. But I just can't see you needing it for this application.

Remember that your program code is not loaded into RAM. It is executed directly from flash (PROGMEM). You can write thousands of lines of code that compile down to the 124KB of flash, and if you use global variables and scoped function variables sparingly, you might only consume 1 or 2KB of RAM during runtime no matter how big your code is.

Sorry for my English its not my native language.
I just finished my controller. I used Mega and it does everything you want to do plus auto top-off and water change, gH, tds.
I preferred all in one, so I fit everything in one box.
Make a good plan before you start. If you don't do it, your controller will coast you twice or three times more then any available controller on the market(from my experience).
See pictures.

Hi Olexiy, very nice aquarium. Could you tell me how the plant in the front left corner is called? This one looks nice.

Back to the aquarium computer. Could you share some data about your aquarium computer? That could most definitely help me with my planning. I am especially interested in your circuit to measure the pH value.

Regarding the memory usage: I did a quick summary this evening and I came up with 3667byte for all the settings I would need to store. The most memory consuming part is the light regulation as I want to be able to control 4 lamps individually with different settings on different days and fading the lights in and out (to simulate something like sunrise, sunset as well as cloudy weather on some days). In addition to this there is the memory consumption for control and other variables that need to be stored. As well as some buffers for e.g. SD card (as the EEPROM will be to small) as well as for some sort of display. I could reduce the memory usage of I would only keep the current and the next setpoint in memory but this needs careful planning as well as smart storage of the data. This might even be necessary to stay within the 8kB limit of the mega.

Thanks everybody so far for your contribution
If you have any more thoughts please share them
Daniel

I expect you'll find that that 3667 byte requirement can be somewhat reduced by bit twiddling tricks and the like. In addition, you could just keep the light time & fading data on the SD card and load it on demand - speed isn't going to be a factor.

Alternatively, you could just ask the Pi for the days data.

Plant name is blyxa japonica.
PH wasn't cheap but very easy. http://atlas-scientific.com/circuits.html?
I'd call my controller - experiment. I want to see what finally will come out from it.
I didn't do any data logging. For my opinion it is unneeded feature.
Lighting I control in two ways. One way just send IR data for Current Satellite led
http://current-usa.com/aquarium-led-lights/satellite-freshwater-led-plus/
Another way sunrise, sunset, full spectrum and clouds. Clouds is simple. There is two colors red and white. Just fading white color you will get what you want. In a future I'll do more colors.
Currently I get stack on ATO and water change system. I'd like to teach controller work with out mistakes. You imaging what can happen if something goes wrong when you live on the 8 floor?

I didn't do any data logging. For my opinion it is unneeded feature.

Once things are working you can certainly leave logging out - invaluable for debugging though. I'd leave the logging in the code though, disabled if desired, against the day that you discover that the system isn't working quite as you had hoped.

Olexiy:
Currently I get stack on ATO and water change system. I'd like to teach controller work with out mistakes. You imaging what can happen if something goes wrong when you live on the 8 floor?

I have a reef. Currently, the ATO is just two float switches in series, but I'd like to Arduino-ize it. My plan:

Still use two float switches. Both switches need to agree before taking action.
Measure the time between topoff events and keep a running average.
Measure the topoff pump run time and keep a running average.
If one float switch responds and the other doesn't after a specified timeout, throw an error and enter "limp" mode".
Limp mode: the nonresponding switch is ignored now. Only the remaining switch is considered as input.
If too too long a time passes during topoff without either float responding, throw an error and enter "blind" mode".
Blind mode: use the previously collected average time between topoffs and topoff pump runtime variables to topoff without any input from the float switches. Actually, run the topoff pump a bit less, as too little topoff is preferable to too much topoff.

My idea:
flow meter on water in
flow meter on water out
float switch low
float switch high
ultrasonic range finder on top of it.
Also measure time. I didn't create algorithm yet, still thinking. :slight_smile:

For the automatic water change/refill system I also had some thoughts.
There are two main risk:

  • Removing too much water -> Unhappy fish
  • Filling in too much water -> Flooding the apartment

Removing too much water can be preented easily. Just make sure that the tube used for this ends sufficiently high in the aquarium. As this is a complete mechanical solution you can't mess it up with whatever faults there are in the electronics. To control the amount of water that is removed it is also possible to just time it. Measure the flow rate you get when you open the valve. This should be a stable value as long as you don't change anything here. That way you don't need the flow meter.

Filling in too much water is harder to prevent. There are aquarium tanks that have an overflow which can be connected to a tube for this. As long as you make sure that the water flow into the aquarium can't exceed the capabilities of this overflow you are save. Unfortunately I didn't think about this as i bought my aquarium. I am currently thinking about the following solution. For the safety solution I will use a system composed of two elektrodes and measure the resistance between them (These systems have a name but i can't remember it). These two electrodes will be at the top of the aquarium. As soon as they touch the water the resistance between the two will drop dramatically and this will trigger a valve to close the water inlet. For the automatic water refill I will use a level meter (I didn't deside which technology I want to take) and define minimum and maximum values for the water level. Start the refill if the water level drops below the minimum value. Stop it as soon as it reaches the maximum value.

Using this the possible fails would be:

  • No refill -> A water level at least at the minimum defined by the position of the water extraction tube
  • No extraction -> A water level that is below the limit defined by the two electrodes
  • Permanent extraction (if it can't stop and the refill is fast enough) -> Fish and plants have to live with the water that is refilled

All situations are safe for the appartment. Fish and plants should be able to tolerate both situations for the water level for at least several days. Most probably for a few weeks. And could only get problematic if the water used for refilling the tank is of insufficient quality for the fish and/or plants. But this would be a problem anyways.

You can't guarantee 100% that no malfunction will ever occur (see: Space Shuttle), but you can have secondary and tertiary failsafes. For example:

Have two independent systems to sense water level. Use your probes and your microcontroller primarily, but have a totally separate float switch (positioned a bit higher) connected to a relay which provides power to your pump. Even if the microcontroller or probes malfunction, power is cut to the pump by the electromechanical system.

Etc.

Thats very true. 100% safety is impossible. And you also mentioned the best way to improve it. Couple different systems. And one should couple different systems that work differently because if the system has a systematic error regardless the number of systems. And for safety systems one should choose systems as simple as possible as it is easier to check them for errors. Thats why I mentioned the overflow as well as an appropriate positioning of the tubes as these work as long as the mechanics is ok.