EcoRenovator  

Go Back   EcoRenovator > Improvements > Geothermal & Heat Pumps
Advanced Search
 


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


Reply
 
Thread Tools Display Modes
Old 08-13-14, 05:02 PM   #181
Ormston
Apprentice EcoRenovator
 
Join Date: Mar 2013
Location: UK
Posts: 131
Thanks: 13
Thanked 35 Times in 32 Posts
Default

After a PM conversation with AC yesterday i agreed to write some code to hopefully get the GPHP controller started.

Below is a first draft, it compiles fine but i haven't had time to set up any hardware to test it.

Flow sensors on D2 and D3 (input flow and output flow), have used this code before should it should work fine. Calibrated for 3/4" version of the flow meters AC showed, i think the calibration should be the same.

D4 is input from thermostat, tank stat or whatever your heating. +5v to call for heat.
D4, D5 and D4 are outputs to compressor, input pump and output pump.

Thermistors on A0 and A1, this is untested code to me. Used thermistor library found here: Tutorial: Using NTC Thermistors With Arduino - GarageLab (arduino, electronics, robotics, hacking)
A0 is evaporator temp (water return to loop field in GSHP)
A1 is condensor temp, return from water tank or radiant floor.

Please try it and tell me what doesn't work. This really is a first draft with much testing and many more features required.

Steve

AC I will start a thread on my system when i get chance.

Code:
#include <Thermistor.h>


double evaporator, condensor;  //Variables for temperatures from thermistors
float HpLPM;                   //Flow rate from flow meter in L/m
float HpLPM1;                   //Flow rate from flow meter in L/m
int minLPM = 3;                //Minimum flowrate to run HP
int minEv = 2;                //Minimum evaporator temp
int maxCon = 65;              //Maximum condensor temp
byte runHP = false;
byte runCompressor = false;
byte runOutPump = false;       // pump to circulate water to house/tank
byte runInPump = false;        //fan in case of ASHP
const int demandPin = 4;       // input connected to external thermostat to request heat
byte demand = false;               // variable for reading if heat required from thermostat
unsigned long compLR;          // Time compressor was last run
unsigned long hpStarted;        // Time HP cycle started
unsigned long hpStopped;        // Time HP cycle stopped
volatile int NbTopsFan; //measuring the rising edges of the signal
volatile int NbTopsFan1; //measuring the rising edges of the signal
int hallsensor = 2; //The pin location of the sensor
int hallsensor1 = 3; //The pin location of the sensor
byte led = 13;
byte ledState = false;
byte comp = 5;
byte inPump = 6;
byte outPump = 7;
unsigned long prevMillis = 0;        //used for led blinking
Thermistor temp(0);
Thermistor temp1(1);

// ********************Temperature measurement starts here**************
void readTemps() { //read all temperatures from thermistors
  evaporator = temp.getTemp();
  condensor = temp1.getTemp();
  }

// ********************Temperature measurement ends here**************

// ********************Flow meter reading starts here**************

void hpFlow () //This is the function that the interupt calls
{
  NbTopsFan++;  //This function measures the rising and falling edge of the hall effect sensors signal
}

void hpFlow1 () //This is the function that the interupt calls
{
  NbTopsFan1++;  //This function measures the rising and falling edge of the hall effect sensors signal
}

void readFlows()
{
  NbTopsFan = 0; //Set NbTops to 0 ready for calculations
  NbTopsFan1 = 0; //Set NbTops to 0 ready for calculations
  interrupts(); //Enables interrupts
  delay (1000); //Wait 1 second
  noInterrupts(); //Disable interrupts
  HpLPM = (NbTopsFan / 2.75);
  HpLPM = (NbTopsFan1 / 2.75);
}
// ********************Flow meter reading ends here**************


void setup() {
  pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
  pinMode(hallsensor1, INPUT); //initializes digital pin 3 as an input
  attachInterrupt(0, hpFlow, RISING); //and the interrupt is attached (1 for Leonardo 0 for mega/uno)
  attachInterrupt(1, hpFlow1, RISING); //and the interrupt is attached (0 for Leonardo 1 for mega/uno)
  pinMode(led, OUTPUT);
  pinMode(comp, OUTPUT);
  pinMode(inPump, OUTPUT);
  pinMode(outPump, OUTPUT);
  pinMode(demandPin, INPUT); 
  compLR = millis();

}

