raschemmel, I will try to answer all your questions.
RSG - army talk for Real Smart Guy.
I have written a 386 line sketch (1/3 comments in case I forget what I was trying to do). I have all the routines working to maintain the various water levels, based on the various float statuses.
All tested and running. I bought another Uno, the old one is in production now, maintaining water levels.
Here is the front part of the sketch:
/*
Aquarium Water Maintenance Program
Keeps RO/DI water tub full and sump full and prevents aquarium overflow.
Displays status of water levels.
Operates 3 heaters to keep Aquarium at desired temperature.
Displays current temperature and status of heaters.
*/
// * * * * * * * * * Global Declarations * * * * * * * * * * *
#include <Time.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define ONE_WIRE_BUS_PIN 13
/*-----( Declare objects )-----*/
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS_PIN);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Set the LCD I2C address, pinouts, and backlight
LiquidCrystal_I2C lcd(0x20, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// *********** Output solenoid array **********
int pumpSumpToAquarium = 2; // Pump to fill Aquarium from the Sump
int solenoidRoDi = 3; // Solenoid activates RO/DI filter to refill Freshwater Tub
int pumpFwToSump = 4; // Pump to refill the Sump from the Freshwater Tub
int heaterA = 5; // Water heaters; bypass thermostats; control directly
int heaterB = 6;
int heaterC = 7;
// ************ Input sensors *************
int switchAqOverflow = 8; // Float switch to indicate overflow situation in Aquarium
int switchLowerSump = 9; // Float switch to indicate Sump water level is low
int switchUpperSump = 10; // Float switch to indicate Sump water level is full
int switchLowerFwTub = 11; // Float switch to indicate Freshwater level is low
int switchUpperFwTub = 12; // Float switch to indicate Freshwater level is full
// #define ONE_WIRE_BUS_PIN 13; // Pin 13 is used by the 1-wire buss (see above)
// ********* Variables for storing Machine State ********
// ***** For Sump ******
long timeSumpFillStarted = 0;
long minSumpFillHoldOff = 5; // (8 * 60 * 60) = 28800; // wait 8 hours
// ***** For Aquarium Overflow *****
long timeAqOverflowStarted = 0;
long minAquariumShutdown = 5; // (5 * 60) = 300; // wait 5 minutes
int stateAqOverflow;
int stateLowerSump;
int stateUpperSump;
int stateLowerFwTub;
int stateUpperFwTub;
int statePumpSumpToAquarium;
int stateSolenoidRoDi;
int statePumpFwToSump;
int stateHeaterA;
int stateHeaterB;
int stateHeaterC;
long timeHeaterAOn;
long timeHeaterAOff;
long timeHeaterBOn;
long timeHeaterBOff;
long timeHeaterCOn;
long timeHeaterCOff;
float tempSensorA;
float tempSensorB;
float tempSensorC;
float tempSensorD;
float tempSensorE;
float maxTempDeviationAB = 0.5; // Temperature Sensors A and B should never deviate more than this.
float maxAquariumTemp = 85; // Aquarium temperature should never exceed this
float minAquariumTemp = 75; // Aquarium temperature should never fall below this
float averageSensorAB; // Average the 2 sensors or take the most reasonable one
float tempDifferenceAB;
void setup()
{
time_t pctime = (1262347200) ; // this sets the clock to some arbitrary date, I forget what date.
setTime(pctime); // it doesn't make any difference; I'm just looking for elapsed time
pinMode(switchAqOverflow, INPUT_PULLUP);
pinMode(switchLowerFwTub, INPUT_PULLUP);
pinMode(switchUpperFwTub, INPUT_PULLUP);
pinMode(switchLowerSump, INPUT_PULLUP);
pinMode(switchLowerSump, INPUT_PULLUP);
pinMode(pumpSumpToAquarium, OUTPUT);
pinMode(solenoidRoDi, OUTPUT);
pinMode(pumpFwToSump, OUTPUT);
lcd.begin(20,4); // initialize the lcd
lcd.home();
lcd.clear();
lcd.noBacklight(); // turns backlight off
lcd.backlight(); // turns backlight on
func_InitDisplay(); // set up the display
// delay(2000);
// Initialize the Temperature measurement library
sensors.begin();
}
void loop()
{
func_ReadSwitches();
func_ReadTemperatures();
func_CheckHeaters();
func_DisplayStates();
func_AquariumOverflow();
func_FillFwTub();
func_FillSump();
}
Every thing is working except " func_CheckHeaters();".
The 8-relay solenoid strip turns pumps, water solenoids, and heaters on and off directly from the Aurduino pins.
The float switches are water-proof reed switches with a magnetic float that gives HIGH when floating LOW when not.
They are attached directly to the Uno.
In my test program, I am reading the 5 temp probes and displaying them in degrees F on the LCD.
I compare the 2 Aquarium probes and determine deviation and take appropriate action with message to LCD for the time being.
Everything is on breadboard. (The production Uno is screwed to a piece of plywood alongside similarly mounted breadboard and LCD. The whole thing is mounted to the wall above the aquarium sump in the basement and powered from a 9v wall wart power supply).
Three 300 watt heaters 110V. I was tempted to say they are connected directly to +5 and Gnd on the Arduino, but I'll show restraint. They are connected to the same 8-relay solenoid array opto-isolated. The relays easily handle the load. I've done it before.
No water-proofing yet. I plan to solder wire to their pins, heatshrinking each, goop it all up with epoxy and heat shrink it all into a little blob on a string (3 strings, actually).
Do you know what that translates to in analogcounts on the arduino ?
Nothing I'm doing is time-critical, so I don't care how hard the Uno works.
Schematic? Schematic? We don't need no stinkin' schematic. It couldn't be simpler. I ain't making a phase-coupled warp drive.
I restate:
"My problem is that I just can't come up with a decent algorithm for accomplishing what I want to do with the temp sensors and heaters."
I know how to work the sensors and the heaters. I just don't want to write a bunch of spaghetti code if I can get some guidance to help me avoid it.
When I finish this sketch with all the bells and whistles I will post it where ever youse guys think would be best. It should be pretty cool. Functionally, not necessarily esoterically.
John