Hunter X's Arduino Whole Tank Controller (52K Warning) - Page 12
Planted Tank Forums
Your Tanks Image Hosting *Tank Tracker * Plant Profiles Fish Profiles Planted Tank Guide Photo Gallery Articles

Go Back   The Planted Tank Forum > Specific Aspects of a Planted Tank > DIY


Reply
 
Thread Tools Display Modes
Old 03-23-2014, 02:07 AM   #166
Fluffles
Algae Grower
 
PTrader: (1/100%)
Join Date: Jul 2012
Location: Canada
Posts: 38
Default

Thanks for posting you code Hunter. I finally had time to go through it today and I think I have a better idea of how I'm going to code my scheduler.
It's very easy to follow and well commented, thanks again.

I do have a question tho. Say that your powerhead #1 (relay3) automatically turns off at 5pm. What happens if you want to manually turn it on after 5pm?

Not sure if I read the code correctly or understand it completely, but it seems like your buttons can either turn a relay off OR allow the scheduler to take over. Do you consider the opposite where you might want force a relay on?

That's where I ran into the problem and started coding 3 states for each button: ON-OFF-AUTO (unless you don't care about forcing a relay ON)
Fluffles is offline   Reply With Quote
Sponsored Links
Advertisement
 
Old 03-23-2014, 10:51 AM   #167
HunterX
Planted Tank Obsessed
 
HunterX's Avatar
 
PTrader: (22/100%)
Join Date: May 2012
Location: Springfield MO
Posts: 361
Default

Quote:
Originally Posted by Fluffles View Post
Thanks for posting you code Hunter. I finally had time to go through it today and I think I have a better idea of how I'm going to code my scheduler.
It's very easy to follow and well commented, thanks again.

I do have a question tho. Say that your powerhead #1 (relay3) automatically turns off at 5pm. What happens if you want to manually turn it on after 5pm?

Not sure if I read the code correctly or understand it completely, but it seems like your buttons can either turn a relay off OR allow the scheduler to take over. Do you consider the opposite where you might want force a relay on?

That's where I ran into the problem and started coding 3 states for each button: ON-OFF-AUTO (unless you don't care about forcing a relay ON)
You make a great point. I didn't think about needing to "force" a relay on. I think this can be done pretty easy by adding another "if" statement to the "if" statement that shuts the relay off. It would just ask it to check the Boolean to see if it is true. If it's true, turn the relay on. Let me play with it and I'll get something back to you. Thanks for pointing that out.

Last edited by HunterX; 03-23-2014 at 12:09 PM.. Reason: sp
HunterX is offline   Reply With Quote
Old 04-09-2014, 01:05 AM   #168
bigd603
Planted Member
 
PTrader: (1/100%)
Join Date: May 2011
Location: Portland, OR
Posts: 261
Default

Hey Guys,

SO I have been making a lot of good progress on my project (after not doing anything for far too long), and I have got the thing online, its serving data to a website hosted on a raspberry pi (check it out here, but keep in mind its still very early in development), and the site has graphs fed from Xively, but im having some issues with some timing aspects of my sketch. I want the arduino to to feed the data to Xively every ten seconds without using a delay command so the rest of the sketch doesn't get held up in the mean time. I'm using the millis method from the Blink Without Delay example. It works well for a while, but after several hours it stops the feed until i reset the Arduino. I think it has something to do with the millis crossing over, but I don't really know how to fix it. Anyone have any ideas? Here's my sketch:


Code:
#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
#include <Xively.h>
#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>


// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 
  0x90, 0xA2, 0xDA, 0x0D, 0x26, 0x4E };
//IPAddress ip(192,168,0,14);

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);



// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); 

// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *macroPump = AFMS.getMotor(1);
// You can also make another motor on port M2
Adafruit_DCMotor *microPump = AFMS.getMotor(2);

//THIS SECTION TELLS ARDUINO THE ADDRESS OF THE TEMP SENSORS
#define ONE_WIRE_BUS 2 //temp is coming from pin 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress testProbe = { 
  0x28, 0xD5, 0xD7, 0xAA, 0x02, 0x00, 0x00, 0xC3 };
DeviceAddress testProbe2 = { 
  0x28, 0x05, 0x02, 0x84, 0x04, 0x00, 0x00, 0x3F };
float tempTest;
float tempTest2;
//END OF TEMP SENSORS SECTION