void loop() {
  readTemps();
  readFlows();
  demand = digitalRead(demandPin);

  unsigned long tm = millis();
  if ((demand == true) && (compLR <= (tm - 120000))) {
    if (runHP == false) hpStarted = tm;
    runHP = true;
  }
  else {
    if (runHP == true) hpStopped = tm;
    runHP = false;
  }

  //*****HP startup cycle********
  if (runHP == true) runInPump = true;
  if ((runHP == true) && (hpStarted <= (tm - 30000) && (HpLPM > minLPM))) runCompressor = true; //Delay compressor start 30s after starting in pump
  if ((runHP == true) && (hpStarted <= (tm - 60000))) {
    runOutPump = true; //Delay out pump start 60s after starting in pump
    ledState = true; ///turn on pin 13 led after startup of HP
  }
  
  //*****HP shutdown cycle********
  if (runHP == false) runCompressor = false;
  if ((runHP == false) && (hpStopped <= (tm - 120000))) runInPump = false;
  if ((runHP == false) && (hpStopped <= (tm - 300000))) {
    runOutPump = false;
    compLR = tm;
    ledState = false; ///turn off pin 13 led after shutdown of HP
  }
  
  //***Check flow rates above min***
  if (HpLPM < minLPM || HpLPM1 < minLPM) {
    runCompressor = false;
    if (runHP == true) hpStopped = tm;
    compLR = (tm + 600000); //prevent cycle restart for 10m
    runHP = false;
  }

 //***Check evaporator/condensor above/below limits*** not intended for defrost purposes, halts system for 30m
  if (evaporator < minEv || condensor > maxCon) {
    runCompressor = false;
    if (runHP == true) hpStopped = tm;
    compLR = (tm + 1800000); //prevent cycle restart for 30m
    runHP = false;
  }
    
  
  digitalWrite(led, ledState);
  digitalWrite(comp, runCompressor);
  digitalWrite(inPump, runInPump);
  digitalWrite(outPump, runOutPump);


}

Ormston is offline   Reply With Quote
The Following 2 Users Say Thank You to Ormston For This Useful Post:
AC_Hacker (08-13-14), buffalobillpatrick (08-13-14)
Old 08-13-14, 06:15 PM   #182
AC_Hacker
Supreme EcoRenovator
 
AC_Hacker's Avatar
 
Join Date: Mar 2009
Location: Portland, OR
Posts: 4,004
Thanks: 303
Thanked 723 Times in 534 Posts
Default

BBP,

Ormston has just offered new code, so I should get your comment here...

Just looking at Ormston's code, it does include flow measurement, which is valuable.

...and Ko_deZ's code seemed locked up...

What do you think?

BTW,

I think that since we are going without a Wiki or anything, if changes are made to some version of code, we should zip the new sketch and attach to any comment.

I also think that we should consider Ko_deZ's code and Ormston's current code to each be Rev00, and if we make mods we should cite the base code-source and increment the sketch we use as a basis for our mod.

For instance, a sketch with a mod to Ormston's code might begin with:

Code:
//Ormston Rev01
#include <Thermistor.h>


double evaporator, condensor;  //Variables for temperatures from thermistors
float HpLPM;                   //Flow rate from flow meter in L/m
float HpLPM1;                   //Flow rate from flow meter in L/m
int minLPM = 3;                //Minimum flowrate to run HP
int minEv = 2;      
.
.
.
OR

Code:
//Ko_dez Rev12

/* First some legal mumbo jumbo:

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
.
.
.
NOTE: Bold added only for clarity of this illustration

ETC.

Does this seem agreeable to all?

Best,

-AC
__________________
I'm not an HVAC technician. In fact, I'm barely even a hacker...
AC_Hacker is offline   Reply With Quote
The Following User Says Thank You to AC_Hacker For This Useful Post:
buffalobillpatrick (08-13-14)
Old 08-13-14, 06:26 PM   #183
AC_Hacker
Supreme EcoRenovator
 
AC_Hacker's Avatar
 
Join Date: Mar 2009
Location: Portland, OR
Posts: 4,004
Thanks: 303
Thanked 723 Times in 534 Posts
Default

Steve,

I'm running Arduino 1.0.5-r2

And my hardware is Arduino Uno r3 (Chinese clone)
I tried to compile the code and here is the error merssage

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Arduino: 1.0.5-r2 (Windows 7), Board: "Arduino Uno"
D:\ARDUINO\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -ID:\ARDUINO\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\hardware\arduino\cores\arduino -ID:\ARDUINO\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\hardware\arduino\variants\standard C:\Users\i7-BOX\AppData\Local\Temp\build7816747282355614957.tm p\Ormston_sketch_aug12a.cpp -o C:\Users\i7-BOX\AppData\Local\Temp\build7816747282355614957.tm p\Ormston_sketch_aug12a.cpp.o

Ormston_sketch_aug12a.ino:1:24: warning: Thermistor.h: No such file or directory
Ormston_sketch_aug12a:29: error: 'Thermistor' does not name a type
Ormston_sketch_aug12a:30: error: 'Thermistor' does not name a type
Ormston_sketch_aug12a.ino: In function 'void readTemps()':
Ormston_sketch_aug12a:34: error: 'temp' was not declared in this scope
Ormston_sketch_aug12a:35: error: 'temp1' was not declared in this scope
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Gotta go for a break...

Back soon.

-AC
__________________
I'm not an HVAC technician. In fact, I'm barely even a hacker...
AC_Hacker is offline   Reply With Quote
Old 08-13-14, 08:29 PM   #184
buffalobillpatrick
Master EcoRenovator
 
Join Date: Mar 2014
Location: Florissant, Colorado
Posts: 599
Thanks: 814
Thanked 59 Times in 55 Posts
Default

A/C I got same error, on my Arduino Uno r3 (Chinese clone) different brand.

I downloaded the referenced zip file, put it into my libraries folder, unziped it
At Sketch Import library, clicked Thermister & compile now works

Last edited by buffalobillpatrick; 08-13-14 at 08:40 PM..
buffalobillpatrick is offline   Reply With Quote
Old 08-13-14, 09:51 PM   #185
AC_Hacker
Supreme EcoRenovator
 
AC_Hacker's Avatar
 
Join Date: Mar 2009
Location: Portland, OR
Posts: 4,004
Thanks: 303
Thanked 723 Times in 534 Posts
Default

Quote:
Originally Posted by buffalobillpatrick View Post
A/C I got same error, on my Arduino Uno r3 (Chinese clone) different brand.

I downloaded the referenced zip file, put it into my libraries folder, unziped it
At Sketch Import library, clicked Thermister & compile now works
Thanks BBP!

Maybe I was under a false impression, but I thought that it was possible to call a "library_name.zip" file from within the Arduino IDE, and have it automatically integrated into the library directory.

Maybe I was making things too complicated. I followed your method, and all is compiling now.

-AC
__________________
I'm not an HVAC technician. In fact, I'm barely even a hacker...
AC_Hacker is offline   Reply With Quote
The Following User Says Thank You to AC_Hacker For This Useful Post:
buffalobillpatrick (08-14-14)
Old 08-14-14, 01:44 AM   #186
AC_Hacker
Supreme EcoRenovator
 
AC_Hacker's Avatar
 
Join Date: Mar 2009
Location: Portland, OR
Posts: 4,004
Thanks: 303
Thanked 723 Times in 534 Posts
Default

The paint has dried in my prototype board, and I have put the main pieces into place.



Ormston's notes on the pin assignments are shown below:

D00 - (N/A)
D01 - (N/A)
D02 - Flow Sensor (indoor)
D03 - Flow Sensor (outdoor)
D04 - Call For Heat (+5V)
D05 - Compressor ON
D06 - Pump ON (indoor)
D07 - Pump ON (outdoor)
D08 - (N/A)
D09 - (N/A)
D10 - (N/A)
D11 - (N/A)
D12 - (N/A)
D13 - LED

A00 - Thermistor (evaporator temperature)
A01 - Thermistor (condenser temperature)
A02 - (N/A)
A03 - (N/A)
A04 - (N/A)
A05 - (N/A)

So I connected the hardware together, per Ormston's pin descriptions.



I'm using SSR's for now just because they have screw-down wire terminals for inputs and out puts, so no flat cable fabrication is required.

SSR Relays are connected to the Uno outputs as below:
  • SSR4 - (N/A)
  • SSR3 - D7 (outdoor pump)
  • SSR2 - D6 (indoor pump)
  • SSR1 - D5 (compressor)

I don't yet have the thermistors hooked up, no pumps hooked up, no flow sensors hooked up.

But I did hook up power and observed the controller's behavior.



Upon power up, the LEDs of the SSR that were driven by Uno digital output pins D7 (outdoot pump) and D6 (indoor pump), Both began to blink 24 blinks at roughly equal intervals.



After that only the SSR LED connected to D6 (indoor pump) continued to blink for 24 blinks at roughly equal intervals


After that neither SSR LED blinked.


Looks to me that the pattern is to pulse the pumps and to sense with the flow meters if water is flowing.

I'm sure that the other goodness will be apparent one the thermistors and flow meters are hooked up.

Thanks to everyone who has helped... it's starting to come to life!

Best,

-AC
Attached Thumbnails
Click image for larger version

Name:	proto-01.jpg
Views:	1132
Size:	23.5 KB
ID:	4555   Click image for larger version

Name:	proto-02.jpg
Views:	1127
Size:	32.3 KB
ID:	4556   Click image for larger version

Name:	proto-03.jpg
Views:	1214
Size:	52.1 KB
ID:	4557   Click image for larger version

Name:	proto-04.jpg
Views:	1392
Size:	51.5 KB
ID:	4558  
__________________
I'm not an HVAC technician. In fact, I'm barely even a hacker...

Last edited by AC_Hacker; 08-14-14 at 06:44 AM..
AC_Hacker is offline   Reply With Quote
The Following User Says Thank You to AC_Hacker For This Useful Post:
buffalobillpatrick (08-14-14)
Old 08-14-14, 02:34 AM   #187
Ormston
Apprentice EcoRenovator
 
Join Date: Mar 2013
Location: UK
Posts: 131
Thanks: 13
Thanked 35 Times in 32 Posts
Default

AC

Outputs shouldn't be blinking so I,be got an issue somewhere. Also will need the ability to disable flow sensors or we won,t get very far with testing.
Will take a look later, off to work now.
Ormston is offline   Reply With Quote
The Following User Says Thank You to Ormston For This Useful Post:
buffalobillpatrick (08-14-14)
Old 08-14-14, 06:46 AM   #188
ICanHas
Banned
 
Join Date: Aug 2014
Location: US
Posts: 150
Thanks: 7
Thanked 5 Times in 5 Posts
Default

Quote:
Originally Posted by AC_Hacker View Post
I learned something today that may be of greater interest to N. American readers that others...

I went to a hardware store to explore my options when I integrate this 1" diameter flow sensor into my heat pump design.

I found that a 1" NPT female thread adapter will not thread all the way on. In fact, one PVC adapter only went on < one full turn. Another, a brass adapter, went on about 2.5 turns before stopping.

-AC_Hacker
Looks like an o-ring face seal. Face seals are very common in auto applications. If you can find whatever brass piece that will make that happen, braze it together with a fitting with a standard NPT thread and you've got an adapter.
ICanHas is offline   Reply With Quote
The Following User Says Thank You to ICanHas For This Useful Post:
buffalobillpatrick (08-14-14)
Old 08-14-14, 07:07 AM   #189
Ormston
Apprentice EcoRenovator
 
Join Date: Mar 2013
Location: UK
Posts: 131
Thanks: 13
Thanked 35 Times in 32 Posts
Default

Try this V0.00001
Made a couple of corrections and added input D8 to simulate flow sensors reading 10L/m for testing.
Run code on simulator and seems OKish except the thermistor code, can't get additional lib's to work in the simulator for some reason.

Code:
#include <Thermistor.h>



double evaporator, condensor;  //Variables for temperatures from thermistors
float HpLPM;                   //Flow rate from flow meter in L/m
float HpLPM1;                   //Flow rate from flow meter in L/m
int minLPM = 3;                //Minimum flowrate to run HP
int minEv = 2;                //Minimum evaporator temp
int maxCon = 65;              //Maximum condensor temp
byte runHP = false;
byte runCompressor = false;
byte runOutPump = false;       // pump to circulate water to house/tank
byte runInPump = false;        //fan in case of ASHP
const int demandPin = 4;       // input connected to external thermostat to request heat
byte demand = false;               // variable for reading if heat required from thermostat
unsigned long compLR;          // Time compressor was last run
unsigned long hpStarted;        // Time HP cycle started
unsigned long hpStopped;        // Time HP cycle stopped
volatile int NbTopsFan; //measuring the rising edges of the signal
volatile int NbTopsFan1; //measuring the rising edges of the signal
int hallsensor = 2; //The pin location of the sensor
int hallsensor1 = 3; //The pin location of the sensor
byte led = 13;
byte ledState = false;
byte comp = 5;
byte inPump = 6;
byte outPump = 7;
unsigned long prevMillis = 0;        //used for led blinking
Thermistor temp(0);
Thermistor temp1(1);
byte simulateFlow = false;

// ********************Temperature measurement starts here**************
void readTemps() { //read all temperatures from thermistors
  evaporator = temp.getTemp();
  condensor = temp1.getTemp();
  //evaporator = 20;
  //condensor = 20;
  }

// ********************Temperature measurement ends here**************

// ********************Flow meter reading starts here**************

void hpFlow () //This is the function that the interupt calls
{
  NbTopsFan++;  //This function measures the rising and falling edge of the hall effect sensors signal
}

void hpFlow1 () //This is the function that the interupt calls
{
  NbTopsFan1++;  //This function measures the rising and falling edge of the hall effect sensors signal
}

void readFlows()
{
  NbTopsFan = 0; //Set NbTops to 0 ready for calculations
  NbTopsFan1 = 0; //Set NbTops to 0 ready for calculations
  interrupts(); //Enables interrupts
  delay (1000); //Wait 1 second
  noInterrupts(); //Disable interrupts
  HpLPM = (NbTopsFan / 2.75);
  HpLPM1 = (NbTopsFan1 / 2.75);
  simulateFlow = digitalRead(8);
  if (simulateFlow == true) {
    HpLPM = 10;
    HpLPM1 = 10;
  }
}
// ********************Flow meter reading ends here**************


void setup() {
  pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
  pinMode(hallsensor1, INPUT); //initializes digital pin 3 as an input
  attachInterrupt(0, hpFlow, RISING); //and the interrupt is attached (1 for Leonardo 0 for mega/uno)
  attachInterrupt(1, hpFlow1, RISING); //and the interrupt is attached (0 for Leonardo 1 for mega/uno)
  pinMode(led, OUTPUT);
  pinMode(comp, OUTPUT);
  pinMode(inPump, OUTPUT);
  pinMode(outPump, OUTPUT);
  pinMode(demandPin, INPUT); 
  compLR = millis();
  pinMode(8, INPUT); //disable flow sensors for testing, high simulates 10L/m

}

void loop() {
  readTemps();
  readFlows();
  demand = digitalRead(demandPin);

  unsigned long tm = millis();
  if ((demand == true) && (compLR <= (tm - 120000))) {
    if (runHP == false) hpStarted = tm;
    runHP = true;
  }
  else {
    if (runHP == true) hpStopped = tm;
    runHP = false;
  }

  //*****HP startup cycle********
  if (runHP == true) runInPump = true;
  if ((runHP == true) && (hpStarted <= (tm - 30000) && (HpLPM > minLPM))) runCompressor = true; //Delay compressor start 30s after starting in pump
  if ((runHP == true) && (hpStarted <= (tm - 60000))) {
    runOutPump = true; //Delay out pump start 60s after starting in pump
    ledState = true; ///turn on pin 13 led after startup of HP
  }
  
  //*****HP shutdown cycle********
  if (runHP == false) runCompressor = false;
  if ((runHP == false) && (hpStopped <= (tm - 120000))) runInPump = false;
  if ((runHP == false) && (hpStopped <= (tm - 300000))) {
    if (runOutPump == true && ledState == true) compLR = tm;
    runOutPump = false;
    ledState = false; ///turn off pin 13 led after shutdown of HP
  }
  
  //***Check flow rates above min***
  if ((runOutPump == true) && HpLPM < minLPM || HpLPM1 < minLPM) {
    runCompressor = false;
    if (runHP == true) {
    hpStopped = tm;
    compLR = (tm + 600000); //prevent cycle restart for 10m
    runHP = false;
    }
  }

 //***Check evaporator/condensor above/below limits*** not intended for defrost purposes, halts system for 30m
  if (evaporator < minEv || condensor > maxCon) {
    runCompressor = false;
    if (runHP == true) hpStopped = tm;
    compLR = (tm + 1800000); //prevent cycle restart for 30m
    runHP = false;
  }
    
  
  digitalWrite(led, ledState);
  digitalWrite(comp, runCompressor);
  digitalWrite(inPump, runInPump);
  digitalWrite(outPump, runOutPump);


}
Ormston is offline   Reply With Quote
The Following User Says Thank You to Ormston For This Useful Post:
buffalobillpatrick (08-14-14)
Old 08-14-14, 03:42 PM   #190
Ormston
Apprentice EcoRenovator
 
Join Date: Mar 2013
Location: UK
Posts: 131
Thanks: 13
Thanked 35 Times in 32 Posts
Default

Spent some more time trying to get the thermistor lib used in the sketches above working.
For whatever reason it doesn't work in an Arduino simulator so unless anyone has any objections i'm going to ditch the lib and use more conventional thermistor code.


Steve

Code:
/*Ormston GPHPC Rev02 
D00 - (N/A)
D01 - (N/A)
D02 - Flow Sensor (indoor)
D03 - Flow Sensor (outdoor)
D04 - Call For Heat (+5V)
D05 - Compressor ON
D06 - Pump ON (indoor)
D07 - Pump ON (outdoor)
D08 - Simulate flow sensors(sets flow to 10L/m for testing)
D09 - (N/A)
D10 - (N/A)
D11 - (N/A)
D12 - (N/A)
D13 - LED

A00 - Thermistor (evaporator temperature)
A01 - Thermistor (condenser temperature)
A02 - (N/A)
A03 - (N/A)
A04 - (N/A)
A05 - (N/A)
*/
#include <math.h>


