# DIY Aquarium Controller



## Darkblade48

I alluded in my pressurized CO2 thread (http://gtaaquaria.com/forum/showthread.php?t=38868&page=2#18) that I had some other surprises coming in the mail.

With some of the spare time I have, I decided to start an Arduino based project for a DIY aquarium controller. Of course, being on a budget means that I don't want to simply go out to the LFS and purchase a controller (besides, building one is a lot more fun!)

I have a few ideas so far, but what I'm thinking of building is a controller that can:

Turn on/off lights on a schedule
Measure pH
Measure temperature
Turn on/off CO2 either based on pH or just timed schedule

Some other ideas I'm floating are ability to control peristaltic pumps for automated dosing and also wireless capability so that I can check/control the controller from anywhere (where I have internet...)

It all sounds so *easy*, but I actually have minimal electrical/electronics/programming experience (aside from a few courses in high school), so the process will be extremely slow. Not only do I have to learn C, but I also have to brush up on my basic electronics (how does a potentiometer work again...?).

At least I have most of the parts ordered (microcontroller board, relay board, temperature probe, pH probe, etc), and some have even arrived.

In any case, here's an obligatory "Hello World" sketch.


----------



## lybrian1

Thanks for the post. Could you give us detail like step by step instructions? I extremely interested and have thought about use arduino to control my led lighting system but I have no experience in programming. But as a tech savvy sort of guy I learn quite quickly. Please provide details instructions and photos. Much appreciated


----------



## Darkblade48

Right now, it's touch and go for me as well. I can't really provide detailed instructions (at least for the programming part) since I am still essentially on a "Hello World" stage for programming in C.

For the electronics, I'll have to prototype it on some breadboards first. I'll try to draw up some schematics, but no guarantee, since I usually do it all in my head anyway (bad habit).

I was considering having my controller control an array of LEDs too, but I haven't invested in any LEDs/done any investigation yet, and my T8s are working fine for now (haven't even upgraded to T5 bulbs; I remember when I was still using T12 bulbs and switched over to T8!)

The advantage of using LEDs is that you can choose colours (i.e. if you want a moonlight at night) and with the Arduino, there are some pins (depending on which board you use) that have PWM so you can dim the lights. I believe that if you want to control LEDs though, you may need an LED power shield, which is expensive.


----------



## smcx

i'm totally going to copy you!

ok, maybe just use you as inspiration


----------



## Darkblade48

Heh, there might be better people to copy than this amateur tinkerer.


----------



## smcx

nah. if you're going to document, you'll be easier to learn from.


----------



## Darkblade48

The electronic components and hookup isn't too bad and isn't too hard to wrap your head around, but the programming part is difficult.

I did some Turing (ha! Remember Turing?) and VB in high school, but that was about it, so the Arduino version of C is going to be a challenge.


----------



## AquaticPulse

where did you get the tech gear from?


----------



## Darkblade48

thinkshane said:


> where did you get the tech gear from?


Various sources; some of it I got from eBay, others I got from Sayal/Active/Digikey/Mouser.

The usual places


----------



## pyrrolin

I hate programming, if this, while that, else something, I had to take a couple basic courses in college but I was never good at it.

now html and xhtml I can do, but stuff like C++, I get messed up on the logic and syntax.

With luck you can find code that is close to what you need and just modify it.

Don't forget to make an app for your smartphone to!


----------



## Darkblade48

pyrrolin said:


> I hate programming, if this, while that, else something, I had to take a couple basic courses in college but I was never good at it.
> 
> now html and xhtml I can do, but stuff like C++, I get messed up on the logic and syntax.
> 
> With luck you can find code that is close to what you need and just modify it.
> 
> Don't forget to make an app for your smartphone to!


At least you took courses at the college level. 

As for the smartphone app, I don't have an ADK capable board


----------



## Darkblade48

Look at the goodies I got today:



So far, the pH board works well, as does the meter. I got it work with some sample code, sending commands and seeing the output via the serial monitor.

pH meter is calibrated and ready to go!


----------



## Darkblade48

An update.

Got temperature probe, pH probe as well as a relay (that is dependent on pH) working.



The pH module reads pH and controls the relay, sends the information back to the Mega 2560. The Mega also processes the data from the temperature probe, and then throws it along with the received pH onto the LCD.

Next on my to do list:

Get RTC working
Add in potentiometer for adjustable pH rather than hard-coded pH

Once I can get that done, it should be relatively easy to implement the touch screen features. With RTC working as well, I should be able to get the Mega to control a relay board (i.e. light timer, dosing pumps, etc). Again, with the touch screen, I can get user input to set the on/off timing of the lights/pump as well.

