View Single Post
Old 02-17-15, 01:27 PM   #14
buffalobillpatrick
Master EcoRenovator
 
Join Date: Mar 2014
Location: Florissant, Colorado
Posts: 599
Thanks: 814
Thanked 59 Times in 55 Posts
Default

Added Subcooling

Hi Side Pressure Transducer:

1 8

Code:
/********************************************************
 *
 * ARDUINO R290 Calculate Subcooling & Suction Line Superheat.
 *
 * Note: REQUIRED SENSOR
 *       Suction Pressure Sensor:  0-150PSI with output of .5 -> 4.5vdc
 *       High Pressure Sensor:     0-300PSI with output of .5 -> 4.5vdc
 *
 * If in DEBUG mode, values are forced to test code function
 *
 * In Void Loop:
 *
 *     , read Hi Side Pressure Transducer
 *     , convert_raw_sensor_to_PSI 
 *     , if input parameter Raw_ADC is not in bounds (between 266 -> 921) 
 *     , hang forever1
 *
 *     , calc_R290_Saturated_Temp
 *     , if input parameter PSI is not in bounds (between 60 -> 300PSI)
 *     , hang forever2
 *
 *     , read Subcooling_Temp_sensor (analog NTC thermistor just prior to TXV)
 *
 *     , calc Suction Subcooling
 *
 *
 *     , read Lo_Side_Pressure_Transducer
 *     , convert_raw_sensor_to_PSI 
 *     , if input parameter Raw_ADC is not in bounds (between 266 -> 921) 
 *     , hang forever3
 *
 *     , calc_R290_Saturated_Temp
 *     , if input parameter PSI is not in bounds (between 30 -> 150PSI)
 *     , hang forever4
 *
 *     , read Suction Temp sensor (analog NTC thermistor)
 *
 *     , calc Suction Superheat
 *
 * Repeat Void loop
 *
 *
 * Change History: 
 * 02/17/15 Coded, BBP
 *
 *
 *
 ********************************************************/

#if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
  #else
  #include "WProgram.h"
  #endif

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


#define DEBUG 1
//#define DEBUG 0


#define I2C_ADDR    0x3F // <<----- Add your address here.  Find it from I2C Scanner
                       //D3
#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 D2 -> D12 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  

//  pinMode(A0, OUTPUT);     //This works acording 
                             //  http://arduino.cc/en/Tutorial/AnalogInputPins
//  digitalWrite(A0, HIGH);  //


#define Subcooling_Temp_sensor_pin        A0 
#define Hi_Side_Pressure_Transducer_pin   A1
#define Suct_Temp_sensor_pin              A2 
#define Lo_Side_Pressure_Transducer_pin   A3
 
float  Raw_ADC, Hi_Side_PSI, Subcooling_T, Subcooling;
float  Suct_PSI, Suct_T, Saturated_Temp, Suct_Superheat;

int Y;

int Which_Sensor;
#define Sensor_150   1
#define Sensor_300   2
 

void setup(void)       //Start Setup
  {
        
  pinMode (Subcooling_Temp_sensor_pin,      INPUT);
  pinMode (Hi_Side_Pressure_Transducer_pin, INPUT);
  pinMode (Suct_Temp_sensor_pin,            INPUT);
  pinMode (Lo_Side_Pressure_Transducer_pin, INPUT); 
 
 
 // Serial.begin(9600); // start serial communication
 // delay(10000);      //time to enable monitor window
 // Serial.println(F("........Hello world!......."));
 // delay(100); 
 
  
  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("LP_SUPERH_SUBCOL"));
  delay(10000);


  if(DEBUG)
  {       
  lcd.clear();
  lcd.home (); // go home
  lcd.print(F("DEBUG = ON"));
  delay(10000);
  }
  else 
  {       
  lcd.clear();
  lcd.home (); // go home
  lcd.print(F("DEBUG = OFF"));
  delay(10000);
  }

  }    //end setup




  void loop ()
{ 
 
  Raw_ADC = analogRead(Hi_Side_Pressure_Transducer_pin);  //read Hi Side pressure
 
if(DEBUG){  Raw_ADC = 400;}

  Hi_Side_PSI =  convert_raw_sensor_to_PSI( Raw_ADC, Sensor_300);
 
  lcd.clear();
  lcd.home (); // go home
  lcd.print(F("SUBCOL_PSI="));
  lcd.print(Hi_Side_PSI);  
  delay(10000);  

 if (Hi_Side_PSI == -1)  //is Hi_Side_PSI out of bounds
  {
  lcd.clear();
  lcd.home (); // go home
  lcd.print(F("RAW_PSI_NG"));   
  lcd.setCursor(0,1);
  lcd.print(F("HANG_FOREVER_1"));   
  do{Y = Y;} while (Y == Y);  //hang forever
  }      
  
  else
  {  //else in bounds  
  Saturated_Temp = calc_R290_Saturated_Temp(Hi_Side_PSI, Sensor_300); 

  lcd.clear();
  lcd.home (); // go home
  lcd.print(F("SAT_T="));
  lcd.print(Saturated_Temp);  
  lcd.print(F("*F"));
  delay(10000);
  
  if (Saturated_Temp == -1)  //is Hi_Side_PSI out of bounds
  {
  lcd.clear();
  lcd.home (); // go home
  lcd.print(F("SUBCOOL_PSI_NG"));   
  lcd.setCursor(0,1);
  lcd.print(F("HANG_FOREVER_2"));   
  do{Y = Y;} while (Y == Y);  //hang forever
  }      
  
  else
  {
    
//read Subcooling Temp sensor
  Subcooling_T = (Read_10K_NTC (Subcooling_Temp_sensor_pin)); 
  
if(DEBUG){ Subcooling_T = 100;}
      
  lcd.clear();
  lcd.home (); // go home
  lcd.print(F("SUBCOL_T="));
  lcd.print(Subcooling_T);  
  lcd.print(F("*F"));
  delay(10000); 
    
  Subcooling = Subcooling_T - Saturated_Temp;  //calc Subcooling
  
  lcd.clear();
  lcd.home (); // go home
  lcd.print(F("SUBCOOL="));
  lcd.print(Subcooling);  
  lcd.print(F("*F"));
  delay(10000);
  }
  
  }  //end else in bounds
  
 
 
 //To be continued
buffalobillpatrick is offline   Reply With Quote