double evaporator, condensor;  //Variables for temperatures from thermistors
float HpLPM;                   //Flow rate from flow meter in L/m
float HpLPM1;                   //Flow rate from flow meter in L/m
int minLPM = 3;                //Minimum flowrate to run HP
int minEv = 2;                //Minimum evaporator temp
int maxCon = 65;              //Maximum condensor temp
byte runHP = false;
byte runCompressor = false;
byte runOutPump = false;       // pump to circulate water to house/tank
byte runInPump = false;        //fan in case of ASHP
const int demandPin = 4;       // input connected to external thermostat to request heat
byte demand = false;               // variable for reading if heat required from thermostat
unsigned long compLR;          // Time compressor was last run
unsigned long hpStarted;        // Time HP cycle started
unsigned long hpStopped;        // Time HP cycle stopped
volatile int NbTopsFan; //measuring the rising edges of the signal
volatile int NbTopsFan1; //measuring the rising edges of the signal
int hallsensor = 2; //The pin location of the sensor
int hallsensor1 = 3; //The pin location of the sensor
byte led = 13;
byte ledState = false;
byte comp = 5;
byte inPump = 6;
byte outPump = 7;
unsigned long prevMillis = 0;        //used for led blinking
byte simulateFlow = false;
float pad = 9850;                       // balance/pad resistor value, set this to
                                        // the measured resistance of your pad resistor