Edit: Sorry about the bad lighting for the LCD. Too lazy to retake another picture  Besides, once I get the 3.2" TFT LCD working, I won't need a 20x04 LCD 
Edit 2: For those that are curious, the LCD reads a pH of 3.23 and a temperature of 73.9 F. It also shows "WARNING" since my pH is too low (I'm measuring the pH of the electrode storage buffer)


----------



## PACMAN

wow this is an aweso build!!!


----------



## Darkblade48

PACMAN said:


> wow this is an aweso build!!!


Not really...but then I guess considering I know next to nothing about electronics and programming...maybe 

The last time I did programming was in Grade 10...which was so long ago that I'd have to calculate how many years ago that was. Then I'd get sad 

On top of that, I was using Turing, which is really just a learner's language.


----------



## SignGuy

I think i still have my Turbo Pascal textbook from 1993 you could borrow!


----------



## Darkblade48

SignGuy said:


> I think i still have my Turbo Pascal textbook from 1993 you could borrow!


Thanks, but Arduino coding is more similar to C and C++ than Pascal 

Not that I'd know the difference, hahaha.


----------



## Darkblade48

A long overdue update.










Cleaned up the wiring, decreased footprint. Some may wonder why I am not using a protoshield to reduce the footprint further; I will eventually get around to this (probably...maybe...we'll see). The protoshield that I ordered does not use stackable headers, and the ones that are already soldered are in the wrong place (will not allow further stacking). I may end up desoldering just the double row header, or might desolder all of them. All in all, it's a hassle, so that's why I'm using a breadboard for the time being.

I've removed the relay for the time being, since I've ordered an 8 channel relay board to replace it allowing for more things to be controlled (already have lighting, CO2, and two autodosers planned. I might put a heater on this as well, which still leaves 3 channels to be used. The ability to expand is nice).

Some may notice that the previous 20x04 LCD is gone too. This is because I plan to use this:










It's a 3.2" TFT Touchscreen LCD (320 x 240 pixels, 65k colours), so it can accept user input and display information, alarms, etc.

I've been tinkering with some of the coding from various sources and examples, and have some of it down...but that's for another update


----------



## Darkblade48

Might as well post a holiday gift for everyone 

You can ignore the strange times/date in the pictures; I didn't bother hooking up the RTC, so there's no time keeping...yet. The back-end coding is all there, however.

Got some parts of the main screen done, thinking about what else to put on.









The option screen (accessed once you tap the main/idle screen) is almost done.









Decided to take the screen in the dark to avoid glare, etc. Couldn't centre the image properly because of that...


----------



## Mlevi

This is tres kewl! 

Just curious. How does this compare to a shrink wrapped unit? I know the focus on most DIY is learning and/or the satisfaction of building, but I'm curious 
Is it that you can customize this unit to your exact needs? or it keeps the cost down? or the satisfaction?

BTW, kudos to you. I would be scared to attempt anything of this magnitude/complexity. I love trollin' the DIY segment of this forum. There is so much creativity, it empowers the desire to take a product and turn it on its head by using it for something other than its intended purpose, or building something from scratch.

Looking forward to the end result!

Merry Christmas!

Al.


----------



## Darkblade48

Mlevi said:


> This is tres kewl!


Thanks for the compliments 



Mlevi said:


> Just curious. How does this compare to a shrink wrapped unit? I know the focus on most DIY is learning and/or the satisfaction of building, but I'm curious
> Is it that you can customize this unit to your exact needs? or it keeps the cost down? or the satisfaction?


It is cheaper than a shrink wrapped unit, and can do everything that a shrink wrapped unit can do (or more). The unit is customizable, and at the same time, I can keep the cost down. Of course, there is satisfaction in seeing something that I built and programmed working as well 

*Some of the features that I have implemented:*
Touch screen TFT LCD
pH controller (pH monitoring and CO2 solenoid control)
pH probe calibration
Temperature monitoring
Automatic lighting
Automatic dosing

*Some other (software) features that I implemented:*
Screensaver
12/24 hour time display
Mth/DD/YYYY or DD/MM/YYYY date display
All settable selections (time display, date display, lighting times, dosing times, pH calibration setpoints (so that the curve can be calculated)) are saved to EEPROM so that even when the unit loses power, it will still have them in memory when power is restored)

*Other functionality that can be implemented:*
Automatic feeding
LED timing/dimming/moonlights
Auto-top off
Salinity/ORP monitoring
Customizable wavemaker settings (i.e. to match lunar phase)
Monitoring of LED temperatures so that a fan turns on when a particular temperature is reached
Data logging (pH, temperature, other data, etc)
Ethernet capability (i.e. control of CO2 (and pH), temperature, fans, lighting, dosing, feeders, etc over the internet)

That's the stuff that I can think of off the top of my head. You'll notice that many of the functions were originally designed to make a reef aquarium easier to maintain, but who says you can't use the same principles for a planted aquarium 



Mlevi said:


> BTW, kudos to you. I would be scared to attempt anything of this magnitude/complexity. I love trollin' the DIY segment of this forum. There is so much creativity, it empowers the desire to take a product and turn it on its head by using it for something other than its intended purpose, or building something from scratch.


I have no knowledge in programming, much less C++ programming nor any knowledge in electronics aside from the things I learned in first year physics. This shows that it's not that hard to pick up if you have some time and are willing to commit.

Of course, it also helps there is a large community built around this sort of thing, and you can easily take existing code and just modify it for your needs.

One of the issues I have with the Arduino IDE (which is essentially C++) is that it is relatively low level coding, meaning that to design the frontend GUI interface you see on the TFT LCD, it is quite a hassle (you have to draw each button individually using polar coordinates, etc). This is why most of the coding for the buttons, I took from another user's project 

The backend stuff (pH measurements, calibrations, lighting, etc) are either coded myself or mish-mashed together from multiple sources.


----------



## Kajendra

This seems amazing 

I enjoy programming and this electronical stuff and have a bit of experience with it I guess 

I just have no applications to put this to use under a freshwater tank -_-

Would love to make these just for the heck of it and though 
Let me know if you want to program anything fancy or cool.

I could just imagine the possibilities for the salties -_-
Plotting measurements on a graph, maybe a 14 day trend...
Automatic water changes... And charting even uploading data online...

Seems like so much fun


----------



## Darkblade48

Kajendra said:


> I just have no applications to put this to use under a freshwater tank -_-


Make one  Failing that, just do it for self-satisfaction!



Kajendra said:


> Let me know if you want to program anything fancy or cool.


Thanks for the offer. Thankfully, I haven't thought up of anything *too* far out there yet...



Kajendra said:


> I could just imagine the possibilities for the salties -_-
> Plotting measurements on a graph, maybe a 14 day trend...
> Automatic water changes... And charting even uploading data online...


These features have been implemented in other DIY controllers 



Kajendra said:


> Seems like so much fun


It is, come join the dark side!


----------



## DaFishMan

Very cool project ! 

Other features I could think of. Monitor nitrates, auto top-up or auto w/c.
Webcam for remote monitoring.


----------



## Darkblade48

DaFishMan said:


> Very cool project !
> 
> Other features I could think of. Monitor nitrates, auto top-up or auto w/c.
> Webcam for remote monitoring.


Nitrate probes are expensive 

Auto top up/water change is possible, but I do not have a drilled aquarium to play with 

Webcam for remote monitoring is possible, but I don't have web capability (need an ethernet board). There are wireless capable boards out there, but they cost significantly more than just a plain old ethernet board (though you'd need a wired connection).


