// Second Gen Solar Controller by Tom Goldberg // // Thanks to http://nateful.com/ and http://angryelectron.com/ for publishing their solar controllers // and many other openly published examples on the web that provided models for this effort // This project takes those to the next level where it can do the full job on a larger solar system // // Goals: // Read pt1000 analog RTD sensor for measuring solar panels that can get too hot for digital sensors // Read old-style 10k Thermistors to accommodate existing equipment (i.e. sensors deep in storage tank) // Read DS18B20 1-wire bus digital sensors for all other temps - cheapest, simplest and most accurate // Connect any sensor to any function easily // Controls main solarpanel circuit pumps at 2 levels, reducing water flow as delta decreases via lead and lag pumps // Controls secondary extraction circuit pump for dhw domestic hot water // Enable third extraction pump for forced air heat exchanger when storage is hot enough (house thermostat actually runs this pump if enabled) // Alarm out and stop pumps when too cold outside, or when too hot supply // Uses LCD Display for showing temperatures and operations with simple user input to manually switch pumps // publish content to a web page and same pump control as available on LCD User interface // // not yet implemented: // collect data over time with time stamp, display graphically // water low alarm // Libraries //LCD Library and Settings #include // define pins used by lcd display. //lcd(RS, E, D4, D5, D6, D7) LiquidCrystal lcd(8, 9, 4, 5, 6, 7); //Ethernet Libraries and Settings #include #include //Set unique MAC address byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF }; //Set IP address byte ip[] = { 192, 168, 0, 120 }; EthernetServer server(80); //Libraries needed for Dallas 1-wire thermometers #include #include //Math Library for log coversion of 10k sensors #include //Time and I2C bus libs for Real Time Clock #include #include #include //G2 Solar functions include #include "G2solarControllerFunctions.h" #include "EthernetWebReport.h" // Global #define sensorReadDelay 5000 //check temperatures this often void setup() { // analog stuff analogReference(DEFAULT); // 5v // analogReference(INTERNAL2V56); // 2.56v // analogReference(INTERNAL1V1); // 1.1v // flush analog input - - ?? rawPanel12bit = analogRead(pt1000SensorInput); // prep the 2 x 16 char LCD display lcd.begin(2, 16); // prep the relay control pins // setup pins as outputs pinMode (PANEL_LEAD_PUMP_RELAY, OUTPUT); pinMode (PANEL_LAG_PUMP_RELAY, OUTPUT); pinMode (DHW_PUMP_RELAY, OUTPUT); pinMode (STORAGE_HEAT_RELAY, OUTPUT); // set all pumps to off to begin - digitalWrite (PANEL_LEAD_PUMP_RELAY, HIGH); digitalWrite (PANEL_LAG_PUMP_RELAY, HIGH); digitalWrite (DHW_PUMP_RELAY, HIGH); digitalWrite (STORAGE_HEAT_RELAY, HIGH); // for serial monitor output Serial.begin(9600); Serial.println("TG G2 Solar Controller Serial Monitor Reporting: reset"); // setup ethernet Ethernet.begin(mac, ip); server.begin(); //provide power to DS1307 RTC module pinMode (18, OUTPUT); //Gnd pinMode (19, OUTPUT); //Vcc digitalWrite (18, LOW); //Gnd digitalWrite (19, HIGH); //Vcc } /* Main Loop */ void loop() { // get time stamp readTimeDate(); // Scan buttons until time to take temps for (int i = 0; i < sensorReadDelay; i++) // wait sensor read delay seconds before checking sensors { delay(1); // While waiting, scan buttons ButtonControl(); // Also while wating, check for web client and report data WebReporting(); } // READ ALL TEMPERATURES - - - // Read Analog Panel Temp Readpt1000Temperature(); // Read Digital Temps ReadDigitalTemperatures(); // Read 10K Temps Read10kTemperatures(); // Sensor Patch Bay - define which physical sensors are being used for which measurement panelT = TempA; supplyT = TempB; storageT= TempD; dhwT = TempE; outsideT = DTemp1; //outsideT= TempC; //supplyT = DTemp2; //outsideT= DTemp3; //storageT= DTemp4; //dhwT = DTemp4; //panelT = pt1000; // Alarm if needed //supplyT = 155; //test alarm high temp //outsideT = -10; //test freeze alarm Alarm(); // PUMP CONTROL: Control Panel Circ, Heat Exchanger Circ and DHW Circ Pumps PumpControl(); // Data Reporting // Update LCD UpdateLCDTemperatures(); //Update Serial Monitor UpdateSerialMonitor(); }