float thermr = 10000;                   // thermistor nominal resistance



// ********************Temperature measurement starts here**************
float Thermistor(int RawADC) {
  long Resistance;  
  float Temp;  // Dual-Purpose variable to save space.

  Resistance=((1024 * pad / RawADC) - pad); 
  Temp = log(Resistance); // Saving the Log(resistance) so not to calculate  it 4 times later
  Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
  Temp = Temp - 273.15;  // Convert Kelvin to Celsius                      
  //temp = (Temp * 9.0)/ 5.0 + 32.0;                  // Convert to Fahrenheit
  return Temp;                                      // Return the Temperature
}

void readTemps() { //read all temperatures from thermistors
  evaporator = Thermistor(analogRead(A0));       // read ADC and  convert it to Celsius
  condensor = Thermistor(analogRead(A1));       // read ADC and  convert it to Celsius
  //evaporator = 20;
  //condensor = 20;
  }

// ********************Temperature measurement ends here**************

// ********************Flow meter reading starts here**************

void hpFlow () //This is the function that the interupt calls
{
  NbTopsFan++;  //This function measures the rising and falling edge of the hall effect sensors signal
}

void hpFlow1 () //This is the function that the interupt calls
{
  NbTopsFan1++;  //This function measures the rising and falling edge of the hall effect sensors signal
}

