Alrighty, Here is the code. Im also doing some stuff with float switches and stuff and all that works fine. The main problem i am having is with the LCD. The LCD portion of the code is at the bottom. I would like to be able to have the LCD running correctly all the time so i can check up on the tank parameters at a glance. I also have a few other projects that i would like to do that involve displaying data on an LCD. I am here to learn so have at it. Thanks guys!
// FISH TANK MANAGEMENT SYSTEM
#include <LiquidCrystal.h>
#include <OneWire.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int WaterLevelSensor = 6; // water level sensor (float switch)
const int WaterValve = 9; // water valve (12v solinoid valve)
const int FillIndication = 13; // fill water indication (Green LED)
const int OverFlowSensor = 7; // over flow sensor (float switch)
const int OverFlowWARNING = 8;
OneWire ds(10);
int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;
byte i;
byte present = 0;
byte data[12];
byte addr[8];
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
lcd.clear();
pinMode(WaterLevelSensor, INPUT); // water level switch
pinMode(WaterValve, OUTPUT); // water valve
pinMode(FillIndication, OUTPUT); // fill water indication
pinMode(OverFlowSensor, INPUT); // overflow protection
pinMode(OverFlowWARNING, OUTPUT); // overflow indication
}
void loop()
{
if (digitalRead(WaterLevelSensor) == HIGH && digitalRead(OverFlowSensor) == LOW) // read water level sensor and over flow sensor
{
delay(500); // delay 1.00 sec
digitalWrite(WaterValve, HIGH); // open water valve, low = valve open
digitalWrite(FillIndication, HIGH); // fill water indication (green)
digitalWrite(OverFlowWARNING, LOW); // overflow indication LED off
Serial.println("H2o Levl = LOW"); // display "Filling Tank"
lcd.setCursor(0,0);
lcd.print("Auto Fill ");
}
if (digitalRead(WaterLevelSensor) == LOW && digitalRead(OverFlowSensor) == LOW) // read water level sensor and over flow sensor
{
delay(500);
digitalWrite(WaterValve, LOW); // close water valve, high = valve closed
digitalWrite(FillIndication, LOW); // fill indication LED off
digitalWrite(OverFlowWARNING, LOW); // overflow indication LED off
Serial.println("H2o Levl = OK ");
lcd.setCursor(0,0);
lcd.print("H2o L = OK ");
}
if (digitalRead(WaterLevelSensor) == HIGH && digitalRead(OverFlowSensor) == HIGH) // read water level sensor and over flow sensor
{
delay(25); // delay 0.25 sec
digitalWrite(WaterValve, HIGH); // close water valve, high = closed
digitalWrite(OverFlowWARNING, HIGH); // overflow warning indication (red)
digitalWrite(FillIndication, LOW); // fill indication LED off
Serial.println("H2o Levl = OK");
lcd.setCursor(0,0);
lcd.print("H2o L = OP");
}
if (digitalRead(WaterLevelSensor) == LOW && digitalRead(OverFlowSensor) == HIGH) // read water level sensor and over flow sensor
{
delay(25); // delay 0.25 sec
digitalWrite(WaterValve, HIGH); // close water valve, high = closed
digitalWrite(OverFlowWARNING, HIGH); // overflow warning indication (red)
digitalWrite(FillIndication, LOW); // fill indication LED off
Serial.println("H2o Levl = OVERFLOW");
lcd.setCursor(0,0);
lcd.print("H2o L = Warning"); // display "OVERFLOW WARNING!!
}
if ( !ds.search(addr)) { // temp probe
ds.reset_search();
return;
}
for( i = 0; i < 8; i++) {
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
return;
}
if ( addr[0] == 0x10) {
}
else if ( addr[0] == 0x28) {
}
else {
Serial.println(addr[0],HEX);
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1);
delay(5);
present = ds.reset();
ds.select(addr);
ds.write(0xBE);
for ( i = 0; i < 9; i++) {
data[i] = ds.read();
}
LowByte = data[0];
HighByte = data[1];
TReading = (HighByte << 8) + LowByte;
SignBit = TReading & 0x8000;
if (SignBit)
{
TReading = (TReading ^ 0xffff) + 1;
}
Tc_100 = (6 * TReading) + TReading / 4;
Whole = Tc_100 / 100;
Fract = Tc_100 % 100;
if (SignBit)
{
Serial.print("-");
}
lcd.setCursor(0, 1);
lcd.print("H2o T = ");
lcd.print(Whole);
lcd.print(".");
lcd.print(Fract);
lcd.print("C");
}