Heat Recovery Unit

I am trying to develop a replacement for the control board for a heat recovery unit. There's many more functions to build in as I get better at this....

However, I've made a start on a sketch for a UNO but it's not working as I expected. The normal operation I'm aiming for is:

On initial start-up Relay 3 is active providing power to Relays 1 & 2.

When the programmer calls for heat, Pins 1 and Ground are closed, Relay 1 on Pin 7 becomes active, which activates the compressor.

If the (mechanical, not thermister) Frost Stat detects excess ice, Pins 2 and Ground are opened, Relay 2 on Pin 6 becomes active which activates the defrost valve.

If the High Pressure Stat triggers, Pins 3 and Ground are opened, which de-activates Relay 3 which shuts down Relays 1 & 2.

If someone more knowledgeable than me loads this sketch into a UNO, it can be seen that only Relay 2 behaves as expected but the wrong way 'round.

Also, is there a better way of dealing with the High Pressure Stat, which should shut down the other two functions if it triggers. Thanks.

Heat Recovery.ino (2.39 KB)

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:

See?? That's how to do it. Maybe it's a 1am thing.

If newbies posting code incorrectly is a constant problem, then how about moving item #7 up to item #1? Or even title the sticky "Before Posting Code, Read This" and then have the code section at item #1. Then people will see it. At the moment the section you want people to read is a post underneath a post. No wonder no-one bothers to drill down to find it.

My apologies for not formatting the code, I didn't realise that was required in addition to verifying. I do not, and never will, consider myself a coder.

Before embarking on this project I studied "Getting Started With Arduino" which I believe is the standard beginners tome. I don't think it mentions braces in its 130 pages. I didn't think a course in C++ would be necessary to put together a simple sketch like this. However, on your advice I've dipped into an online course to see what it says on the subject of braces and, to be honest, I'm no further illuminated on the subject than I was at the start. Further study required.

Anyway, thank you for replying to my post.

I'm only trying to achieve three functions with this sketch so that I can get a heat recovery unit working in a basic fashion for visitors next week. The manufacturer's board is controlling the fans OK, but not the compressor. The manufacturer's only remedy is for me to spend £11,000 on a new unit, which is why I'm trying to get some basic functionality out of my old unit. There's nothing wrong with the compressor, the problem is on the board.

1: The Compressor must come on if the Programmer closes Pin 1 to Ground.

2: If the Frost Stat opens Pin 2 to Ground (it's normally closed), the Defrost Valve must switch on, along with the Compressor which should already be on (slightly different to what I said above) until the excess ice is gone and the Frost Stat closes Pin 2 to Ground again, switching the Defrost Valve off, leaving just the compressor on.

3: If the High Pressure Stat opens Pin 3 to Ground (it's normally closed), both the Compressor and the Defrost Valve must switch off, (and remain that way until the Arduino is reset, if possible.)

I suspect the reason my sketch is not working correctly is to do with these braces. I thought my initial sketch was a pretty reasonable start.

And now, the latest version of the sketch....

#define RELAY_ON 0
#define RELAY_OFF 1

#define Relay_1  7  // Digital I/O pin number 7 - Relay 1 - Compressor
#define Relay_2  6  // Digital I/O pin number 6 - Relay 2 - Defrost Valve
#define Relay_3  5  // Digital I/O pin number 5 - Relay 3 - Supply Power to Relays 1 & 2
#define Relay_4  4  // Digital I/O pin number 4 - Relay 4 - Not Used

#define Programmable_Thermostat 1  // Digital I/O pin 1 - Toggle Switch - closed for heat demand
#define Frost_Stat  2  // Digital I/O pin 2-  Toggle Switch - normally closed, open for defrost mode
#define High_Pressure_Stat  3  // Digital I/O pin 3 -  Toggle Switch - normally closed, open to stop compressor

void setup()         /****** SETUP: RUNS ONCE ******/
{
  // Initialize Pins so relays are inactive at reset
  digitalWrite(Relay_1, RELAY_ON);  // Initialize Relay Pins so relays are inactive at reset
  digitalWrite(Relay_2, RELAY_ON);  // Initialize Relay Pins so relays are inactive at reset
  digitalWrite(Relay_3, RELAY_ON);  // Initialize Relay Pins so relays are inactive at reset
  digitalWrite(Relay_4, RELAY_ON);  // Initialize Relay Pins so relays are inactive at reset

  // THEN set pins as outputs
  pinMode(Relay_1, OUTPUT);  // set Relay Pin as output
  pinMode(Relay_2, OUTPUT);  // set Relay Pin as output
  pinMode(Relay_3, OUTPUT);  // set Relay Pin as output
  pinMode(Relay_4, OUTPUT);  // set Relay Pin as output

  pinMode(1, INPUT_PULLUP); // enable internal pullup resistor on Pin 1 - Programmable Thermostat
  pinMode(2, INPUT_PULLUP); // enable internal pullup resistor on Pin 2 - Defrost Stat
  pinMode(3, INPUT_PULLUP); // enable internal pullup resistor on Pin 3 - High Pressure Stat

}          //--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  if (digitalRead(1) == HIGH
     )digitalWrite(Relay_1, RELAY_ON);  // set Compressor ON

  else {
    digitalWrite(Relay_1, RELAY_OFF);  // set Compressor OFF

    if (digitalRead(2) == LOW
       )digitalWrite(Relay_2, RELAY_ON);  // set Defrost Valve ON

    else {
      digitalWrite(Relay_2, RELAY_OFF);  // set Defrost Valve OFF

      if (digitalRead(3) == LOW
         )digitalWrite(Relay_3, RELAY_ON);  // set available power for Compressor & Defrost Valve to ON

      else {
        digitalWrite(Relay_3, RELAY_OFF);  // set available power for Compressor & Defrost Valve to OFF

      }
    }
  }
}//--(end main loop )---



