Code update2
Here is code so far. And some pics of the whole assembly in the enclosure. (3D CAD) I think i got it the way i want . Will soon be machining all cutouts and such in the enclosure. Will post when i get updates.
Thanks again,
Troy
Here is code so far. And some pics of the whole assembly in the enclosure. (3D CAD) I think i got it the way i want . Will soon be machining all cutouts and such in the enclosure. Will post when i get updates.
Thanks again,
Troy
Code:
//This version has all Serial Prints and GLCD Prints at begining of loop()
//Last Updated: 3/26/2015 @ 9:41PM
//This code will control 2 pumps and a Peltier Cooler with 4 analog 10k thermisitor sensors. For
//a Solar Hot Water system consisting of Solar Collectors, Solar Collector Tank and a potable
//hot water tank.
//AnalogRead(0) is sensor at HotWaterTank.
//AnalogRead(1) is sensor at SolarCollectorTank.
//AnalogRead(2) is sensor at SollarCollectors.
//AnalogRead(3) is sensor inside of electronics enclosure.
//PIN_D0 is pin D0 on Teensy++2.0 board. It controls On/Off of HotWaterTank pump relay.
//PIN_D1 is pin D1 on Teensy++2.0 board. It controls On/Off of SolarCollectors pump relay.
//PIN_D2 is pin D2 on Teensy++2.0 board. It controls On/Off of Peltier Cooler & Inside fan relay.
//PIN_D3 is pin D3 on Teensy++2.0 board. It controls On/Off of Peltier outside fan relay.
#include <Time.h>
#include <Wire.h>
#include <openGLCD.h>
unsigned long interval1 =5000; // the time we need to wait
unsigned long previousMillis1=0; // millis() returns an unsigned long.
unsigned long interval2 =1000; // the time we need to wait
unsigned long previousMillis2=0; // millis() returns an unsigned long.
unsigned long interval3 =1000; // the time we need to wait
unsigned long previousMillis3=0; // millis() returns an unsigned long.
unsigned long interval4 =2000; // the time we need to wait
unsigned long previousMillis4=0; // millis() returns an unsigned long.
unsigned long interval5 =100000; // the time we need to wait
unsigned long previousMillis5=0; // millis() returns an unsigned long.
float TemperatureSensorInput;
float fahrenheit = 0;
void setup()
{
delay(500);
GLCD.Init(NON_INVERTED); // initialise the library, non inverted writes pixels onto a clear screen
GLCD.ClearScreen();
GLCD.ClearScreen();
Serial.begin(38400);
pinMode(PIN_D0, OUTPUT);
pinMode(PIN_D1, OUTPUT);
pinMode(PIN_D2, OUTPUT);
pinMode(PIN_D3, OUTPUT);
}
void loop()
{
//This is the Time and Date print out. It uses both Wire.h and Time.h files.
GLCD.SelectFont(TimesNewRoman9);
GLCD.CursorTo(0,0);
GLCD.Puts("UpTime ");
GLCD.PrintNumber(hour());
GLCD.Puts("h");
GLCD.PrintNumber(minute());
GLCD.Puts("m");
GLCD.PrintNumber(second());
GLCD.Puts("s ");
GLCD.Puts("D");
GLCD.PrintNumber(day());
GLCD.Puts("/");
GLCD.Puts("M");
GLCD.PrintNumber(month());
GLCD.Puts(" ");
if((millis() - previousMillis1) >= interval1)
{ //Here is where
previousMillis1 = millis(); //the code waits for the set time before code executes again.
TemperatureSensorInput = analogRead(0); //Hot Water Tank temperature sensor.
float celsius0 = ((TemperatureSensorInput - 512) / 9.73f + 25); //Math for 10KOhm Thermistor.
fahrenheit = celsius0 * 1.8 + 32;
GLCD.SelectFont(Tahoma9B);
GLCD.CursorTo(1,1);
GLCD.Puts("HotWaterTank: ");
//GLCD.PrintNumber(celsius0);
//GLCD.Puts("C/");
GLCD.PrintNumber(fahrenheit);
GLCD.Puts("F");
GLCD.Puts(" ");
Serial.print("HotWaterTank: ");
Serial.print(celsius0);
Serial.print(" C/");
Serial.print(fahrenheit);
Serial.println("F");
TemperatureSensorInput = analogRead(1); //Collector Tank temperature sensor.
float celsius1 = ((TemperatureSensorInput - 512) / 11.0f + 25); //Math for 10KOhm Thermistor.
fahrenheit = celsius1 * 1.8 + 32;
GLCD.CursorTo(1,2);
GLCD.Puts("CollectorTank: ");
//GLCD.PrintNumber(celsius1);
//GLCD.Puts("C/");
GLCD.PrintNumber(fahrenheit);
GLCD.Puts("F");
Serial.print("CollectorTank: ");
Serial.print(celsius1);
Serial.print(" C/");
Serial.print(fahrenheit);
Serial.println("F");
TemperatureSensorInput = analogRead(2); //Solar Collector Temperature Sensor
float celsius2 = ((TemperatureSensorInput - 512) / 11.0f + 25); //Math for 10KOhm Thermistor.
fahrenheit = celsius2 * 1.8 + 32;
GLCD.CursorTo(1,3);
GLCD.Puts("SolarCollector: ");
//GLCD.PrintNumber(celsius2);
//GLCD.Puts("C/");
GLCD.PrintNumber(fahrenheit);
GLCD.Puts("F");
GLCD.Puts(" ");
Serial.print("SolarCollector: ");
Serial.print(celsius2);
Serial.print("C/");
Serial.print(fahrenheit);
Serial.println("F");
TemperatureSensorInput = analogRead(3); //Enclosure temperature sensor.
float celsius3 = ((TemperatureSensorInput - 512) / 11.0f + 25); //Math for 10KOhm Thermistor.
fahrenheit = celsius3 * 1.8 + 32;
GLCD.CursorTo(1,4);
GLCD.Puts("ControlBox: ");
//GLCD.PrintNumber(celsius3);
//GLCD.Puts("C/");
GLCD.PrintNumber(fahrenheit);
GLCD.Puts("F");
GLCD.Puts(" ");
Serial.print("ControlBox: ");
Serial.print(celsius3);
Serial.print("C/");
Serial.print(fahrenheit);
Serial.println("F ");
Serial.println();
// Below is Hot Water Tank pump control.
if((millis() - previousMillis2) >= interval2)
{ //Here is where
previousMillis2 = millis(); //the code waits for the set time before code executes again.
if ((celsius0 < 25) && (celsius1 > 27)) //If Hot Water Tank is below 25C and Collector Tank
//is greater than 27C then turn on pump/relay1.
{
digitalWrite(PIN_D0, HIGH); //Relay1 HotWaterTank Pump ON
}
else if ((celsius0 >= 30)|| celsius1 < 25) // 1st part: turn off 5C differential, for Hot Water Tank OR,2nd part:
// turn off 2C differential, for CollectorTank.
{
digitalWrite(PIN_D0, LOW); //Relay1 HotWaterTank Pump OFF
}
}
// Below is Solar Collectors and Collector Tank control.
if ((((celsius2 > 27) && (celsius2 > celsius1 + 10))|| celsius2 < -2)|| celsius2 >= 94) // If Solar Collector is at least 27C AND
//10C greater than Collector Tank,turn on relay2
//SolarCollector pump, OR freezing temperature turn on, OR extreme hot turn on.
//System is closed loop with 50/50 glycol/water mixture.
{
digitalWrite(PIN_D1, HIGH); //Relay2 SollarCollector Pump ON
}
else if ((celsius2 <= 24)|| celsius2 < celsius1 - 5) // 1st part: low turn off differential, Solar Collectors are less than or equal to 24C turn off relay2 OR, 2nd part: normal
//turn off differential, Solar Collectors are 5C below Collector Tank temperature turn off relay2.
{
digitalWrite(PIN_D1, LOW); //Relay SollarCollector Pump OFF
}
}
// Below is Petier Cooler control.
if ((millis() - previousMillis4) >= interval4)
{
previousMillis4 = millis();
TemperatureSensorInput = analogRead(3); //Enclosure temperature sensor.
float celsius3 = ((TemperatureSensorInput - 512) / 11.0f + 25); //Math for 10KOhm Thermistor.
if (celsius3 > 28) // If Temperature inside of enclosure is greater than or equal to 27C turn on Peltier cooler.
{
digitalWrite(PIN_D2, HIGH); // Relay3 Peltier cooler and Inside Fan ON.
digitalWrite(PIN_D3, HIGH); // Relay3 Peltier Outside Fan ON.
previousMillis5 = millis(); // constantly update the timout because both fans are on
}
else if(celsius3 <= 27) // This is a 2 degree differential. When sensor is 2C cooler, relay will turn OFF.
{
digitalWrite(PIN_D2, LOW); // Relay3 Peltier cooler and Inside Fan OFF.
if ((millis() - previousMillis5) >= interval5)
{
// Set time for Peltier Outside fan to keep running after Peltier is shut off.This
// will help prevent hot side of Peltier from transfering heat back into inside of Enclosure.
digitalWrite(PIN_D3, LOW); // Relay4 Peltier Outside Fan OFF.}
}
}
}
}
// To Do:
// 1. Adjust sensor temperature calculation for higher value refer to this chart at bottom of page.
//pjrc.com/teensy/tutorial4.html
// 2.
// 3. Add a 0.1uF cap on each analog signal input to GND.
// 4.
// 5.
// 6. Wire LCD power & Relay board directly to power supply.
// Notes:
// Current operating temperatures are for easy bench testing of project. Will need to adjust
// for actual system. Including the amount of differential. And the amount of long intervals delay.
// The if statement for SollarCollector pump should cover times of Hot days with sudden cloud cover
// when hot water is NOT being used and when hot water IS being used.
// Will cover short days and long periods of cold and no sun.
// Main reason for differentials is to keep relays from quickly cycling on and off and to allow
// for energy/temperature loss when transfering heat from Collectors to Collector Tank to Hot Water Tank.
Attachments
Last edited: