Aquarium Reef Controller, stage 1, the LCD shield,

Hello Folks, New to both Arduino and the forum so please be nice.

firstly alittle bit about this project: I'm an avid marine/reef keeper, and always love dabbling with 1 DIY project or another. My last project was building a DIY LED rig (you've probably seen tonnes of them). Now the next step up from this is to add an Arduino to control it via PWM. It was researching the LED build that brought my attention to ardiuno's and everything else possible with them. after spending many an hour googling, it looks like theres a few Arduino based controllers and decided i wanted to build my own.
Intial plans is to build a controller which controls the LED's and the light cycle and display them via a LC. Then from here include temp probes, and other things vaguely interesting.

Alittle bit about myself: as i mentioned above im an avid reef keeper, Im also 20, Male, British, love getting my hands in and always been the kind of person to rip something apart jsut to see how it ticks.

Im currently studying Biology and Computer Science at University and am in my first year. as part of my computer course im learning the programming language JAVA, which was another reason why i picked up an arduino because i thought it might be an interesting self teaching exercise. Im aware that arduinos are programmed in C/C++ but as you probably know, java came out of C++ and is very similar in some respects. so i have "some" consept of Object orientated programing and pick new stuff up pretty easy.

I currently have an Arduino Mega and 2 LCD with 5 button keypad shields (though 1 is broken and can only be used as a "3" button keypad)

Right still with me?


because i've had limited time recently i havent had a chance to do much hardware work on the arduino (i.e. intergrating the buckpuck's) and have instead turned my attention to trying to create and menu and try and link the keypad coding with the LCD display coding.

my main issue is ... well everything :-/ ok not quite.

firstly i put most of my coding inside of Loop() method calling various methods etc but the big issue i have is the code is cycling through the code adn telling the LCD to rewrite itself over adn over, which gives an awful looking program which flickers constantly as the LCD rewrites itself.