----------



## altcharacter

why would you need a drilled tank for an ATO?


----------



## Darkblade48

altcharacter said:


> why would you need a drilled tank for an ATO?


I was thinking auto water changer, sorry.

For top offs, it could be easily accomplished with a reed switch, and your top off water (a bucket of distilled water with a pump or something of the like).


----------



## jd81

This is a very cool build thread. I am very impressed.

If you can do all that from high-school programming courses, I am scared of what you would be able to program with university level courses!!!

Could post the part numbers of components that you are using, example which arduino board you are using etc...


----------



## Darkblade48

jd81 said:


> This is a very cool build thread. I am very impressed.
> 
> If you can do all that from high-school programming courses, I am scared of what you would be able to program with university level courses!!!


I have to be honest, half the time I have no idea what I am doing 



jd81 said:


> Could post the part numbers of components that you are using, example which arduino board you are using etc...


I'm using a standard Arduino Mega 2560 (revision 2) board. Not the "Made in Italy" ones, but one from eBay (an Arduino "clone" if you want to call it that - the entire project is open source, just the Arduino brand name is copyrighted).

Temperature sensor is a DS18B20, wrapped in a stainless steel casing so that it can be submerged in water.

pH probe is again some cheap eBay one; $16, and works fine, relatively little drift, and I've only needed to calibrate it once (when I got it new). It still measures about the same to this day (about 2 months time). There is a little drift (not more than 0.1 units).

The touch screen is an eBay (do you see the pattern here yet?) 3.2" TFT LCD Touch screen.


----------



## jd81

Thanks!! 

Taking notes hehe


----------



## rickcasa

Looks like you might finish this cool controller before Vertex rolls out their Cerebra. Touchscreen is the way to go. Impressive work.


----------



## Darkblade48

rickcasa said:


> Looks like you might finish this cool controller before Vertex rolls out their Cerebra. Touchscreen is the way to go. Impressive work.


Hahah, no way...

There is still so much front end stuff to do, and using low level code is the worst way to do it.


----------



## Darkblade48

