All pastes #2101168 Raw Edit

Unnamed

public text v1 · immutable
#2101168 ·published 2012-01-08 16:09 UTC
rendered paste body
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(53, 51, 49, 47, 45, 43, 41, 39, 37, 33, 31);

int backLight = 29;      // pin 29 will control the backlight
int heaterRelay = 46;    //board relay 1 controls the power outlet for the heater
const int sumpLevel = 27;      //float switch to sense low water level in sump
int atoPump = 48;        // board relay 2 power control for auto top off pump

int sumpLevel_state = 0;

#define ONE_WIRE_BUS 52 // Data wire for ds18b20 temp sensors is plugged into pin 52 on the Arduino

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

DeviceAddress tankThermometer = { 0x28, 0xDF, 0x00, 0x43, 0x03, 0x00, 0x00, 0x72 };
DeviceAddress blueoneThermometer = { 0x28, 0x20, 0x04, 0xA8, 0x02, 0x00, 0x00, 0x4D };
DeviceAddress bluetwoThermometer = { 0x28, 0xDF, 0x00, 0x43, 0x03, 0x00, 0x00, 0x4D };
DeviceAddress whiteoneThermometer = { 0x28, 0xDF, 0x00, 0x43, 0x03, 0x00, 0x00, 0x4D };
DeviceAddress whitetwoThermometer = { 0x28, 0xDF, 0x00, 0x43, 0x03, 0x00, 0x00, 0x4D };

void setup(void)
{
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(tankThermometer, 10);
sensors.setResolution(blueoneThermometer, 10);
sensors.setResolution(bluetwoThermometer, 10);
sensors.setResolution(whiteoneThermometer, 10);
sensors.setResolution(whitetwoThermometer, 10);

pinMode(backLight, OUTPUT);
pinMode(heaterRelay, OUTPUT);
pinMode(sumpLevel, INPUT);
pinMode(atoPump, OUTPUT);
digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
lcd.begin(20, 4); // columns, rows. use 16,2 for a 16x2 LCD, etc.
lcd.clear(); // start with a blank screen

//--------------------------------------------------------------------  This is a custom fish icon, it wasn't my idea but its really cool!------------------------------------//
byte newChar[8] = {
	B00000,
	B00000,
	B10001,
	B11011,
	B11111,
	B11111,
	B11001,
	B10000
};

byte newChar1[8] = {
	B00001,
	B00010,
	B11101,
	B11010,
	B11111,
	B11110,
	B11100,
	B00000
};
byte newChar2[8] = {
	B00000,
	B00000,
	B10001,
	B11011,
	B11111,
	B11111,
	B10011,
	B00001
};
byte newChar3[8] = {
	B10000,
	B01000,
	B10111,
	B01011,
	B11111,
	B01111,
	B00111,
	B00000
};
byte newChar4[8] = {
	B00111,
	B01110,
	B11100,
	B11000,
	B11000,
	B11100,
	B01110,
	B00111
};
byte newChar5[8] = {
	B01010,
	B10000,
	B00010,
	B01001,
	B00100,
	B10000,
	B00100,
	B10001
};
byte newChar6[8] = {
	B01010,
	B00100,
	B00001,
	B11011,
	B00011,
	B00001,
	B01000,
	B10010
};
byte newChar7[8] = {
	B10010,
	B00100,
	B10000,
	B11011,
	B11000,
	B10000,
	B00010,
	B01001
};
 ////------------------------------------------------------------------- DISPLAY SETUP -------------------------------------------------------////
 lcd.createChar(0, newChar);
 lcd.createChar(1, newChar1);
 lcd.createChar(2, newChar2);
 lcd.createChar(3, newChar3);
 lcd.createChar(4, newChar4);
 lcd.createChar(5, newChar5);
 lcd.createChar(6, newChar6);
 lcd.createChar(7, newChar7);  
}

void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
lcd.print("Error");
} else {
lcd.print(DallasTemperature::toFahrenheit(tempC));
lcd.print((char)223);
lcd.print("F");
}
}

void loop(void)
{ 
delay(2000);
sensors.requestTemperatures();
lcd.setCursor(0,3);
lcd.print("Temp:");
printTemperature(tankThermometer);
lcd.setCursor(3,0);
lcd.print("Controllertron");
lcd.setCursor(0, 2);
lcd.print("PH:");
lcd.setCursor(11, 2);
lcd.print("Salinity:");
lcd.setCursor(0, 0);
lcd.write(0);
lcd.write(1);
lcd.setCursor(18, 0);
lcd.write(3);
lcd.write(2);
lcd.setCursor(0,1);
lcd.print("ATO:");


////------------------------------------------SNIPPET THAT TELLS THE SYSTEM TO SHUT OFF HEATER IF TANK TEMP IS TOO HIGH-----------------------------////
float tempF = DallasTemperature::toFahrenheit(sensors.getTempC(tankThermometer));
if (tempF > 85) {
digitalWrite(heaterRelay, LOW); // turn on above high temp
}
if (tempF < 84) {
digitalWrite(heaterRelay, HIGH); // turn off below high temp
}

////------------------------------------------SNIPPET THAT TELLS THE AUTO TOP OFF PUMP TO TURN ON WHEN THE WATER LEVEL IS TOO LOW------------------////
sumpLevel_state = digitalRead(sumpLevel);

if (sumpLevel_state == HIGH)
 {
   digitalWrite(atoPump, LOW); //Turn on the ATO pump
   lcd.setCursor(4,1);
   lcd.print("ON");
 }
else if (sumpLevel_state == LOW)
 {
   digitalWrite(atoPump, HIGH);
   lcd.setCursor(4,1);
   lcd.print("OFF");
 }
}