now one way i managed to get past that was to run the cycle first then put a Delay() at the end. Issue with this is, if your stuck in a delay period (say 5 second) you cant input any data (i'll get onto the keypad programming later) the second option was to use a While loop and a boolean to run it once then only run it if the boolean value has been "reset" at another point.

before people shout, yes i have done some googling, on menu tutorials but cant really find much help. Also this is going to be a big ongoing project so i thought it was worth creating its own thread.

Well i think that covers everythign for the moment. hope that wasnt too much and i appricate any help or suggestions people offer.

Im new to arduinos, the program language C++ and i've only been doing java for a semester.



(sorry for the double post, but i wasnt able to post links without posting atleast 1 message)

for those interested here is the LCD+keypad shield i have, on retrospect i think it might have been easier to buy a seperate LCD and keypad, for coding. and if it is i might buy a seperate one anyhow.

one imeidate issue i can see with this shield as it covers all the PWM ports, so i'd have to use jump leads etc anyhow to connect it in the final project and while prototyping.

If the LCD is visibly flickering then the chances are that you are clearing the LCD screen on each loop. Simply removing the clear statement and just overwriting will get rid of the flicker.

Also, if the sheild is blocking the pins then just make yourself some leads to connect it instead of plugging it straight in on top of the arduino.

What are you hoping to achive with the Aquarium Reef Controller?

Can't really do much more without seeing your code; any chance you could post it?


hello Chris thank you for your qucik reply, where to begin..

unfortunatly i dont have my coding to hand, it wasnt anyhting special as its on my old pc (i got a new laptop a few days a go) but when i get a moment i'll pull it off the old pc.

I'll write sone new coding now to show you some of the things i've been thinking. it wont take me that long and i'll post it up once i have it, so far all teh coding ive done todate has just been messign around to see if i can get different ideas to work. so i dont really have much todate. but like i said i'll load some up once i've wrote "as far" as i can get .. if that vaguely makes sense.

the first thing i'd like it to control is all the lighting, (i copied and pasted this off my tank thread on anothe forum)


Fade in
Fade out
enable user to input the photo period
enable user to set max light intensity
possibly simulate lunar cycle
possibly simulate varying weather conditions (i.e. cloud cover, stormy, you get the idea)
possibly have an Acclimatization mode which reduces the lights and then slowly ramps them back up.

i want the user to be able to enter values via the keypad so i dont have to plug the thing into a computer i want to make it "stand alone" if that makes sense.

other ideas i have floating around once ive got the lighting down.


Monitor Tank temperature.
Monitor LED lighting unit temperature.
possibly monitor PH
possibly monitor salinity
do retrievable data logging.

and possibly build my own power bar using relays etc to control pumps on and off etc.

hope that vaguely makes sense, i know its alot and its very ambitious but hey it keeps me out of trouble :P.

i'll creat some mock ups and stuff now and post them, up.

some of the better/more complete controllers are this one :



(oh i also know at some point i'll need to order a RTC for the time inputs, but for now i was just going to use delay() ... maybe )

Hi Luke,

That look like an interesting project. I have a freshwater tank myself and you have got me thinking about the automation possabilities.

All the temperature monitoring should be really easy, the difficult point is deciding which of about ten million methods to use! :smiley:

I look forward to seeing your code, and I hope I can help you with your project.

Keep us posted!


example of the menu system i'd like to do

Start up:-
[ VERSION 1.00 ]

Idle screen:-
[TEMP:25*C 12:30]
[WHT:100 BLU:100]

Menu Screen:-


then if the user "selected" set lights/option 1 it would lead to these screens:-


if the user then selected set intensity :

[ XXX % ]
| user then presses select/next
\ /
[ XXX % ]
| user then presses select/next
\ /
[ ]
\ /
short delay then back to menu

Thats sort of what im aiming for, in my "mock" screen i was going to use a switch statement/ while loop, then depending on what key is pressed at what time in the program it sets the variable/case to the corisponding menu screen which gets loaded,

anything highlighted in red, would need to be constantly updated. the temp from a temp probe, the time from the RTC, the light intensitys on the LCD screen would be a variable which would change when the user pressed up or down when in the "set blue max" etc...

that make sense?
;D :o

edit: just sene your reply chris, thats brilliant someone who actually vaguely understands what i plan to do ! i know temp measurement should be relatively easy, wait till i get to dosing pumps and Auto top off devices XD. like i said though i dont have much codea s i dont really know where to begin, i assume my first step would be to get a "scrollable/interactive" menu system adn go from there?

(and for the record i have a 125ltr Fresh water at my mums, a 4ft Full reef 300 ltr system at my dads and my hose, and a 20 ltr marine pico, which this controllers for, if it gets goign i'll build one for the other reef tank)

The technique you're looking for is called a "state machine".
While the arduino supports some object orientated programming, you're still mostly doing procedural programming.

A state machine is the thing to use in these situations.
Essentially, your menu would have 3 or 4 states.

  1. (default) display data
    if button is pressed, go to state 2
  2. display the basic menu options
    if button is pressed, either change the selection or go to the state of the selected item
  3. light intensity was chosen, button up raises the intensity displayed, button down lowers it. the select button changes the output, has a delay, and returns to state 1.

Now I won't do your work for you and put it into actual code, but I hope you get the idea now :slight_smile:

sounds about right to me Imahilus, i shall do some googling/reading up. thank you.

it sounds vaguely what i had in mind with my While statements or more should i say thats what i wanted to do. thanks.

just writing some coding and see where im at, you were right Chris, i was clearing the menu at the start of the loop which caused the flickering. Just writing up a new piece of code tonight and i'll post it once im done


Ok so heres some rough coding i knocket together this evening, Its not pretty, its probably not effiecent but its what first came to mind for me that worked.

its just the various "menu" screens or cases, i need to somehow interface the button pad coding into this exisiting coding.

oh and if your wondering why theres 2 of everything its because one has an asterix "*" at the end, this is the way i decided to show which option is "selected".

i looked at the Display blink tutorial in the arduino folders and would like to have a blinking cursor at the end instead of using a asterix but i figured if i used the delay method it used then i could see problems with how the program runs.

its not much but you get the idea.

next step is implimenting the actual keypad. i wrote psudo code in each method sawing what i want to happen when each butten is pressed.

#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);//delares the LCD Pins for the liquidCrystal library methods.
int x = 0;//Used for testing purposes to show the LED strength
int menuOption = 3;//used for the Switch statement, each menu has its own value,
int tankTemp = 25;//used for testing purposes, in real build this value with come from a temp probe
int timeHour = 12;//used for testing purposes, in real build RTC wil give this value
int timeMinute = 30;//used for testing purposes, in real build RTC wil give this value
void setup() {//ran once AKA welcome screen
  lcd.begin(16, 2);//sets the LCD screen dimentions up
  lcd.print(" Reef Minder ");
  lcd.print("by Luke V1.00");
void loop() {
  switch(menuOption){//loads each menu depending on what value "menuOption" has at the start of the loop.
    case 1:  mainMenuOneOne();break; 
    case 2:  mainMenuOneTwo();break; 
    case 3:  mainMenuTwoOne();break;
    case 4:  mainMenuTwoTwo();break;
    case 5:  setIntensityOne();break;
    case 6:  setIntensityTwo();break;
    case 7:  setIntensityThree();break;
    case 8:  setLightsOne();break; 
    case 9:  setLightsTwo();break;
    case 10: setTimePeriodOne();break;
    case 11: setTimePeriodTwo();break; 
    default: idleMenu();break;
void idleMenu(){//case 0
  //this is the idle screen which will be the ran as default, when the user hasnt pressed anything, after X amount of time if the user hasnt pressed anything load this menuOption
  lcd.print("Temp:"); lcd.print(tankTemp);  lcd.print("*C ");//temp half, top line
  lcd.print(timeHour); lcd.print(":"); lcd.print(timeMinute);// time half, top line
  lcd.print("WHT:");lcd.print(x);lcd.print(" BLU:");lcd.print(x);
  if(x <100){//used in testing, real value will come from the led's/set by the user in the SET intensity menu option
  //If any button pressed, load mainMenuOne()/ menuOption = 1;

void mainMenuOneOne(){ //case 1
  //main menu, 
  lcd.print("1.SET LIGHTS   *");
  lcd.print("2.VIEW PERAMS");
  /*if V pressed load menuOptionOneTwo();
    if ^ pressed do nothing
    if < pressed load idleMenu()/ menuOption = 0;
    if > pressed load setLightsOne();/ menuOption = 8;
    if * pressed load setLightsOne();/ menuOption = 9;
void mainMenuOneTwo(){ //case 2
  //main menu, 
  lcd.print("1.SET LIGHTS"); 
  lcd.print("2.VIEW PERAMS  *");
  /*if V pressed load menuOptionTwoOne()/menuOption = 3;
    if ^ pressed load menuOptionOneOne()/menuOption = 2;
    if < pressed load idleMenu()/menuOption = 0;
    if > pressed load viewPerams(); not coded yet
    if * pressed load viewPerams(); not coded yet
void mainMenuTwoOne(){// case 3
  lcd.print("3.BLANK        *");
  //flashing pixel
  /*if V pressed load menuOptionTwoTwo()/menuOption = 4;
    if ^ pressed load menuOptionOneTwo()/menuOption = 2;
    if < pressed load idleMenu()/menuOption = 0;
    if > pressed load 3rd menu;/not coded yet
    if * pressed load 3rd menu()/not coded yet

void mainMenuTwoTwo(){// case 4
  lcd.print("4.BLANK        *");
  //flashing pixel

  /*if V pressed do nothing;
    if ^ pressed load menuOptionTwoOne()/menuOption = 3;
    if < pressed load idleMenu()/menuOption = 0;
    if > pressed load 4rd menu;/not coded yet
    if * pressed load 4th menu();/not coded yet


void setLightsOne(){// case 8
  lcd.print("1.SET INTENSITY*");
  lcd.print("2.SET TIMES");

 /*if V pressed load setLightsTwo()/menuOption = 9;
    if ^ pressed do nothing 
    if < pressed load idleMenu()//menuOption = 0;
    if > pressed load setintensityOne()/menuOption = 5;
    if * pressed load setLightsTwo()/menuOption = 9;

void setLightsTwo(){//case 9
  lcd.print("1.SET INTENSITY"); 
  lcd.print("2.SET TIMES    *");
  //flash pixel
 /*if V pressed do nothing;
    if ^ pressed load setLightsOne()/menuOption = 8;
    if < pressed load mainMenuOneOne()/menuOption = 1;
    if > pressed load setTimeOne()/menuOption = 10;
    if * pressed load setTimeOne()/menuOption = 10;

void setIntensityOne(){// case 5
  lcd.print("1. SET BLUE MAX"); 
  lcd.print("   100%");
   /*if V pressed value-- While => 0;
    if ^ pressed value++ while <= 100; 
    if < pressed do nothing;
    if > pressed load setIntenistyTwo()//menuOption = 6;
    if * pressed load setIntenistyTwo()/menuOption = 6;

void setIntensityTwo(){//case 6
  lcd.print("1. SET WHITE MAX"); 
  lcd.print("   100%");
  /*if V pressed value-- While => 0;
    if ^ pressed value++ while <= 100; 
    if < pressed do nothing;
    if > pressed load setIntenistyThree()/menuOption = 7;
    if * pressed load setIntenistyThree()//menuOption = 7;

void setIntensityThree(){//case 7
  lcd.print("LIGHTS SET"); 
  menuOption = 1; 
  /*if V pressed do nothing;
    if ^ pressed do nothing; 
    if < pressed do nothing;
    if > pressed load mainMenuOne()/menuOption = 1;
    if * pressed load mainMenuOne()/menuOption = 1;
void setTimePeriodOne(){//case 10
  lcd.print("1.SET START    *");
  lcd.print("2.SET END");
  /*if V pressed load setTimePeriodTwo()/menuOption = 11;
    if ^ pressed do nothing; 
    if < pressed load setLightsTwo()/menuOption = 9;
    if > pressed load setStartTime/not coded yet;
    if * pressed load setStartTime)/not coded yet

void setTimePeriodTwo(){//case 11
  lcd.print("1.SET START"); 
  lcd.print("2.SET END      *");
   /*if V pressed do nothing;
    if ^ pressed load setTimePeriodOne/menuOption = 10;
    if < pressed load setLightsTwo()/menuOption = 9;
    if > pressed load setEndTime/not coded yet
    if * pressed load setEndTime)/not coded yet

Hi Harlequin, I'm undergoing the same project as you so I'd thought I'd drop by. I'm still playing around with with the LCD and temperature probes at this point, so I'm still in the beginning. I'm currently working on getting a reading from two dallas temperature probes (DS18B20 in Parasite Mode) from the same pin using the onewire library.

I'm awaiting a real time clock and serial i2c for my 20x4 LCD screen. The clock will let me set the times for turning my lights on and off and the i2c will prevent the LCD from taking up so many of my precious i/o ports. I also need to buy a keypad to control it, but I haven't found one that I was particularly enthusiastic about yet.

I'm implementing mine into a running 120g tank. I'm using solid state relays to power on the lights or pumps which is where my project will vary a bit from your LED controlling.

I'll be looking forward to seeing how you go about the project, it's reassuring to see other's attempting the same project.

Hello Ludnix,

thanks for swinging by, this project hasnt gone any further since i last posted code wise as i've been too busy, Infact i was just about to sitdown and try and do some more coding. hense why i checked here.

looks like your further along then i am Ludnix as i've just started my project really, I've yet to order my RTC and also some Temp probes etc.

And then if i get that far, to work on solid state relays =]

you'll have to excuse my ignorance but whats "parasite mode" this is all completely new technology to me =].

about 3 hours later.....

Well i just had a rather sucessful few hours coding, managed to synq my keypressed recognition coding with my menu coding.

just need to write it up and i'll post some coding later tonight.

pretty awful video can be seen here:

(note, play it quietly as the sound quality is pretty awful and i had music playing int he background)

its no where near finished but atleast i've got over the huge hurdle that was interfacing the menu and the keypad input, i was struggling with calling the menus at the right time and when to "listen" for a keypress and what to do, got it sorted now though.

And for the record "phoenix" is the user name i go by on some of the fish forums i frequent.

all in all im pretty pleased with my progress, i kinda had a "if i did it this way.... OMG Im so stupid why didnt i think of that earlier" moment ^^.

Going to place an order for a few bits and bobs soon ish i think.

looking at RTC module and a few temp probes for now.

there seems to be a few RTC's out there and also a few different temp probes, does anyone have any idea's suggestions on which to order? the temp probes will be wrapped in heatshrink probably and a dab of glue/silicone at the end to encapsulate it, unless you can think of a better idea?.

also on a semi serious thought.

i've been tinkering with the idea of data recording actually. I know you can buy SD card shields but is there a way of using one of those few hundred small USB sticks people have knocking around? like those small 128 mb ones?

looks like i need to do some googling.

I assume you're familiar with this site, but it's where I'm basing my project off:

Parasite mode allows you to control several of the DS18B20 temperature probes using a single wire to the arduino (very valuable when there are so few ports!). I haven't gotten it to display the two probes I have connected separately yet, but that's really a matter of taking the time to learn the code used in the examples.

For my probes, you need a 4.7k resistor on the +5v lead, so I wired it all up and heat shrunk it. I then put it in a tube you can get at the pet store. It's like rigid air line tubing only slightly larger, then epoxied the ends closed.

I have all my relays now, but I'm still waiting on the RTC to arrive and the serial connector for the LCD.

How do you intend to control your other component with the LCD shield on the arduino? Can you control the relays and LCD on the same I/O ports? I have seen port doublers for sale, but I have no idea how the coding works or circuitry.

Here's a picture of my LCD running. I'm planning on building a black acrylic box to put the LCD and keypad in. I haven't picked the keypad out yet but I'm not sure what my options are for interfacing with the arduino.

Evening Ludnix, Yes i have seen the reefproject controller before,

Firstly the use of parasite mode sounds interesting especially if its possible to isolate each sensor as i was planning of having two sensors, 1 for the light rig 1 for the display tank ( inhonesty i dont need the light rig but i might as well, they only cost a few pounds or so per sensor,

As far as the use of relays is controlled, in honesty im not sure what im going to do, Im currently using an Arduino Mega so im hoping i have enough ports. if not i'll look at other ideas,

Im just about to place an order for 5x DS18B20 sensors ( its £3.60 for 2 or £7.60 for 5) and also place an order for a RTC module.

one thing that im alittle confused about is rewiring my LCD shield to different pins, Currenly i have it "bolted on" to the arduino ( like a true shield) but the problem is it uses up All my PWM pins, and im not entirely sure if each pin actually does something.

the LCD schematic can be found here

could someone tell me which if any pins i can reposition to free up my PWM pins, and if any dont actually do anything... if that makes sense.

(and each time i see a blue 20 x 4 the more i think i want one)

as far as i can tell.....

the 5 pushbuttons go to the analog pin 0-4, the "reset button" and other stuff that i cant tell (led for one) takes up the 5 pins to the left of the analog pins (Reset,3v3,5v,gnd and vin)

these are fine (for now as they arent in the way)

but the 16 pins used for the LCD display use PWM pins 0-13,gnd and AREF, now from as far as i can tell on the schematics (though im rubbish at reading them) LCD pins 7-10 which fit to ardiunio PWM pins 6-9 are blanks? so if i used jumper leads on the others but didnt conect those 4 pins that frees up 4 PWM pins for my led rig?

please tell me that makes any sense lol,

what i want to do is rewire the shield using protoboards and jump leads/jumpers to free up as many ports as possible.

i'm currently not using any of my Digital pins which i assume i can use if i change my code correctly?

help would be appriciated

Are you sure your LCD isn't using any digital pins? Mine is only using the +5v on the analog side of the board, otherwise it's all connected to my digital pins (2-5, 9-13).

yeah My current shield uses none of the standard digital pins, but slots into all of the digital PWM pins.

I assume the input doesnt need PWM.

shield and arduino mega top down,

looking at the mega with the USB port to the left, analog pins facing you.

from left to right the pins that are used are as follows:-


Anaglog IN pins 0-5

looking at the mega with the Digital PWM and Communication ports to you with the USB port to the right.

pins right to left pins used are:

PWM 13 - 8

PWM 7-0

could i simply use jumper leads to rewire all the current pins that are in the PWM to digital pins,

then rewrite the:
LiquidCrystal lcd(8, 9, 4, 5, 6, 7)

to what ever digital pins i used.

see what i mean?

now that im looking at it IF LiquidCrystal lcd(8, 9, 4, 5, 6, 7) variables are used to define the LCD, and 2 pins stick in the AREF and GND....what does pin 0-3 and 13-10? i need to sit and read the schematic again.. but not now tomorrow when i can think straight lol

I imagine the LCD is communicating with the arduino over i2c then. I think your idea would work, but looking at the schematic should clear it up.

They do sell a pin doubler at liquid ware which would allow the shield to go over the arduino but duplicate the pins so you can actually use them. It's about $18. It might be worth considering depending on how you want to do the wiring, but it would be the same as if you just ran jumpers out to a breadboard.

I got a i2c board to interface with the LCD and communicate with my arduino today. it only requires 4 wires go to the arduino, but there isn't an existing library to work with the controller yet. I'm waiting for the lcd and keypad controller to come from, which has a working library, but it's already been 2 weeks with no response from them.

Quotes "I imagine the LCD is communicating with the arduino over i2c then."

i'll take your word for it :P, after a quick google, i ended up alittle confused and just took it at face value, my lcd is i2C haha, if anyone has a laymans explaination id appriciate it.

I had my physics/techie friend come round for lunch today and showed him my progress with the arduino which he was pretty impressed, he's pretty good at reading schematics etc and he's coming over for dinner this sunday so im sure i can pick his brains a bit more about it then, i plan to move it to some protoboards and hopefully connect up some LED's to mimic my LED rig. ( i need to steal his/my electronics bits box, most of the DIY projects i've done have been at his house so i just left all my electronics at his, resitors, led's, proto boards wire, solder etc...)

Put a bid on some DS18B20 chips (x5) earlier today so i'll probably win them, if not i'll jsut bid on the next lot until i get some. £7.60 intotal but the postage is a bit of a b***h and can take anywhere between 10-20 days, hopefully sooner. I looked around to see if there were any stockpiles in the UK i could order from but they were hellishly exspensive compaired to these ones from HK. I dont want them that badly to warent the cost.

Going to order my RTC clock in a moment as well, hopefully this will come sooner as theres a few suppliers in the uk that sell them for around £12. just trying to think if i want anything else while i order.

Think thats about it.... wondering if i can justify buying a 20x4 plus a key... ;D

out of interest how easy is it to make a RTC module by scrach?
I can buy the Chip and crystal for 1/3rd of the price of a prefabricated module?

I'd have to get a cell battery and holder as well but that would be no more then a few Pounds?

I wonder how difficult would it be to program/build? or should i just go ahead and buy a pre made one and save myself some trouble?

anyone got a decent DIY tutorial etc?

edit: RTC schematics from sparkfun

as long as i get these bits and bobs and have a pre programmed DS1307 chip i should be on a winner no? just seems alittle expensive for something that looks like it could be done with a few hours DIY'ing...

second edit: I dont even need a pre programmed chip... i could set the variables myself, the chip does the auto calibrate/configure for me... thats the whole point.

third edit some hours later: Won the DS18B20 chips, so i have 5 of those on the way sometime this side of 20 days the wait begins :-?

You can definitely build your own RTC, I just wanted one that was on a PCB for compact size.
I ordered mine from Futurlec, but they take a very long time to ship as well. web4robot contacted me and told me my i2c controller for my LCD will ship Monday, so at least there's progress.

I don't know if I had asked this yet, but do you have an plans for enclosing the controller? I'm thinking about using black acrylic and building my own box, but I don't have the best tools for cutting. I checked out a lot of project boxes locally, but didn't find anything appropriately sized.

I saw this and thought it seemed like what you were talking about: