Jump to content
Innovative Marine Aquariums

Arduino Pico Controller


plantarms

Recommended Posts

Hey all, I've had my pico tank for about 3 years now, and I've come to the conclusion that it needs to be fully automated. I currently have the ato on a float switch and just recently spit out some code to automate the LED lighting (4cw 4rb) for my 2.7 gallon pico tank with a fade in/fade out on the blues and whites. It was a fun project so I decided to go all the way and do a full controller.

 

I originally started working on a controller back in 2009 and was sidetracked due to classes and my very limited knowledge of electronics. I still have some of the parts, so I am giving it another shot. The overall plan is to include the following features and any others that I think of along the way: water and air temp sensors, control of the heater based on temps, led lighting control and fade, ato control, pH readings, interactive touch screen display, and different tank modes (main, feeding, cleaning, waterchange). I have eight relays that will be connected my arduino digital pins to give all wired parts of the tank the ability to controlled.

 

This build will use an arduino base, which is open source by nature, therefore I am making this an open source project and will post code in this thread as well as pics and updates on the build. I will also be researching and using bits of code and project designs I find online to shape this to my liking. I am open to any feedback on this project, however please be tolerant of my coding skills and soldering.

 

Current Parts

-8 outlet power center with custom wiring

-rackmount project box to house relays

-x8 25A crouzet solid state relays

-x8 crouzet relay covers

-arduino duemilanove/uno r3(originally started with the duemilanove, now have the uno, not sure which one will live in the project box)

-ezLCD 301 touchscreen display

-rtc module dsS1307

-x4 ds18b20 temp sensors

-pH probe

-pcb boards from radioshack

-stereo cables for pwm/temp sensors

-ethernet cable and jacks for relay control from arduino

-tons of prototyping tools: breadboards, jumper wires, soldering iron, solder, perforated board, project boxes, wire cutters/strippers

 

Relay controlled:

marineland mini jet 606 pump

finnex 50w titanium heater

led light - blue

led light - white

led moonlight

fuge light

ato float switch wired to an aqualifter

Link to comment
  • Replies 88
  • Created
  • Last Reply

Here is the current code I threw together for the led lighting. It controls two 3023 wired buckpucks connecting to pins 9 and 10 on the arduino. Let me know if there are any questions on it. I have it coded so it will resume the current lighting or fade value if it gets reset or a power outage occurs. It has worked great so far, but there are always bugs that can be sorted out. One problem I had to code for was that the RTC unit was occasionally throwing random times which was causing the light to change settings. To account for this I coded some pretty specific time periods with checks in the ledRtc class.

 

//2.7 Gallon Pico Reef LED Light Controller Version 1.06//Code written by plant_arms 2012-08-31//Based on various code libraries avalable on the public domain along with coding compiled by the author. #include <Wire.h>#include "RTClib.h"RTC_DS1307 RTC;int bluePin = 9;				// blue LEDs connected to digital pin5int whitePin = 10;			   // white LEDs connected to digital pin6double blueFadeValue = 255;double whiteFadeValue = 255;double userWhiteMax =		4;	// maximum percentage intensity of white leds, 0-100 user defineddouble userBlueMax =		 9;	// maximum percentage intensity of blue leds, 0-100 user defineddouble blueMaxPwm;				 // variable used to convert the userBlueMax value into a PWM valuedouble whiteMaxPwm;				// variable used to convert the userWhiteMax value into a PWM valueint second;int hour;int minute; int blueLightsOn =		  9;	  // time of day (hour, 24h clock) to begin blue lights fading onint whiteLightsOn =		10;	  // time of day (hour, 24h clock) to begin white lights fading onint whiteLightsOff =	   20;	  // time of day (hour, 24h clock) to begin white lights fading outint blueLightsOff =		21;	  // time of day (hour, 24h clock) to begin blue lights fading outdouble fadeTime =		  60;	  // amount of time in minutes for the fade in/out to last **must be in 60 minute increments**  void setup () {	Serial.begin(115200);	Wire.begin();	RTC.begin();   if (!RTC.isrunning()) { //uncomment the ! to be able to reset the datetime value	// this will allow you to set RTC to the current computer date and time if uncommented and compiled 	//RTC.adjust(DateTime(__DATE__, __TIME__));  } }   void loop () {	 setFade();	 ledRtc();	 SerialOut();				     }     	  //void setFade class used to covert the user percentage input to a PWM value and set to white/blue     void setFade(){	 blueMaxPwm = (userBlueMax*2.55);  //converts the user input value (0-100) to a PWM value (0-255)	 whiteMaxPwm = (userWhiteMax*2.55); //converts the user input value (0-100) to a PWM value (0-255)      }	    //void ledRtc class to control the leds with the ds1307 timer, absolute value and using the time periods(<= etc) is to gain the correct fade position in case of a power outage   void ledRtc(){      DateTime now = RTC.now();   hour = now.hour();   minute = now.minute();   second = now.second();   int totBlueHrOn = hour - blueLightsOn;   int totBlueHrOff = hour - blueLightsOff;   int totWhiteHrOn = hour - whiteLightsOn;   int totWhiteHrOff = hour - whiteLightsOff;   int totalMinute = minute;   abs(totBlueHrOn);    abs(totBlueHrOff);   abs(totWhiteHrOn);    abs(totWhiteHrOff);   abs(totalMinute);   int totalBlueOn   = ((totBlueHrOn*60) + totalMinute);   int totalBlueOff  = ((totBlueHrOff*60) + totalMinute);   int totalWhiteOn  = ((totWhiteHrOn*60) + totalMinute);   int totalWhiteOff = ((totWhiteHrOff*60) + totalMinute);      //fades on blue lights from blueLightsOn through blueLightsOn plus fadeTime and outputs light intensity based on the current time      if((hour >= blueLightsOn)&&(hour < (blueLightsOn+(fadeTime/60)))&&(totalBlueOn < fadeTime)){ 	 blueFadeValue = 255-(blueMaxPwm*(totalBlueOn/fadeTime)); 	 analogWrite(bluePin, blueFadeValue);   }      //fades on white lights from whiteLightsOn to whiteLightsOn plus fadeTime and outputs light intensity based on the current time	   if((hour >= whiteLightsOn)&&(hour <= (whiteLightsOn+(fadeTime/60)))&&(totalWhiteOn <= fadeTime)){  	 whiteFadeValue = 255-(whiteMaxPwm*(totalWhiteOn/fadeTime)); 	 analogWrite(whitePin, whiteFadeValue);   }     //puts blue lights up to full if the fade in period is complete and less than bluelightsoff, so full from 10 to 20:59   if((hour >= (blueLightsOn+(fadeTime/60)))&&(hour < blueLightsOff)){ 	 blueFadeValue = 255-blueMaxPwm;	 analogWrite(bluePin, blueFadeValue);   }      //puts white lights up to full if the fade in period is complete and less than whitelightsoff, so full from 11 to 19:59   if((hour >= (whiteLightsOn+(fadeTime/60)))&&(hour < whiteLightsOff)){ 	 whiteFadeValue = 255-whiteMaxPwm;	 analogWrite(whitePin, whiteFadeValue);   }      //fades out whites from whiteLightsOff to whiteLightsOff plus fadeTime and outputs light intensity based on the current time    if((hour >= whiteLightsOff)&&(hour < (whiteLightsOff+(fadeTime/60)))&&(totalWhiteOff <= fadeTime)){ 	 whiteFadeValue = 255-(whiteMaxPwm - (whiteMaxPwm*(totalWhiteOff/fadeTime)));	 analogWrite(whitePin, whiteFadeValue);     }  //fade out blues from blueLightsOff to blueLightsOff plus fadeTime and outputs light intensity based on the current time   if((hour >= blueLightsOff)&&(hour < (blueLightsOff+(fadeTime/60)))&&(totalBlueOff <= fadeTime)){	 blueFadeValue = 255-(blueMaxPwm - (blueMaxPwm*(totalBlueOff/fadeTime)));	 analogWrite(bluePin, blueFadeValue);     }      //this sets the white lights to be off from end of whiteLightsOff plus fadeTime to midnight   if((hour >= (whiteLightsOff+(fadeTime/60))&&(hour <= 24))){  	 whiteFadeValue = 255;	 analogWrite(whitePin, whiteFadeValue);  }       //this sets the blue lights to be off from end of blueLightsOff plus fadeTime to midnight   if((hour >= (blueLightsOff+(fadeTime/60))&&(hour < 24))){  	 blueFadeValue = 255;	 analogWrite(bluePin, blueFadeValue);  }     //this sets the white lights to be off from midnight to whiteLightsOn in case of reset of power outage   if((hour >= 0)&&(hour < whiteLightsOn)){  	 whiteFadeValue = 255;	 analogWrite(whitePin, whiteFadeValue);  }       //this sets the blue lights to be off from midnight to blueLightsOn in case of reset or power outage   if((hour >= 0)&&(hour < blueLightsOn)){  	 blueFadeValue = 255;	 analogWrite(bluePin, blueFadeValue);  } }	  	      //SerialOut class to output print statements to the serial lcd display, time, temp, and light prcnt   void SerialOut(){ 	//DateTime now = RTC.now();	//print the time pulled in with spaced 0's	if (hour < 10) {	   Serial.print('0');	   Serial.print(hour);}	 else {Serial.print(hour);}	Serial.print(':');	if (minute < 10) {	   Serial.print('0');	   Serial.print(minute);}	 else {Serial.print(minute);}	Serial.print(':');	if (second < 10) {	  Serial.print('0');	  Serial.print(second);}	  else { 	Serial.print(second);}		Serial.print(100-(whiteFadeValue/2.55));	Serial.print("%");			 Serial.print(100-(blueFadeValue/2.55));	Serial.print("%");		Serial.println();	delay(1000); }

