EcoRenovator  

Go Back   EcoRenovator > Improvements > Solar Heating
Advanced Search
 


Blog Register 60+ Home Energy Saving Tips Recent Posts Search Today's Posts Mark Forums Read


Reply
 
Thread Tools Display Modes
Old 08-09-14, 04:02 PM   #1
buffalobillpatrick
Master EcoRenovator
 
Join Date: Mar 2014
Location: Florissant, Colorado
Posts: 599
Thanks: 814
Thanked 59 Times in 55 Posts
Default Solar Differential Controller Arduino Code

Code:
/********************************************************
 *
 * ARDUINO SOLAR Differential Controller.
 *
 * In Setup: Read & Display the 2x Control Pots: 
 * ON_DELTA & OFF_DELTA
 *
 * In Forever Loop: Read & display 2x 10K NTC Sensors:
 * PANEL_TEMP & TANK_TEMP
 *
 * If Pump is ON: 
 * If (PANEL_TEMP - OFF_DELTA) is less than or = TANK_TEMP
 * or TANK_TEMP is greater than or = TANK_MAX_TEMP
 * Then Turn Pump & LED OFF and set PUMP_BOOL to false  
 *
 * Else Pump is OFF: 
 * If (PANEL_TEMP - ON_DELTA) is greater than or = TANK_TEMP
 * AND TANK_TEMP is Less than or = TANK_MAX_TEMP
 * Then Turn Pump & LED ON and set PUMP_BOOL to true
 *
 * Next display PUMP_BOOL status: 0 = OFF, 1 = ON
 *
 *
 *
 * INPUTS:
 *
 * Reset switch            //Reset pin switched to Gnd & released
 *
 * ON_DELTA_POT            //control pots   
 * OFF_DELTA_POT         
 *       
 * PANEL_sensor            //2X 10K NTC Thermisters
 * TANK_sensor                     
 *
 *
 * OUTPUTS:
 *
 * LCD Display: Status & Progression through code
 *
 * PUMP_RLY
 * PUMP_LED  //LED Pin 13 on Arduino board
 *
 ********************************************************/


#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>


#define I2C_ADDR    0x3F // <<----- Add your address here.  Find it from I2C Scanner

#define BACKLIGHT_PIN     3  //define LCD digital pins
#define En_pin  2
#define Rw_pin  1             //can't use D0 & D1 Tx Rx
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5              //can use 2 -> 12 below in code
#define D6_pin  6
#define D7_pin  7

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

#define SDA                   A4  //RESERVE I2C for LCD           
#define SCL                   A5  


#define ON_DELTA_POT          A0 
#define OFF_DELTA_POT         A1               
#define PANEL_sensor          A2 
#define TANK_sensor           A3               

                                  

                // D0 = RX, D1 = TX, reserved
                                     // digital output pin relay control
#define  PUMP_RLY             2
#define  PUMP_LED            13

#define  TANK_MAX_TEMP      160


int PANEL_TEMP;
int TANK_TEMP;
//int I;

int ON_DELTA;
int OFF_DELTA;

static bool PUMP_BOOL = false;


void setup(void) 
  {  
  pinMode (PUMP_RLY,             OUTPUT);
  pinMode (PUMP_LED,             OUTPUT); 

  digitalWrite (PUMP_RLY,        LOW); //OFF
  digitalWrite (PUMP_LED,        LOW); //OFF

  pinMode (TANK_sensor,          INPUT);
  pinMode (PANEL_sensor,         INPUT);

 
 
  lcd.begin (16,2); //  <<----- My LCD is 16x2
  lcd.clear();
 
  //Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);  


  lcd.clear();
  lcd.home (); // go home
  lcd.print(F("DIFFER-DUINO"));
  lcd.setCursor(0,1);
  lcd.print(F("1_0"));
  delay(5000); 


  ON_DELTA        =    ((Read_10K_NTC (ON_DELTA_POT)  / 10));  // 15
  OFF_DELTA       =    ((Read_10K_NTC (OFF_DELTA_POT) / 50));  //  2

  lcd.clear();  
  lcd.home (); // go home
  lcd.print(F("ON DELTA = "));
  lcd.print(ON_DELTA);
  lcd.setCursor(0,1);  
  lcd.print(F("OFF DELTA = "));
  lcd.print(OFF_DELTA);
  delay(5000); 

  }    //end setup


 
  
void loop ()
{
                    //read & display the 2 10K NTC Sensors
    
  PANEL_TEMP  =  (Read_10K_NTC (PANEL_sensor));
  
  TANK_TEMP   =  (Read_10K_NTC (TANK_sensor));
  
  lcd.clear();  
  lcd.home (); // go home
  lcd.print(F("PANEL TEMP=")); 
  lcd.print(PANEL_TEMP);
  lcd.setCursor(0,1);  
  lcd.print(F("TANK TEMP=")); 
  lcd.print(TANK_TEMP);  
  delay(5000); 

    
  // If Pump is ON: 
  // If (PANEL_TEMP - OFF_DELTA) is less than or = TANK_TEMP
  // or TANK_TEMP is greater than or = TANK_MAX_TEMP
  // Then Turn Pump & LED OFF and set PUMP_BOOL to false  
  if ( PUMP_BOOL)  
  {
  if ((( PANEL_TEMP - OFF_DELTA ) <= TANK_TEMP ) 
       || ( TANK_TEMP >= TANK_MAX_TEMP )) 
  {
  digitalWrite (PUMP_RLY,       LOW); //OFF
  digitalWrite (PUMP_LED,       LOW); //OFF
  PUMP_BOOL =false;
  }
  }
  
  // Else Pump is OFF: 
  // If (PANEL_TEMP - ON_DELTA) is greater than or = TANK_TEMP
  // AND TANK_TEMP is Less Than or = TANK_MAX_TEMP
  // Then Turn Pump & LED ON and set PUMP_BOOL to true
  else if ((( PANEL_TEMP - ON_DELTA ) >= TANK_TEMP )
      && ( TANK_TEMP <= TANK_MAX_TEMP ) )       
  {
  digitalWrite (PUMP_RLY,       HIGH); //ON
  digitalWrite (PUMP_LED,       HIGH); //ON
  PUMP_BOOL = true;     
  }

  lcd.clear();  
  lcd.home (); // go home
  lcd.print(F("PUMP = ")); 
  lcd.print(PUMP_BOOL);
  delay(5000);  
  
   
} //end forever loop