//*********( THE END )***********

Better not to use pin one for a relay, then you can put some Serial.print statements in your code to help debug.

The issue is likely the nested if statements that Delta_G identified in reply #2.

What does the system do with the sketch as written?

Oh well, there's more than one way to skin a rabbit. I found a much simpler way of doing what I wanted. And I've moved the trigger away from Pin 1. The Adruino is now in my attic doing it's thing. Although I'm a bit disappointed I didn't get to the bottom of the braces thing.

I've still got a problem though. I switched to an 8 relay block from the 4 I was using as I need 7 relays anyway, and this one has optocouplers and slots which the old one didn't have.

The problem I'm having is, when the UNO is reset, Relay no. 8 flickers half a dozen times on reboot, so I can't really connect anything to it.

What would the reason for this be? Video attached. Thanks.

Edit: video was too big.

Actually, not having a clue about coding and managing to get a microcontroller to control your heat pump is a very good achievement.

I know you said this was a “temporary” solution, but a big design mode of most HVAC compressor controllers is that will always wait for typical 5 minutes between engaging the compressor.

Else the compressor will be “stalled” as the high side is already quite high and that can damage the winding, armatures, and even the compressor mechanics itself in some cases. It’s not usually a once and done event, but if it was a common occurrence and or the system is already perished, a few “Hot Starts” might finish it off.

So to prevent that, set a variable to millis() during setup, also set that same variable to millis() when you turn off the compressor and check that mills() - variable at >= 300000 to make sure you give the pressure some time to disapate.

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png? :slight_smile:

Thanks.. Tom... :slight_smile:

Oops, sorry, I forgot to upload the code.

I solved the rattling relay - I had it plugged into Pin 13 so I moved them all down 1.

The photo is on my bench, I know it's a bit "how're you doing" as Dave would say, but it works, and I've got a proper connection shield on its way so that should make it look a lot tidier. And I've got it in a proper box because of the high voltage areas.

The photo shows the compressor and the defrost valve are active, if I plug the orange wire into the ground line as well, relays 6 & 7 become active which opens the control lines to relays 4 & 5.

@ Delta_G, yes, I'm stubborn, but I've enjoyed our sparring on this project and thanks for your time. I'll make it a priority to learn about braces. It would be interesting to put you in a 20 acre field and with a tractor and plough, and tell you to get ploughing. I dare say you'd make a fair mess of it - even though there's lots of information on the internet on how to plough. Whereas I can do it without even thinking.

@ Slumpert, that's a good thought, the original board used to start the compressor about 10 seconds after the fans started, that must be why. I'll incorporate that into the code next.

The code as it is at the moment:

#define RELAY_ON 0
#define RELAY_OFF 1

#define Relay_1  5  // Digital I/O pin number 5 - Relay 1 - Fan 90 V
#define Relay_2  6  // Digital I/O pin number 6 - Relay 2 - Fan 120 V Extract
#define Relay_3  7  // Digital I/O pin number 7 - Relay 3 - Fan 90 V
#define Relay_4  8  // Digital I/O pin number 8 - Relay 4 - Compressor
#define Relay_5  9  // Digital I/O pin number 9 - Relay 5 - Defrost Valve
#define Relay_6  10  // Digital I/O pin number 10 - Relay 6 - Control to Compressor
#define Relay_7  11  // Digital I/O pin number 11 - Relay 7 - Control to Defrost Valve
#define Relay_8  12  // Digital I/O pin number 12 - Relay 8 - Not Used

#define Programmable_Thermostat 2  // Digital I/O pin 2 - Toggle Switch - closed for heat demand
#define Frost_Stat  3              // Digital I/O pin 3-  Toggle Switch - normally closed, open for defrost mode
#define High_Pressure_Stat  4      // Digital I/O pin 4 - Toggle Switch - normally closed, open to stop compressor and defrost valve

void setup()         /****** SETUP: RUNS ONCE ******/
{
  // Initialize Pins so relays are inactive at reset
  digitalWrite(Relay_1, RELAY_OFF);  // Initialize Relay Pins so relays are inactive at reset
  digitalWrite(Relay_2, RELAY_OFF);  // Initialize Relay Pins so relays are inactive at reset
  digitalWrite(Relay_3, RELAY_OFF);  // Initialize Relay Pins so relays are inactive at reset
  digitalWrite(Relay_4, RELAY_OFF);  // Initialize Relay Pins so relays are inactive at reset
  digitalWrite(Relay_5, RELAY_OFF);  // Initialize Relay Pins so relays are inactive at reset
  digitalWrite(Relay_6, RELAY_OFF);  // Initialize Relay Pins so relays are inactive at reset
  digitalWrite(Relay_7, RELAY_OFF);  // Initialize Relay Pins so relays are inactive at reset
  digitalWrite(Relay_8, RELAY_OFF);  // Initialize Relay Pins so relays are inactive at reset

  // THEN set pins as outputs
  pinMode(Relay_1, OUTPUT);  // set Relay Pin as output
  pinMode(Relay_2, OUTPUT);  // set Relay Pin as output
  pinMode(Relay_3, OUTPUT);  // set Relay Pin as output
  pinMode(Relay_4, OUTPUT);  // set Relay Pin as output
  pinMode(Relay_5, OUTPUT);  // set Relay Pin as output
  pinMode(Relay_6, OUTPUT);  // set Relay Pin as output
  pinMode(Relay_7, OUTPUT);  // set Relay Pin as output
  pinMode(Relay_8, OUTPUT);  // set Relay Pin as output

  pinMode(2, INPUT_PULLUP); // enable internal pullup resistor on Pin 2 - Programmable Thermostat
  pinMode(3, INPUT_PULLUP); // enable internal pullup resistor on Pin 3 - Defrost Stat
  pinMode(4, INPUT_PULLUP); // enable internal pullup resistor on Pin 4 - High Pressure Stat

}          //--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  {
    digitalWrite(8, digitalRead(2));      // turn Compressor Relay ON if input pin is HIGH, else turn OFF
  }
  {
    digitalWrite(9, digitalRead(3));      // turn Defrost Valve Relay ON if input pin is HIGH, else turn OFF
  }
  {
    digitalWrite(10, digitalRead(4));      // turn OFF control to Compressor Relay if input pin is HIGH, else turn OFF
  }
  {
    digitalWrite(11, digitalRead(4));      // turn OFF control to Defrost Valve Relay if input pin is HIGH, else turn OFF
  }
}




//--(end main loop )---



//*********( THE END )***********

If you're going to do this:

#define Programmable_Thermostat 2  // Digital I/O pin 2 - Toggle Switch - closed for heat demand

You might as well use it in your pinMode and digitalWrite statements - helps you not miss one if you change pins again.

Here you have two superfluous braces:

  {
    digitalWrite(8, digitalRead(2));      // turn Compressor Relay ON if input pin is HIGH, else turn OFF
  }

Six more below too.

Hi,
Ops pic;


Tom.. :slight_smile:

Thank you @Slumpert for drawing my attention to how important it is to avoid hot starts for the compressor. I hadn't appreciated that. I've tried to take your advice on how to enact that but, how shall I say, I'm still working on it....

And @TomGeorge, I'll draw up a circuit diagram soon, when I've got this millis() thing sorted out.

At least I've got the braces sorted out (I think). It works, anyway.

// constants don't change
const int RELAY_ON = 0;
const int RELAY_OFF = 1;