Another long overdue update.

This picture is a bit old, so I'll probably take some other pictures later.










Got the general settings screen worked out.

I've managed to get the pH stuff all implemented - the controller can read the pH, put it on the main screen and then do a certain action (turn on/off solenoid controlling CO2) based on user set pH values.

pH probe calibration has also been implemented (reference 4.0, 7.0 and 10.0 solutions).

Temperature readout and display on main screen has been implemented.

I'm working on the clock, which will lead to light controller, automatic dosing, and perhaps automatic feeding (all based on the same principle, really).

Problem I am encountering is with the RTC library; using Henning Karlsen's library does not seem to work, but using the Adafruit library, it does...very puzzling.

I thought I had gotten the RTC to work with Karlsen's library (took about a week of coding), but now, it doesn't seem to want to work, despite other libraries working (without altering any of the hardware). I might have to change libraries (which would require an extensive recoding). 

Also, some extra hardware came, one of which was an 8 relay board; one relay was broken


----------



## Darkblade48

New photo of the hardware. Ignore the crooked board and the fact that the pH probe isn't plugged in 










As I mentioned, one of the relays is broken 

Also realized I need to account for temperature changes that will affect pH measurements. Spent last night rewriting code.


----------



## Darkblade48

Updated the menu screen.
Got pH probe calibration as well as pH settings done. When pH is greater than maximum set pH, CO2 will turn on. When pH is equal to the minimum set pH, CO2 will shut off.

A minimum - maximum range is required to prevent the solenoid from turning on and off too much.


----------



## Bantario

This kicks ass


----------



## Darkblade48

Almost forgot about this thread; I've been working on other things for a bit.

I have the RTC working.

On Month/DD/YYYY format:

















and on DD/MM/YYYY format

















Ignore the errors that I (purposefully) programmed in  Oh, I guess the photos also show the switch between Celsius and Fahrenheit working as well. Main screen layout is nowhere near finished, I just threw together something for the sake of being able to see the output values.


----------



## Fishfur

I really wish I were more of a computer geek.. and I mean that in the most respectful possible interpretation.. this is pretty awesome. It would be amazing to be able to control all that from the computer screen !


----------



## Darkblade48

Fishfur said:


> I really wish I were more of a computer geek.. and I mean that in the most respectful possible interpretation.. this is pretty awesome. It would be amazing to be able to control all that from the computer screen !


Actually, it's a touch screen 

Once all the coding is done, I plan to mount all the components into a little box, so it will be a stand alone unit.

The problem is that since all the components are not optimized (onto one PCB), the box will be larger than your standard commercial aquarium controller. The tradeoff is customizability to suit your needs and "future proofing."


----------



## Fishfur

I stand corrected.. still very cool device. So what if it's a bit bigger.. half the fun is figuring it out yourself and having it suit your own needs.


----------



## Darkblade48

Fishfur said:


> I stand corrected.. still very cool device. So what if it's a bit bigger.. half the fun is figuring it out yourself and having it suit your own needs.


Heh, if you think of "fun" as staring at your computer screen and cursing at why the code won't compile


----------



## altcharacter

Once you finish it I would make a newer, smaller circuit board and integrate everything together. I might be able to help you out with doing this but you'll have to PM me for more info.


----------



## Darkblade48

altcharacter said:


> Once you finish it I would make a newer, smaller circuit board and integrate everything together. I might be able to help you out with doing this but you'll have to PM me for more info.


Yes, I was thinking about designing a new PCB - but it'll be a pain. I designed some PCBs (and sent them off for printing) a long time ago, and have forgotten most of it by now 

Then there's the issue of getting all the components wave soldered, etc (SMT components)


----------



## altcharacter

Yeah...like I said...pm me


----------



## LeD

I just stumbled on this thread and its great to see that your also working on an arduino based LED controller. I wanted to say it looks great and i was curious if you know any other programming languages. I do some software development myself and it would be cool to see your build interacting with a pc. Do you have any updated pics of your build?


----------



## Darkblade48

LeD said:


> I just stumbled on this thread and its great to see that your also working on an arduino based LED controller. I wanted to say it looks great and i was curious if you know any other programming languages. I do some software development myself and it would be cool to see your build interacting with a pc. Do you have any updated pics of your build?


I don't know any other programming languages other than C; I don't come from a programming/electronics background.

Everything I learned about computer hardware/software/programming is self taught/self learnt.

There are some parts of the controller project that are interactable via PC (pH readings, pH probe calibration, I am thinking of data acquisition in the future).

As for updated pictures, I have been working on a different pet project for some time, so I haven't had time to look at the coding for my controller


----------



## LeD

It would be awesome to see data collection using a Windows based app. I'm in Computer Engineering so If you need some help just PM me. Always happy to help a member.


----------