int Read_10K_NTC (int which_sensor)
{   
  #define sample_cnt 30
  
  float alpha =   0.9;     // factor to tune
  float average = 0.0;
  float steinhart;
  
  int I;
 
// resistance at 25 degrees C
#define THERMISTORNOMINAL 10000

// TEMP. for nominal resistance (almost always 25 C)
#define TEMPERATURENOMINAL 25

// The beta coefficient of the thermistor (usually 3000-4000)
#define BCOEFFICIENT 3892

// the value of the series resistor
#define SERIESRESISTOR 10000



  
  for (I=0; I< sample_cnt; I++) 
  {  
  average =  alpha * analogRead(which_sensor) + (1-alpha) * average;
  delay(10);
  }
 
  // convert the value to resistance
  average = 1023 / average - 1;
  average = SERIESRESISTOR / average;
  steinhart = average / THERMISTORNOMINAL;     // (R/Ro)
  steinhart = log(steinhart);                  // ln(R/Ro)
  steinhart /= BCOEFFICIENT;                   // 1/B * ln(R/Ro)
  steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
  steinhart = 1.0 / steinhart;                 // Invert
  steinhart -= 273.15;                         // convert to C
  
  return (round(steinhart * 1.8) + 32);       // round to whole number 
                                              // & convert to F            
}  // end of Read_10K_NTC


Last edited by buffalobillpatrick; 08-09-14 at 10:44 PM..
buffalobillpatrick is offline   Reply With Quote
The Following User Says Thank You to buffalobillpatrick For This Useful Post:
where2 (08-09-14)
Old 08-09-14, 07:56 PM   #2
where2
DIY Geek
 
Join Date: Apr 2013
Location: Sunny Florida
Posts: 400
Thanks: 73
Thanked 83 Times in 73 Posts
Default

Do you have this running, and if so what shield(s) are you using to acquire the temperature data?
where2 is offline   Reply With Quote
Old 08-09-14, 10:38 PM   #3
buffalobillpatrick
Master EcoRenovator
 
Join Date: Mar 2014
Location: Florissant, Colorado
Posts: 599
Thanks: 814
Thanked 59 Times in 55 Posts
Default

Yes it's running. No shield is needed.

10K NTC sensors connect at
#define PANEL_sensor A2
#define TANK_sensor A3

see: https://learn.adafruit.com/thermistor?view=all

A voltage divider circuit is built. A 10K 1% resistor is soldered in series with 10K NTC thermistor & wired across +5 & Gnd.

The sensor wire to A2 or A3 wire is soldered to the middle of voltage divider.

Every brand of 10K NTC Thermistor possibly has a different Beta which "YOU" would specify in the Read_10K_NTC function.

The ones I'm using are:
// The beta coefficient of the thermistor (usually 3000-4000)
#define BCOEFFICIENT 3892

You could also:
#define ON_DELTA 16 or 20
#define OFF_DELTA 2 or 3
instead of 5K pots, but I like pots instead of re-compiling 5 years from now.

Last edited by buffalobillpatrick; 08-09-14 at 10:51 PM..
buffalobillpatrick is offline   Reply With Quote
Old 08-11-14, 07:58 PM   #4
buffalobillpatrick
Master EcoRenovator
 
Join Date: Mar 2014
Location: Florissant, Colorado
Posts: 599
Thanks: 814
Thanked 59 Times in 55 Posts
Default

Arduino Uno & Crydom D1202 SSR Relay are in the white box.
(This relay is rated at 2.5A 120vac so a much larger pump could be used)

When Panel sensor is 20*F or more hotter than Tank sensor,
the Arduino energizes Relay.

The Relay powers the 30VDC 1A Power Supply,
which powers the 24-30VDC El-Sid 10W pump.

When Tank sensor rises to within 2*F of the Panel sensor,
the Arduino de-energizes the Relay.

This setup is for a small system in my 8'x16' trailer.
1 3'x8' panel & 40 gallon tank, heats radiant floor.
A cheap mercury thermostat controls a seperate 12VDC El_Sid pump for floor loop.






Attached Thumbnails
Click image for larger version

Name:	IMG_0230.jpg
Views:	1559
Size:	521.9 KB
ID:	4546   Click image for larger version

Name:	IMG_0231.jpg
Views:	1341
Size:	528.5 KB
ID:	4547   Click image for larger version

Name:	IMG_0232.jpg
Views:	1756
Size:	524.0 KB
ID:	4548  

Last edited by Daox; 08-12-14 at 08:18 AM..
buffalobillpatrick is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 09:55 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, vBulletin Solutions Inc.
Ad Management by RedTyger
Inactive Reminders By Icora Web Design