void readFlows()
{
  NbTopsFan = 0; //Set NbTops to 0 ready for calculations
  NbTopsFan1 = 0; //Set NbTops to 0 ready for calculations
  interrupts(); //Enables interrupts
  delay (1000); //Wait 1 second
  noInterrupts(); //Disable interrupts
  HpLPM = (NbTopsFan / 2.75);
  HpLPM1 = (NbTopsFan1 / 2.75);
  simulateFlow = digitalRead(8);
  if (simulateFlow == true) {
    HpLPM = 10;
    HpLPM1 = 10;
  }
}
// ********************Flow meter reading ends here**************


void setup() {
  pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
  pinMode(hallsensor1, INPUT); //initializes digital pin 3 as an input
  attachInterrupt(0, hpFlow, RISING); //and the interrupt is attached (1 for Leonardo 0 for mega/uno)
  attachInterrupt(1, hpFlow1, RISING); //and the interrupt is attached (0 for Leonardo 1 for mega/uno)
  pinMode(led, OUTPUT);
  pinMode(comp, OUTPUT);
  pinMode(inPump, OUTPUT);
  pinMode(outPump, OUTPUT);
  pinMode(demandPin, INPUT); 
  compLR = millis();
  pinMode(8, INPUT); //disable flow sensors for testing, high simulates 10L/m

}