/////XIVELY
// Your Xively key to let you upload data
char xivelyKey[] = "8Ot0JKtOfqg7yLaG9QhNN5s3HSqbPl9WnO7c4wrBptpiq6ER";
//your xively feed ID
#define xivelyFeed 835109294
//datastreams
char sensorID[] = "TankTemp";
char resID[] = "ResTemp";

 
// Define the strings for our datastream IDs
XivelyDatastream datastreams[] = {
  XivelyDatastream(sensorID, strlen(sensorID), DATASTREAM_FLOAT),
  XivelyDatastream(resID, strlen(resID), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(xivelyFeed, datastreams, 2 /* number of datastreams */);
 
EthernetClient client;
XivelyClient xivelyclient(client);

//timing for sending Xively data
unsigned long lastXivelyPut = 0; //stores the last time Xively sent data
unsigned long putInterval = 10000;  //interval at which to send data



unsigned char doseTime;

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  
   Ethernet.begin(mac/*, ip*/);
  server.begin();
  
  setSyncProvider(RTC.get); //Retrieves time from the RTC
   

  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
  
  // Set the speed to start, from 0 (off) to 255 (max speed)
  macroPump->setSpeed(150);
  macroPump->run(FORWARD);
  // turn on motor
  macroPump->run(RELEASE);//Turn off motor
  
  microPump->setSpeed(150);
  microPump->run(FORWARD);
  // turn on motor
  microPump->run(RELEASE);
}

void loop() {
  uint8_t i;
  unsigned long currentMillis = millis();
  
  sensors.requestTemperatures();
  tempTest = (sensors.getTempF(testProbe));
  tempTest2 = (sensors.getTempF(testProbe2));
  
  int TankTemp = (sensors.getTempF(testProbe));
  datastreams[0].setFloat(TankTemp);
  
  int ResTemp = (sensors.getTempF(testProbe2));
  datastreams[1].setFloat(ResTemp);
  
   
  
  if (currentMillis - lastXivelyPut > putInterval) {
    lastXivelyPut = currentMillis;
    Serial.println("Uploading it to Xively");
    int ret = xivelyclient.put(feed, xivelyKey);
  }
  
  
  if (hour() == 7 && minute() == 46 && second() == 0) {
      doseTime = second();
    macroPump->setSpeed(155);
    macroPump->run(FORWARD);
    }
  if (second() >= (doseTime + 2)) {
        macroPump->run(RELEASE);
      }
      
    if (hour() == 13 && minute() == 5 && second() == 0) {
      doseTime = second();
    microPump->setSpeed(155);
    microPump->run(FORWARD);
    }
  if (second() >= (doseTime + 2)) {
        microPump->run(RELEASE);
      }
}
bigd603 is online now   Reply With Quote
Old 04-09-2014, 04:19 AM   #169
benjaf
Algae Grower
 
benjaf's Avatar
 
PTrader: (0/0%)
Join Date: Mar 2012
Location: Denmark
Posts: 105
Default

Quote:
Originally Posted by bigd603 View Post
I want the arduino to to feed the data to Xively every ten seconds without using a delay command so the rest of the sketch doesn't get held up in the mean time. I'm using the millis method from the Blink Without Delay example. It works well for a while, but after several hours it stops the feed until i reset the Arduino. I think it has something to do with the millis crossing over, but I don't really know how to fix it. Anyone have any ideas?
Nice to see someone is making progress!
Any particular reason for using millis rather than a timestamp from the RTC? If you do want to use millis you will have to handle rollover. That could be done with something like this:
Code:
 
if (currentMillis - lastXivelyPut > putInterval) 
{ ... }
else if(currentMillis < lastXivelyPut) {
lastXivelyPut = 0;
}
__________________
benjaf is online now   Reply With Quote
Old 04-09-2014, 05:20 AM   #170
bigd603
Planted Member
 
PTrader: (1/100%)
Join Date: May 2011
Location: Portland, OR
Posts: 261
Default

Quote:
Originally Posted by benjaf View Post
Nice to see someone is making progress!
Any particular reason for using millis rather than a timestamp from the RTC? If you do want to use millis you will have to handle rollover. That could be done with something like this:
Code:
 
if (currentMillis - lastXivelyPut > putInterval) 
{ ... }
else if(currentMillis < lastXivelyPut) {
lastXivelyPut = 0;
}
Thanks Benjaf, I didn't do the RTC time stamp at first because I was also worried about a rollover scenario (if it checked if lastXivelyPut >= second() + 9 or something like that) when the second rolled over into the next minute. But thinking about it, I could just have it check if second = 0, 10, 20, 30, 40, or 50. That would give me the same result without worrying about a rollover. Thanks!
bigd603 is online now   Reply With Quote
Old 04-09-2014, 05:46 AM   #171
benjaf
Algae Grower
 
benjaf's Avatar
 
PTrader: (0/0%)
Join Date: Mar 2012
Location: Denmark
Posts: 105
Default

Quote:
Originally Posted by bigd603 View Post
Thanks Benjaf, I didn't do the RTC time stamp at first because I was also worried about a rollover scenario (if it checked if lastXivelyPut >= second() + 9 or something like that) when the second rolled over into the next minute. But thinking about it, I could just have it check if second = 0, 10, 20, 30, 40, or 50. That would give me the same result without worrying about a rollover. Thanks!
You're welcome!
Most RTC libraries also have an option to return a proper timestamp, usually Unix time (seconds since 01-01-1970) or seconds since 01-01-2000 which would be ideal for this use since it doesn't roll over any time soon.
__________________
benjaf is online now   Reply With Quote
Old 04-09-2014, 05:50 PM   #172
HunterX
Planted Tank Obsessed
 
HunterX's Avatar
 
PTrader: (22/100%)
Join Date: May 2012
Location: Springfield MO
Posts: 361
Default

Quote:
Originally Posted by benjaf View Post
You're welcome!
Most RTC libraries also have an option to return a proper timestamp, usually Unix time (seconds since 01-01-1970) or seconds since 01-01-2000 which would be ideal for this use since it doesn't roll over any time soon.
Benjaf to the rescue! Thanks Ben. I have been so busy. I'm getting ready to redeploy back to the states. Can't wait!
HunterX is offline   Reply With Quote
Old 04-09-2014, 06:20 PM   #173
benjaf
Algae Grower
 
benjaf's Avatar
 
PTrader: (0/0%)
Join Date: Mar 2012
Location: Denmark
Posts: 105
Default

Quote:
Originally Posted by HunterX View Post
Benjaf to the rescue! Thanks Ben. I have been so busy. I'm getting ready to redeploy back to the states. Can't wait!
Well, someone has to troll the board, and it is a lot easier to find time for than playing around with the soldering iron.. Don't you just hate when real life gets in the way of a hobby!
__________________
benjaf is online now   Reply With Quote
Old 04-13-2014, 06:25 AM   #174
HunterX
Planted Tank Obsessed
 
HunterX's Avatar
 
PTrader: (22/100%)
Join Date: May 2012
Location: Springfield MO
Posts: 361
Default

Quote:
Originally Posted by benjaf View Post
Well, someone has to troll the board, and it is a lot easier to find time for than playing around with the soldering iron.. Don't you just hate when real life gets in the way of a hobby!
Hey Ben,
Sorry if I sounded sarcastic. You have made a huge contribution to this thread and project. I sincerely appreciate your help and input. As soon as I get back to the states I can get back to giving this thread the attention it deserves!
HunterX is offline   Reply With Quote
Old 04-13-2014, 06:35 AM   #175
benjaf
Algae Grower
 
benjaf's Avatar
 
PTrader: (0/0%)
Join Date: Mar 2012
Location: Denmark
Posts: 105
Default

Quote:
Originally Posted by HunterX View Post
Hey Ben,
Sorry if I sounded sarcastic. You have made a huge contribution to this thread and project. I sincerely appreciate your help and input. As soon as I get back to the states I can get back to giving this thread the attention it deserves!
Oh, not at all! :-) I just had a kid not long ago - and really don't have time to get anything done. That part rather sucks! ;-)

