// // W w w. S a l u e V i r e. l t // // The project is titled "DIY hot water solar controller. // All files are here - http://fritzing.org/projects/hot-water-solar-controller/ // // CHANGES // // 2013 05 12 // Added the ability to select the PCB version. Lithuania and China produce plaques // Use different CPU conclusion. // Therefore, before recording, select a plate with which the processor will work. Look for the line "# define VERSIJA_1.0" // 2013 05 05 // Displayed if the anti-freeze // 2013 04 27 // Attached the pump start and stop values printing // 2013 04 23 // Added the variable "freezing" frost protection enabled (freezing = 1) or off (freezing = 0) // // Required libraries: // "Dallas Temperature Control Library here: // Http://milesburton.com/index.php?title=Dallas_Temperature_Control_Library // OneWire (Version 2.1) library here: // Http://www.pjrc.com/teensy/arduino_libraries/OneWire.zip // Library should be unpacked to C: \ arduino-xxx \ library directory. c: \ arduino-xxx \ library \ dallas-temperature-control // Need to rename the folder to C: \ arduino-xxx \ library \ DallasTemperatureControl (without dashes) // // First When the temperature difference between the solar collector and the tank more than 5 degrees, the switch is turned on. // Temperture is measured and displayed on the screen constantly, but the difference is checked every 15 seconds. // Second When the temperature difference between the solar collector and the tank is less than 2 degrees, the pump drives the relay is switched off. // Difference checked every 15 seundžių. // Third Potentiometer can ask any number from 0 to 100, it is displayed on the screen. When the 3-ber temperature sensor // Reaches the limit switches 2nd relay. Temperature falls below the limit switch turns off. // 4th Instead of the two sensors (2 išlitavus cages or track perpovus board) can connect another 2 channel // Relay module and the necessary sensors connected sequentially on a single cable. For the controller to work after such changes // Must be a minimum program of improvements. // 5th DS18B20 sensors can be connected 2 or 3 wires. // 6th The display shows the boiler temperature, collector temperature, the temperature difference // 3-ber temperature sensor, potentiometer preset temperature, relay status. // 7. If the collector temperature is less than or equal to 0, the pump and the collector from freezing. // // #include <LiquidCrystal.h> #include <OneWire.h> #include <DallasTemperature.h> // Comment out the existing line "# define VERSIJA_1.0" if you are on your polokštelės // Www.SauleVire.lt advertising and the "Order # 100010284" //#define VERSIJA_1.0 #ifdef VERSIJA_1.0 // Here the first version of the plate used in the conclusion (produced in Lithuania, yellow) #define Pump 11 //Siurblio valdymo relės išvadas #define Relay2 12 //Termostato valdymo relės išvadas int analogPin = A0; //daugiasūkio rezistoriaus pajungimo išvadas #else // Here the second version of the plate used in the conclusion (produced in China, green) #define Pump A0 //Siurblio valdymo relės išvadas #define Relay2 A1 //Termostato valdymo relės išvadas int analogPin = A2; ////daugiasūkio rezistoriaus pajungimo išvadas #endif #define SERIAL_BAUD_RATE 9600 // Temperature sensors data pins connected to the Arduino 8,9,10 outputs #define Collector 8 // collector sensor conclusions #define Boiler 9 // Boiler sensor conclusions #define Temp_3 10 // thermostat sensor conclusions int relayPin = Pump; int relay2Pin = Relay2; static long timer_pump=0; static long timer_Relay2=0; static long timer_Collector_Error=0; static long timer_Boiler_Error=0; // Time Intervals // REQUEST_Pump_Control minimum pump relay operating time interval, the change in the temperature values // REQUEST_Relay2_Control minimum thermostat relay operating time interval, the change in the temperature values // Time interval REQUEST_Collector_Error action if the collector temperature sensor shows error // REQUEST_Boiler_Error interval operation if the boiler temperature sensor shows error #define REQUEST_Pump_Control 10000 // 10000 millis= 10 sekundziu #define REQUEST_Relay2_Control 10000 // 15000 millis= 15 sekundziu #define REQUEST_Collector_Error 180000 // 120000 millis= 3 minutės #define REQUEST_Boiler_Error 10000 // 30000 millis= 30 sekundziu int freezing = 1; // variable frost protection enabled (freezing = 1) or off (freezing = 0) int Differential_ON=3; // You asked what the temperature difference between the collector pump relay is activated int Differential_OFF=2; // to such differences pump relay off int Collector_Error, Boiler_Error; // sensor status "error" tag int Collector_Good, Boiler_Good; // sensor status 'all good' tag float Collector_tempC, Boiler_tempC, Sensor3_tempC; // ariables to store values of the temperature measurements float Saved_Collector_tempC, Saved_Boiler_tempC; byte arrow_up[8]={ // pump on indicator (arrow up) B00100, B01110, B11111, B00100, B00100, B00100, B00100, B00100 }; byte arrow_down[8]={ // Pump disarm symbol (arrow down) B00100, B00100, B00100, B00100, B00100, B11111, B01110, B00100 }; // Sets the values of the controller "build bridges" with sensors DS18B20 OneWire Collector_T(Collector); OneWire Boiler_T(Boiler); OneWire Temp_T(Temp_3); DallasTemperature CollectorSensor(&Collector_T); DallasTemperature BoilerSensor(&Boiler_T); DallasTemperature TempSensor(&Temp_T); // Sensor arrays to store addresses DeviceAddress Collector_Sensor_Address; DeviceAddress Boiler_Sensor_Address; DeviceAddress Temp_3_Sensor_Address; // LCD display settings // Connection: // Rs (LCD conclusions 4) to Arduino conclusions 2 // Enable (LCD findings 6) to Arduino conclusions3 // LCD findings 15 - 13 Arduino conclusions // LCD conclusion d4, d5, d6, d7 - Arduino outputs 4, 5, 6, 7 int backLight = 13; // output 13 controls the display backlight LiquidCrystal lcd(2, 3, 4, 5, 6, 7); // Variable to keep the thermostat set point int val = 0; // General settings begin void setup() { Serial.begin(SERIAL_BAUD_RATE); pinMode(Pump, OUTPUT); pinMode(Relay2, OUTPUT), // Arduino preparing pinns for the LCD panel pinMode(backLight, OUTPUT); digitalWrite(backLight, HIGH); // activated lighting. lcd.createChar(1, arrow_down); lcd.createChar(2, arrow_up); lcd.begin(16, 2); // Promotional message output to the screen (this is very important :-). lcd.print("www.SauleVire.lt"); Serial.println(); Serial.println("www.SauleVire.lt"); Serial.print("The pump turns on when the temperature difference will be - "); Serial.println(Differential_ON); Serial.print("The pump turns off when the temperature difference will be - "); Serial.println(Differential_OFF); if (freezing = 1) {Serial.println("The collector frost protection - ON");} else {Serial.println("The collector frost protection - OFF");} delay(5000); // Advertising takes only 5 seconds. lcd.clear(); CollectorSensor.begin(); if (!CollectorSensor.getAddress(Collector_Sensor_Address, 0)) Serial.println("defective Collector temperature Sensor"); // Set the maximum sensor-12-bit accuracy. CollectorSensor.setResolution(Collector_Sensor_Address, 12); BoilerSensor.begin(); if (!BoilerSensor.getAddress(Boiler_Sensor_Address, 0)) Serial.println("defective Boiler temperature Sensor"); // Set the maximum sensor-12-bit accuracy. BoilerSensor.setResolution(Boiler_Sensor_Address, 12); TempSensor.begin(); if (!TempSensor.getAddress(Temp_3_Sensor_Address, 0)) Serial.println("defective Temp_3 temperature Sensor"); // Set the maximum sensor-12-bit accuracy. TempSensor.setResolution(Temp_3_Sensor_Address, 12); } //____________________________ // End of program settings //____________________________ void loop() { // Satart main programm Serial.println(); Serial.print("The pump turns ON when the temperature difference will be - "); Serial.println(Differential_ON); Serial.print("The pump turns OFF when the temperature difference will be - "); Serial.println(Differential_OFF); if (freezing == 1) {lcd.setCursor(14,0); lcd.print("*");} else {Serial.println("Collector frost protection - OFF"); lcd.setCursor(14,0); lcd.print(" "); } val = (analogRead(analogPin) * 100.0) / 1024; // read a resistor value variable for the thermostat lcd.setCursor(7,1); lcd.print("N"); lcd.setCursor(8,1); lcd.print(val); // display resistor value on the screen TempSensor.requestTemperatures(); Sensor3_tempC=TempSensor.getTempC(Temp_3_Sensor_Address); Serial.print("The thermostat value "); Serial.println(val); // printed to the terminal, if the computer is connected Sensor3_tempC=TempSensor.getTempC(Temp_3_Sensor_Address); lcd.setCursor(11,1); lcd.print(Sensor3_tempC); Serial.println(Sensor3_tempC); if (millis() > timer_Relay2 + REQUEST_Relay2_Control) { timer_Relay2 = millis(); if (Sensor3_tempC >= val) { Rele_2_ijungta();} if (Sensor3_tempC <= val) { Rele_2_isjungta();} } Serial.print((!CollectorSensor.getAddress(Collector_Sensor_Address, 0))); if (!CollectorSensor.getAddress(Collector_Sensor_Address, 0)) { lcd.setCursor(0,0); lcd.print("Collect. ERROR!"); Collector_Error=1; } else { CollectorSensor.requestTemperatures(); // command sensor to show the measured temperature Serial.print("Collector temperature: "); Collector_tempC=CollectorSensor.getTempC(Collector_Sensor_Address); if (Collector_tempC==-127.00){ lcd.setCursor(0,0); lcd.print("Collect. ERROR!"); Serial.println(" E R R O R !"); Collector_Error=1; } else { Serial.println(Collector_tempC); lcd.setCursor(0,0); lcd.print("K "); lcd.setCursor(1,0); lcd.print(Collector_tempC); lcd.setCursor(9,0); lcd.print(" "); lcd.setCursor(9,0); lcd.print(Collector_tempC-Boiler_tempC); Collector_Good=1; }} if (!BoilerSensor.getAddress(Boiler_Sensor_Address, 0)) { lcd.setCursor(0,1); lcd.print(" Boiler ERROR! "); Boiler_Error=1; } else{ BoilerSensor.requestTemperatures(); Serial.print("Boiler temperature: "); Boiler_tempC=BoilerSensor.getTempC(Boiler_Sensor_Address); if (Boiler_tempC==-127.00){ lcd.setCursor(0,1); lcd.print(" Boiler ERROR! "); Serial.println(" E R R O R !"); Boiler_Error=1; } else{ Serial.println(Boiler_tempC); lcd.setCursor(0,1); lcd.print("B "); lcd.setCursor(1,1); lcd.print(Boiler_tempC); Boiler_Good=1; }} //__________________________________________________ // Check what must be the pump status. Start //-------------------------------------------------- // Variable REQUEST_Pump_Control indicates how often do if (millis() > timer_pump + REQUEST_Pump_Control) { timer_pump = millis(); if (Boiler_Good==1){ if (Collector_Good==1){ // Check at the collector is not warmer than the boiler if (Collector_tempC - Boiler_tempC >= Differential_ON) { Siurblys_ijungtas(); Serial.println("PUMP _ON_"); } // Check whether the collector and tank temperature difference is not less than the prescribed if (Collector_tempC - Boiler_tempC <= Differential_OFF) { Siurblys_isjungtas(); Serial.println("PUMP _OFF_"); } // Freeze Protection if (freezing = 1) { //if security is enabled, // Check if the collector temperature is positive if (Collector_tempC <= 0 ) { // if temperature is negative, Siurblys_ijungtas(); // Pump turn on Serial.println("switched frost protection ON"); }} //______________________________________________ // Collector sensor error checking. START //---------------------------------------------- }else{// If the collector temperature sensor is not working, the pump for 3 minutes (the time variable indicates REQUEST_Collector_Error) if (millis() > timer_Collector_Error + REQUEST_Collector_Error) { timer_Collector_Error = millis(); Saved_Boiler_tempC=Boiler_tempC; // remembering the boiler temperature Siurblys_ijungtas(); Serial.println("collector temperature measuring error, the pump is turned on"); }else{ if (Saved_Boiler_tempC-Boiler_tempC <=2){ Siurblys_isjungtas(); // If the collector temperature sensor is not working and the boiler temperature drops, the pump is turned off }}//______________________________________________ // Collector sensor error checking START //---------------------------------------------- }} else{ if (Collector_tempC >=81){Siurblys_ijungtas();} }} //__________________________________________________ // End of the survey what must be the pump status. //-------------------------------------------------- }// End main programm //_______________________________________ // subroutine // Pump and thermostat relay Switching //--------------------------------------- // Turn on the pump and the corresponding mark on the screen display void Siurblys_ijungtas() { digitalWrite(Pump, LOW); lcd.setCursor(15,0); lcd.write((uint8_t)2);//char up to LCD // lcd.setCursor(15,1); // lcd.write((uint8_t)2);//char up to LCD } // Pump switch-off and the corresponding mark on the screen display void Siurblys_isjungtas(){ digitalWrite(Pump, HIGH); lcd.setCursor(15,0); lcd.write((uint8_t)1);//char down to LCD // lcd.setCursor(15,1); // lcd.write((uint8_t)1); //char down to LCD } // Thermostat relay on and the corresponding mark on the screen display void Rele_2_ijungta() { digitalWrite(Relay2, LOW); lcd.setCursor(10,1); lcd.write((uint8_t)2);//char up to LCD } // Thermostat relay switch-off and the corresponding mark on the screen display void Rele_2_isjungta(){ digitalWrite(Relay2, HIGH); lcd.setCursor(10,1); lcd.write((uint8_t)1); //char down to LCD }