Aquarium Controller

Hi all,

My name is Ollie, new to the forum and the world of arduino.
I've been keeping fish for many years but have recently decided to dip my toes into reefkeeping. To make life easier with led lights to control and various parameters to monitor I've decided to utilise a controller but given the extortionate cost of off the shelf units and my love of DIY I've opted to build my own.
Given my lack of programming experience I'm feeling a tad daunted by the task but looking forward to the challenge.

Goals for the controller:
4x pwm channels for dimming lights.
Temperature control for the lights using a temp sensor and pwm fans
Multiple relays for both ac and dc switching (potentially up to x16)
Temperature control of the aquarium
Water level monitoring and top off
Spill/leak sensor
Warning buzzer for out of limits parameters
LCD to display warning
Everything referenced to an rtc
Pump override button for feeding and maintenance.
I'm sure there will be more added to the list as time goes on so I've purchased a mega to make sure I have an excess of everything

Regards

Ollie

Welcome to the forum Ollie.
There are lots of examples of Arduino aquarium controller's to be found online that should get you started.

I would suggest that you take the time to learn the basics of using an Arduino first, there are many tutorials available that will teach you.

When you do start your project it is best to get one thing working and keep adding slowly and getting each thing working before adding more. this makes it easier to figure out where problems are.

I didn't see an actual question in your post, but when you do have one, post it up and we will be glad to help.
just be sure to read How to use this forum at the top of every forum section.
This shows how to format your post in a way that makes it much easier for us to help especially #7 about using code tags so your code shows up properly.

Meanwhile have fun this stuff is rather addicting :slight_smile:

Hutkikz:
Welcome to the forum Ollie.
There are lots of examples of Arduino aquarium controller's to be found online that should get you started.

I would suggest that you take the time to learn the basics of using an Arduino first, there are many tutorials available that will teach you.

When you do start your project it is best to get one thing working and keep adding slowly and getting each thing working before adding more. this makes it easier to figure out where problems are.

I didn't see an actual question in your post, but when you do have one, post it up and we will be glad to help.
just be sure to read How to use this forum at the top of every forum section.
This shows how to format your post in a way that makes it much easier for us to help especially #7 about using code tags so your code shows up properly.

Meanwhile have fun this stuff is rather addicting :slight_smile:

Thanks for the welcome, the question should have been will it be possible to achieve all of the above without running out of resources with the board I've chosen?
I'm sure I'll have more specific questions as the project goes on :slight_smile:

Oh certainly it can be done.
There are 70 I/O pins on the mega and shift registers etc. available that can be used to expand that to many more.

Well this project has been on the back burner for some time but now I'm finally getting stuck in I've got several questions.
First of all is I'm currently using this circuit x4 to replace the manual potentiometer dimmers

I've had it suggested to use an opto coupler to isolate the dimmers from the controller and so the vdm- for each dimmer is isolated from each other. The dimming circuit is 10v and >10mA when shorted with a meter. Is this really necessary?

Next is relating to the code, Is there a way to replace the setTime(8, 29, 00, 1, 1, 16); //Set to current time that goes with the time alarm library with a command that will set the time to the current system time?

And lastly, this is my dimming code

  if (bluFadeDwn0 == 1) {
    if (currentMillis - previousBluFade0Millis >= fadeInterval) {
      previousBluFade0Millis = currentMillis;
      if (bluFadeVal0 <= fadeBlu0) {
        analogWrite(bluFade0, bluFadeVal0);
        bluFadeVal0 = bluFadeVal0 + 4;
      }
    }
  }

I'd like to change this to provide a non linear curve to provide a smoother transition to match the leds better but I'm not really sure how to go about this.

Regards

Ollie

I'm not sure about your first 2 questions, but here is a logarithmic fade code originally posted by Grumpy Mike that I found to work quite well.

/*
  Change brightness of LED linearly to Human eye
  32 step brightness using 8 bit PWM of Arduino
  brightness step 24 should be twice bright than step 12 to your eye.

  reply #11 by Grumpy Mike: http://forum.arduino.cc/index.php?topic=147818.0
*/