Looking forward to see the final result once you get back to the States!
__________________
benjaf is online now   Reply With Quote
Old 04-23-2014, 03:11 PM   #176
bigd603
Planted Member
 
PTrader: (1/100%)
Join Date: May 2011
Location: Portland, OR
Posts: 261
Default

Quote:
Originally Posted by Fluffles View Post
Most of the parts are in, but I'm still missing the 8-channel relay board, 4x24 LCD, and the 10P terminal blocks. They are coming in from China so it still might be 1-3 weeks from now. Also, I ordered a wood box for the project since I don't have any woodworking skills or tools. That's still about 2 weeks away from arrival. I don't think I'll really be able to start before getting the box.

Here's a quick pic of where everything stands:


This will be very similar to your project except I have less space to fit everything in so it will be a bit of a challenge.

I will be adding an in-line fuse for the AC line before the terminal blocks just to be safe.
Also, I'll have a second LCD screen inside the box (above the power supply). The screen has pushbuttons so I was thinking of making the second screen a menu that will allow me to select LED brightness, morning ramp-up time, nightime, time set, and fan speed.

I kinda decided not to do temperature or PH readings from the tank. My tank is a small 10G rimless tank, and I'd like to minimize the amount of wires going in and out. I won't be doing any sort of ethernet/wireless communication since I don't see the point with my specific setup, it also keeps things simple.