void loop() {
  readTemps();
  readFlows();
  demand = digitalRead(demandPin);

  unsigned long tm = millis();
  if ((demand == true) && (compLR <= (tm - 120000))) {
    if (runHP == false) hpStarted = tm;
    runHP = true;
  }
  else {
    if (runHP == true) hpStopped = tm;
    runHP = false;
  }

  //*****HP startup cycle********
  if (runHP == true) runInPump = true;
  if ((runHP == true) && (hpStarted <= (tm - 30000) && (HpLPM > minLPM))) runCompressor = true; //Delay compressor start 30s after starting in pump
  if ((runHP == true) && (hpStarted <= (tm - 60000))) {
    runOutPump = true; //Delay out pump start 60s after starting in pump
    ledState = true; ///turn on pin 13 led after startup of HP
  }
  
  //*****HP shutdown cycle********
  if (runHP == false) runCompressor = false;
  if ((runHP == false) && (hpStopped <= (tm - 120000))) runInPump = false;
  if ((runHP == false) && (hpStopped <= (tm - 300000))) {
    if (runOutPump == true && ledState == true) compLR = tm;
    runOutPump = false;
    ledState = false; ///turn off pin 13 led after shutdown of HP
  }
  
  //***Check flow rates above min***
  if ((runOutPump == true) && HpLPM < minLPM || HpLPM1 < minLPM) {
    runCompressor = false;
    if (runHP == true) {
    hpStopped = tm;
    compLR = (tm + 600000); //prevent cycle restart for 10m
    runHP = false;
    }
  }

 //***Check evaporator/condensor above/below limits*** not intended for defrost purposes, halts system for 30m
  if (evaporator < minEv || condensor > maxCon) {
    runCompressor = false;
    if (runHP == true) hpStopped = tm;
    compLR = (tm + 1800000); //prevent cycle restart for 30m
    runHP = false;
  }
    
  
  digitalWrite(led, ledState);
  digitalWrite(comp, runCompressor);
  digitalWrite(inPump, runInPump);
  digitalWrite(outPump, runOutPump);


}

Ormston is offline   Reply With Quote
The Following User Says Thank You to Ormston For This Useful Post:
buffalobillpatrick (09-09-14)
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 04:18 AM.


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