#include <avr/pgmspace.h>
#define CIELPWM(a) (pgm_read_word_near(CIEL8 + a)) // CIE Lightness lookup table function

/*
  5 bit CIE Lightness to 8 bit PWM conversion
  L* = 116(Y/Yn)^1/3 - 16 , Y/Yn > 0.008856
  L* = 903.3(Y/Yn), Y/Yn <= 0.008856
*/

const uint8_t CIEL8[] PROGMEM = {
  0,    1,    2,    3,    4,    5,    7,    9,    12,
  15,    18,    22,    27,    32,    38,    44,    51,    58,
  67,    76,    86,    96,    108,    120,    134,    148,    163,
  180,    197,    216,    235,    255
};

int brightness = 0;    // initial brightness of LED
int fadeAmount = 1;
int led1Pin = 9;

// timing variables
unsigned long startTime = 0;
const long interval = 100;    // adjust's fade speed



void setup()  {
  pinMode(led1Pin, OUTPUT);
}

void loop()  {
  unsigned long currentTime = millis();
  if (currentTime - startTime >= interval)
  {
    startTime = millis();                    // reset timing sequence
    analogWrite(led1Pin, CIELPWM(brightness));     // set the brightness of pin 9:, 0-31, 5 bit steps of brightness
    brightness = brightness + fadeAmount;    // change the brightness for next time through the loop:
    if (brightness == 0 || brightness == 31) // reverse the direction of the fading at the ends of the fade:
    {
      fadeAmount = -fadeAmount ;
    }
  }
}

You may want to post the first question in the General Electrics section of the forum for faster results.

Hi,

Have just completed a very similar controller, with very similar functions to your plan.

Although there are 2800 lines of code and comments, it still fits a Uno /Nano memory, though I had to use a lcd serial converter to ensure I had enough ports.

As a similar newbie to C++ the following might help with your project.

Modularize your code into separate functions and avoid directly addressing the port pin from within those functions, use Flags and then a separate function to take all the Flags and control the Ports.
Nothing worse than having to look though all your code just to change the odd port around.

Not readily detailed if you do not know what to look for, but my Ram useage went sky high, because when you do a "print" you need to add the "F" to stop C++ using Ram.

For the RTC get the DS3231 module rather than the lower spec DS1307 module.

The Arduino IDE is ok for small volumes of code but as things get bigger you will really appreciate the editing facillities of programs like the free Atmel Studio 7 wth the free a Visual Micro ardunio plug in.
Its a big program to load in but worth getting to know it, plenty of ytubes on it.

Once you complete a module, take a proper copy/backup of it to a usb stick /disc so if you loose things you have a backup, nothing worse than loosing a months worth of code !

Hutkikz:
I'm not sure about your first 2 questions, but here is a logarithmic fade code originally posted by Grumpy Mike that I found to work quite well.

/*

Change brightness of LED linearly to Human eye
 32 step brightness using 8 bit PWM of Arduino
 brightness step 24 should be twice bright than step 12 to your eye.

reply #11 by Grumpy Mike: Logarithmic scaling for LED dimming? - Programming Questions - Arduino Forum
*/

#include <avr/pgmspace.h>
#define CIELPWM(a) (pgm_read_word_near(CIEL8 + a)) // CIE Lightness lookup table function

/*
 5 bit CIE Lightness to 8 bit PWM conversion
 L* = 116(Y/Yn)^1/3 - 16 , Y/Yn > 0.008856
 L* = 903.3(Y/Yn), Y/Yn <= 0.008856
*/

const uint8_t CIEL8[] PROGMEM = {
 0,    1,    2,    3,    4,    5,    7,    9,    12,
 15,    18,    22,    27,    32,    38,    44,    51,    58,
 67,    76,    86,    96,    108,    120,    134,    148,    163,
 180,    197,    216,    235,    255
};

int brightness = 0;    // initial brightness of LED
int fadeAmount = 1;
int led1Pin = 9;

// timing variables
unsigned long startTime = 0;
const long interval = 100;    // adjust's fade speed

void setup()  {
 pinMode(led1Pin, OUTPUT);
}

void loop()  {
 unsigned long currentTime = millis();
 if (currentTime - startTime >= interval)
 {
   startTime = millis();                    // reset timing sequence
   analogWrite(led1Pin, CIELPWM(brightness));     // set the brightness of pin 9:, 0-31, 5 bit steps of brightness
   brightness = brightness + fadeAmount;    // change the brightness for next time through the loop:
   if (brightness == 0 || brightness == 31) // reverse the direction of the fading at the ends of the fade:
   {
     fadeAmount = -fadeAmount ;
   }
 }
}



You may want to post the first question in the General Electrics section of the forum for faster results.

It looks promising but I'm using an equation to limit the max brightness by setting a percentage but after looking at a few log dimming graphs I see I'm going to have to totally rethink this.

ricky101:
Hi,

Have just completed a very similar controller, with very similar functions to your plan.

Although there are 2800 lines of code and comments, it still fits a Uno /Nano memory, though I had to use a lcd serial converter to ensure I had enough ports.

As a similar newbie to C++ the following might help with your project.

Modularize your code into separate functions and avoid directly addressing the port pin from within those functions, use Flags and then a separate function to take all the Flags and control the Ports.
Nothing worse than having to look though all your code just to change the odd port around.

Not readily detailed if you do not know what to look for, but my Ram useage went sky high, because when you do a "print" you need to add the "F" to stop C++ using Ram.
https://www.baldengineer.com/arduino-f-macro.html

For the RTC get the DS3231 module rather than the lower spec DS1307 module.

The Arduino IDE is ok for small volumes of code but as things get bigger you will really appreciate the editing facillities of programs like the free Atmel Studio 7 wth the free a Visual Micro ardunio plug in.
Its a big program to load in but worth getting to know it, plenty of ytubes on it.

Once you complete a module, take a proper copy/backup of it to a usb stick /disc so if you loose things you have a backup, nothing worse than loosing a months worth of code !

Have you got a link for your project? Unfortunately I already have a DS1037 so I'll be using that for now.
Thanks for the tip on the serial/lcd print, that will definitely be helpful. I've been testing snippets of code at a time to make sure it works before constructing the larger sketch.
I've attached my sketch so far (please excuse the over abuse of the time alarms library) I still need tidy up further and move the variables that will be editable to top for ease of use.

Aquarium_Lights.ino (10.1 KB)

Thats some complex led control code you have there, though expect there are lots of similar ways of doing it.
Assume you have seen the Jarduino project for led code, that also uses a 2560 and large screen.

Also noticed that your do not have many increments in your pwm steps, are you aware that some pwm outputs are 1k instead of 500hz and that you can change their frequencies, so giving a more even rise/fall to the actual lighting effect.
https://arduino-info.wikispaces.com/Arduino-PWM-Frequency

Don't have a project link for mine yet, have had the code running on a bench rig, just in the process doing a pcb .
Its just a replica of my old assembly code Pic based controller from many years ago, one that Ozreef adopted for a forum build.
Once I have done the pcb I will swap controllers over and give it a good test.

I was origianlly going to do a 2560 with tft screen, but that seemed a bit beyond me when I started with C++ ( slow learner :grin: )

Below is the main loop showing the modules used, just you normal stuff , plain beginners code, nothing fancy ; apart from some moonlight leds all my lights are on/off tubes.

functions.ino (1.23 KB)

ricky101:
Thats some complex led control code you have there, though expect there are lots of similar ways of doing it.
Assume you have seen the Jarduino project for led code, that also uses a 2560 and large screen.

Also noticed that your do not have many increments in your pwm steps, are you aware that some pwm outputs are 1k instead of 500hz and that you can change their frequencies, so giving a more even rise/fall to the actual lighting effect.
https://arduino-info.wikispaces.com/Arduino-PWM-Frequency

Don't have a project link for mine yet, have had the code running on a bench rig, just in the process doing a pcb .
Its just a replica of my old assembly code Pic based controller from many years ago, one that Ozreef adopted for a forum build.
Once I have done the pcb I will swap controllers over and give it a good test.

I was origianlly going to do a 2560 with tft screen, but that seemed a bit beyond me when I started with C++ ( slow learner :grin: )

Below is the main loop showing the modules used, just you normal stuff , plain beginners code, nothing fancy ; apart from some moonlight leds all my lights are on/off tubes.

I have seen the jarduino project but my lack of understanding of code (at the time) meant without replicating the set up exactly it was of limited use me but now my understanding of coding is (slowly) improving it may be a good idea to revisit it.
The other thing is I want to come up with my own setup but without reinventing the wheel, to help improve my knowledge and make fault finding easier if any issues arise in the future.
Thanks for the heads up on the pwm frequency differences, it seems pins 4 and 13 on the mega are different to the rest. I'll have to read up more on the subject.
I thought that given my objectives for the lights my code was about as simple as I could make it.
3 steps:
-Relay to switch the power on and off.
-A state change to tell the dimmer to go up, down or do nothing.
-The dimming itself.

Just to throw a further spanner in the works it seems the leds themselves have a fairly linear Fwd voltage - luminous flux output ratio, so while I am interested in what the dimming curve looks like to my eyes being able to set the actual output is much more important for growing corals. I really need to get my hands on a PAR meter.

Expect you have also looked in Reef Central for LED tips ? Lots of project on there but finding a good complete working one like the Jarduino is another thing.

Don't know if you have a good NZ marine forum or use OZReef ? which I assume is still going, though a long time since I last looked.

Our local forum has a led sub section with arduino projects so you might pick up some tips there.
http://www.ultimatereef.net/forums/forumdisplay.php?717-LED-s-sub-forum&s=eb054dd88bb36d3108a9eee67f713494

Suppose you can go the technical route with a meter, but usually let the corals tell you by the way they react; plus I think they say as a rule of thumb its best to only run a led up to 80% of its quoted maximum.

Don't run leds, other tha 5050 moonlights as I just do not like the led light 'scatter' that fills the whole room like a disco !

ricky101:
Expect you have also looked in Reef Central for LED tips ? Lots of project on there but finding a good complete working one like the Jarduino is another thing.

Don't know if you have a good NZ marine forum or use OZReef ? which I assume is still going, though a long time since I last looked.

Our local forum has a led sub section with arduino projects so you might pick up some tips there.
http://www.ultimatereef.net/forums/forumdisplay.php?717-LED-s-sub-forum&s=eb054dd88bb36d3108a9eee67f713494

Suppose you can go the technical route with a meter, but usually let the corals tell you by the way they react; plus I think they say as a rule of thumb its best to only run a led up to 80% of its quoted maximum.

Don't run leds, other tha 5050 moonlights as I just do not like the led light 'scatter' that fills the whole room like a disco !

I actually live in the UK ;). I'm on reef central (same user name) and as you say there is a great pool of knowledge there but finding what you need is not always easy. Unfortunately I've got no experience with corals yet so rather not rely on that till I've got more experience. I'll take a look at the link, thanks :slight_smile:

:lol !! Doh, thought the NZ was for New Zealand :smiley:

Do look in to that link and also the DIY section where there are quiet a few Arduino based tank projects you might find interesting.

If you are just starting off go with the easy soft corals which only need a much lower light level; again loads of help and advice in that forum to guide you.
I'm just throwing out some kenya tree corals as they are getting too big/prolific, offered them to the lfs but not interested, too common /cheap...

ricky101:
:lol !! Doh, thought the NZ was for New Zealand :smiley:

Do look in to that link and also the DIY section where there are quiet a few Arduino based tank projects you might find interesting.

If you are just starting off go with the easy soft corals which only need a much lower light level; again loads of help and advice in that forum to guide you.
I'm just throwing out some kenya tree corals as they are getting too big/prolific, offered them to the lfs but not interested, too common /cheap...

Ahh but it is :wink: I'm a kiwi but moved to the UK a few years ago.