I think the biggest thing for me is that I'll be able to control relays, LEDs, and dosing pumps from the same RTC module. Right now I have 3 different timers in my tank and already had several accidents happen while I'm on a trip. Also, with pushbuttons to control the relays, it will be a breeze to disable outlets for doing maintenance.

Thanks again for posting your project up so everyone can see it. It made me take the plunge and get started on this. I'll keep you posted on any new ideas or discoveries I make while working on this.

Fluffles, what size fuse did you wind up using on your build?
bigd603 is online now   Reply With Quote
Old 04-24-2014, 02:50 AM   #177
Fluffles
Algae Grower
 
PTrader: (1/100%)
Join Date: Jul 2012
Location: Canada
Posts: 38
Default

I used a 10A 20mm fuse. There is a fuse drawer included with the module where the power cord plugs in.
The relays' max current spec is 10A so that's the main reason I chose this value.
Also, I don't expect the current draw for the controller to be more than 10A even with heater, filter, lights, skimmer, etc all connected and on at the same time. If for some reason my controller is drawing 10A at 120V, then there's a huge problem happening somewhere lol.
Fluffles is offline   Reply With Quote
Old 04-24-2014, 03:11 PM   #178
bigd603
Planted Member
 
PTrader: (1/100%)
Join Date: May 2011
Location: Portland, OR
Posts: 261
Default

Quote:
Originally Posted by Fluffles View Post
I used a 10A 20mm fuse. There is a fuse drawer included with the module where the power cord plugs in.
The relays' max current spec is 10A so that's the main reason I chose this value.
Also, I don't expect the current draw for the controller to be more than 10A even with heater, filter, lights, skimmer, etc all connected and on at the same time. If for some reason my controller is drawing 10A at 120V, then there's a huge problem happening somewhere lol.

Is this what you used for the power module? There's a place to put a fuse in that little guy?

https://www.jameco.com/webapp/wcs/st...ductId=1951596
bigd603 is online now   Reply With Quote
Old 04-25-2014, 12:02 AM   #179
Fluffles
Algae Grower
 
PTrader: (1/100%)
Join Date: Jul 2012
Location: Canada
Posts: 38
Default

I ended up changing the power entry module from what you see in the picture above.

I'm using Corcom PSJS0SBX0 (Warning PDF). It doesn't have an EMI filter, but it has a switch and fusebox. I figured that I didn't need an EMI filter since my 12V power supply has one included. It was pretty much the only thing available at my local electronics store that met my requirements.

You can take a better look at the pictures I posted on post #141 earlier. It's the big plastic box on the back right corner.
Fluffles is offline   Reply With Quote
Old 05-11-2014, 05:34 AM   #180
allabouttheplants
Algae Grower
 
PTrader: (0/0%)
Join Date: May 2014
Location: Murfreesboro TN.
Posts: 42
Default

First of all, Hunter thank you for your service. i make it a habit to thank all who have served, and i am teaching my 5 y/o to have the same respect that the service men and women of our country deserve. Second all i can say is WOW on this build. i did a diy aquarium controller about 15 years ago, all timers, relays and 2 PLC ( setup by the maintenance tech for me) for the heating and cooling, no dosing. with all i have been reading about the arduino's lately i am becoming very interested, and my wife can tell you that is not a good thing when it comes to my wallet. you have taken every aspect of normal aquarium attention, and automated them all. i am curious to know who easy would this be for someone like me with very little experience with PCB and no experience with coding be to do?again great work and have a safe trip home.
allabouttheplants is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:12 AM.


Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright Planted Tank LLC 2012