Link to comment

Hey Cool! I've been working on something like this myself. My inspiration has been this project:

http://reefprojects.com/wiki/Main_Page

I've been very slowly working through stuff and got my Hydor Koralia Nano to pulse on an off, but haven't made it much past that. I'm pretty stumped by the DS18B20 Digital temperature sensor I bought and beginning to wonder if I fried the thing.

 

Good luck with the build and I hope you can keep finding the time to post your progress here!

Link to comment

Yes I definitely found that build at reefprojects when I've been browsing and I've taken some ideas from there as well. I hadn't thought about doing a wave simulator, I might add that in now. I can provide you with some wiring to get started on the DS18B20 temp sensors. Here is some code I found. Use the wiring I provided and the libraries and code in the post about halfway down the page under "Lesson 2 Digital Temp Sensors"

-->DS18B20 Code

 

7981180763_9af59247e7_b.jpg

Link to comment

Rescue12g, that code I linked previously was confusing and not very user friendly, so I wrote some simpler stuff. Still needs to use the OneWire and DallasTemperature libraries, but this should be very straightforward. It's currently setup for my 4 temp sensors, but you can remove or add the extra lines as needed. Good luck

 

//customTemp_sep12f code created by plant_arms 2012-09-12#include <OneWire.h>#include <DallasTemperature.h> // Initialize Temperature Sensor Library on pin 3#define ONE_WIRE_BUS 3OneWire oneWire(ONE_WIRE_BUS);DallasTemperature sensors(&oneWire);//create deviceaddress objectsDeviceAddress addrZero, addrOne, addrTwo, addrThree;//create floats to store temp sensor valuesfloat tempZero, tempOne, tempTwo, tempThree, avgTemp;int sensorCount;void setup() {  // Begin Serial Communication  Serial.begin(115200);  sensors.begin();    //add some code here for future to output errors if device count < 4 and output which temp sensor has no data  sensorCount = sensors.getDeviceCount();  sensors.getAddress(addrZero, 0);  sensors.getAddress(addrOne, 1);  sensors.getAddress(addrTwo, 2);  sensors.getAddress(addrThree, 3);	}//outputs all 4 temp sensor data and an avg tempvoid loop(){  sensors.requestTemperatures();  getTemp();  Serial.print(tempZero);  Serial.print(" ");  Serial.print(tempOne);  Serial.print(" ");  Serial.print(tempTwo);  Serial.print(" ");  Serial.println(tempThree);  Serial.print("Average: ");  Serial.println(avgTemp);  delay(3000);}//pulls the fahrenheit value of each temp sensor and then adds them and divides by the sensorCount to get an avgTemp void getTemp()  {  tempZero = sensors.getTempF(addrZero);  tempOne = sensors.getTempF(addrOne);  tempTwo = sensors.getTempF(addrTwo);  tempThree = sensors.getTempF(addrThree);    avgTemp = ((tempZero+tempOne+tempTwo+tempThree)/sensorCount);}

Link to comment

Oh wow! Thanks for the code and especially the wiring diagram. It really helps to say exactly where to tie things in like that. I won't be able to get to it for a while (have a big deadline at work Oct. 1st), but looking forward to pulling out the electronics stuff again. Here's another arduino controller project that seems a lot more advanced than the other one I linked.

 

jarduino aquarium controller

 

I'm not sure if the jarduino code is "open" but the user manual is a good source of ideas and has some hardware strategies.

Link to comment

Thanks guys, I got the project box (19''x6''x1'') to house the 8 relays. Also received some relay covers in the mail today. Need to work on some drilling and wiring soon, here's a quick pic.

 

7994494529_c0a4431588_b.jpg

Link to comment

Whoa! Aren't these waaaaaay overkill! :lol: I'm just asking because now I'm worried my relays are too small? I thought you just took the amps times the voltage to give the power. So your relays can handle 100V*25Amps, or 2500 watts -- which is like a window AC unit or a space heater!

 

Thanks guys, I got the project box (19''x6''x1'') to house the 8 relays. Also received some relay covers in the mail today. Need to work on some drilling and wiring soon, here's a quick pic.

 

7994494529_c0a4431588_b.jpg

Link to comment
Whoa! Aren't these waaaaaay overkill! :lol: I'm just asking because now I'm worried my relays are too small? I thought you just took the amps times the voltage to give the power. So your relays can handle 100V*25Amps, or 2500 watts -- which is like a window AC unit or a space heater!

Oh yeah mine are definitely overkill without a doubt. Got them used on eBay for a very reasonable price though. They will run cool and will still take the signal from the arduino, and I can power some really cool stuff if I have spares.

Link to comment

Here are some updates on the relay enclosure from last night

 

drilling the enclosure

8001651585_c9165d4acb_b.jpg

 

relays mounted

8001654552_178414c3bd_b.jpg

 

top view

8001653630_91d85c9285_b.jpg

 

pass through grommet installed

8001652967_d04f1d728d_b.jpg

 

power center wiring completed

8001652021_fe291afc63_b.jpg

Link to comment

Thanks for sharing the pictures Plantarms!

 

Could you explain your wiring scheme a little bit -- I can't quite see in the pictures where the red wires are going. Are you going Power -> Relay -> Switch -> Device or Power -> Switch -> Relay -> Device? Now that I've written that out I guess it doesn't really matter. Both would accomplish the same thing. For my build I was hoping to get some three way switches that could allow me to either switch the device off, put it under Arduino control, or put it under manual control. I haven't had any luck finding these kinds of switches at the hardware store or Radioshack, but I think I saw some in the Jameco catalog.

 

Here are some updates on the relay enclosure from last night

 

drilling the enclosure

8001651585_c9165d4acb_b.jpg

 

relays mounted

8001654552_178414c3bd_b.jpg

 

top view

8001653630_91d85c9285_b.jpg

 

pass through grommet installed

8001652967_d04f1d728d_b.jpg

 

power center wiring completed

8001652021_fe291afc63_b.jpg

Link to comment
Thanks for sharing the pictures Plantarms!

 

Could you explain your wiring scheme a little bit -- I can't quite see in the pictures where the red wires are going. Are you going Power -> Relay -> Switch -> Device or Power -> Switch -> Relay -> Device? Now that I've written that out I guess it doesn't really matter. Both would accomplish the same thing. For my build I was hoping to get some three way switches that could allow me to either switch the device off, put it under Arduino control, or put it under manual control. I haven't had any luck finding these kinds of switches at the hardware store or Radioshack, but I think I saw some in the Jameco catalog.

 

I'll add some more pics once I get the relays wired up, but basically the red wires from each individual switch in the power center are the cutoff point so I can manually cut the power to any relay even if it is powered on by the arduino. So I guess I am doing Power --> Switch --> Relay --> Arduino if that makes sense.

 

8004353451_3677396202.jpg

Link to comment
Does anyone know of any pH sensor or board that interfaces with arduino easily or has been used in other builds?

 

http://cgi.ebay.com/ws/eBayISAPI.dll?ViewI...em=270987262193

 

$16 on ebay. It's just an analog input. You need to calibrate the voltage at 7pH and at 10pH with a buffer solution. (Record the voltage). If 7pH reads 1 volt and 10pH reads 4 volts on calibration, then 2.1 volts in a reading = 8.1pH

Link to comment

That's the problem on ebay. Anything electronic takes a month to get to you.

And nice idea! If you ever decide to make these to sell, I will buy one.

Link to comment

Just realized that I'm going to be one digital pin short if I decide to use the uno board, and it leaves me no room for future probes or expansion. I'm going to go ahead and upgrade to the arduino mega and use the uno and duemilanove as prototyping boards. That also gives me more memory to store the code, but I will have to find a larger project box.

Link to comment

Ordered the following to add to the build today, I now have way more i/o pins then I know what to do with. On another note, does anyone have any experience with ORP, EC, or DO probe readings? Are these measurements even worth having? I would definitely be interested in an automated salinity or calcium sensor if that is even possible.

 

Arduino Mega 2560 R3

8007928883_095d7232e9.jpg

 

pH Probe

8007928763_8d00268778.jpg

 

pH Stamp

8007928829_50454cc68b.jpg

Link to comment

Archived

This topic is now archived and is closed to further replies.

  • Recommended Discussions


×
×
  • Create New...