const int RELAY_1 = 5;  // Digital I/O pin number 5 - Relay 1 - Not used
const int RELAY_2 = 6;  // Digital I/O pin number 6 - Relay 2 - Not used
const int RELAY_3 = 7;  // Digital I/O pin number 7 - Relay 3 - Not used
const int RELAY_4 = 8;  // Digital I/O pin number 8 - Relay 4 - Not used
const int RELAY_5 = 9;  // Digital I/O pin number 9 - Relay 5 - Compressor
const int RELAY_6 = 10;  // Digital I/O pin number 10 - Relay 6 - Defrost Valve
const int RELAY_7 = 11;  // Digital I/O pin number 11 - Relay 7 - Compressor Relay control line
const int RELAY_8 = 12;  // Digital I/O pin number 12 - Relay 8 - Defrost Valve Relay control line

const int Programmable_Thermostat = 2;  // Digital I/O pin 2 - closed for heat demand
const int Frost_Stat = 3;               // Digital I/O pin 3 - normally closed, open for defrost mode
const int High_Pressure_Stat = 4;       // Digital I/O pin 4 - normally closed, open to stop compressor and defrost valve

void setup()         /****** SETUP: RUNS ONCE ******/
{
  // Initialize Pins so relays are inactive at reset
  digitalWrite(RELAY_1, RELAY_OFF);  // Initialize Relay Pins so relays are inactive at reset
  digitalWrite(RELAY_2, RELAY_OFF);  // Initialize Relay Pins so relays are inactive at reset
  digitalWrite(RELAY_3, RELAY_OFF);  // Initialize Relay Pins so relays are inactive at reset
  digitalWrite(RELAY_4, RELAY_OFF);  // Initialize Relay Pins so relays are inactive at reset
  digitalWrite(RELAY_5, RELAY_OFF);  // Initialize Relay Pins so relays are inactive at reset
  digitalWrite(RELAY_6, RELAY_OFF);  // Initialize Relay Pins so relays are inactive at reset
  digitalWrite(RELAY_7, RELAY_OFF);  // Initialize Relay Pins so relays are inactive at reset
  digitalWrite(RELAY_8, RELAY_OFF);  // Initialize Relay Pins so relays are inactive at reset

  // THEN set pins as outputs
  pinMode(RELAY_1, OUTPUT);  // set Relay Pin as output
  pinMode(RELAY_2, OUTPUT);  // set Relay Pin as output
  pinMode(RELAY_3, OUTPUT);  // set Relay Pin as output
  pinMode(RELAY_4, OUTPUT);  // set Relay Pin as output
  pinMode(RELAY_5, OUTPUT);  // set Relay Pin as output
  pinMode(RELAY_6, OUTPUT);  // set Relay Pin as output
  pinMode(RELAY_7, OUTPUT);  // set Relay Pin as output
  pinMode(RELAY_8, OUTPUT);  // set Relay Pin as output

  pinMode(2, INPUT_PULLUP); // enable internal pullup resistor on Pin 2 - Programmable Thermostat
  pinMode(3, INPUT_PULLUP); // enable internal pullup resistor on Pin 3 - Defrost Stat
  pinMode(4, INPUT_PULLUP); // enable internal pullup resistor on Pin 4 - High Pressure Stat


}          //--(end setup )---


void loop() {  /****** LOOP: RUNS CONSTANTLY ******/
  if (digitalRead(Programmable_Thermostat) == LOW)
  {
    digitalWrite(RELAY_5, RELAY_ON);  // set Compressor ON

  }    else   {
    digitalWrite(RELAY_5, RELAY_OFF);  // set Compressor OFF

  }

  if (digitalRead(Frost_Stat) == HIGH)
  {
    digitalWrite(RELAY_6, RELAY_ON);  // set Defrost Valve ON

  } else   {
    digitalWrite(RELAY_6, RELAY_OFF);  // set Defrost Valve OFF
  }

  if (digitalRead(High_Pressure_Stat) == HIGH)
  {
    digitalWrite(RELAY_7, RELAY_ON);  // Compressor Relay control line OPEN - Disabled

  } else   {
    digitalWrite(RELAY_7, RELAY_OFF);  // Compressor Relay control line CLOSED
  }

  if (digitalRead(High_Pressure_Stat) == HIGH)
  {
    digitalWrite(RELAY_8, RELAY_ON);  // Defrost Valve Relay control line OPEN - Disabled

  } else   {
    digitalWrite(RELAY_8, RELAY_OFF);  // Defrost Valve Relay control line CLOSED
  }
}


//--(end main loop )---



//*********( THE END )***********