EcoRenovator (
-   Geothermal & Heat Pumps (
-   -   Home made heat pump controller (

Acuario 11-16-15 02:20 AM

Home made heat pump controller
I need a heat pump controller for a flat that I have in the nearby city. I have installed under floor heating as it is probably the most comfortable and efficient heating there is (and it can also work for cooling).

There are commercial heat pumps around but I have enough experience with my own home setup to be able to build my own unit.

One of the 'problems' with building your own whatever is the case and display, especially if it is visible to everyone. I did think about a touch screen LCD display or an OLED display and some buttons but anything I was going to make would look home-made and I wanted something a bit better.

Looking on ebay I found lots of fancy looking thermostats with nice displays and buttons but nothing that could run both heating and cooling, also there was no way o communicate with these units as they were self contained.

After some hunting I finally came across a thermostat, a BAC-1000, on AliBaba that has a RS485 interface so I can communicate with it, works for heating and cooling, looks good and is touch control. It also fits into a standard electrical outlet box - perfect!

One down, several to go.

My initial list of hardware requirements for the controller were:
  • Wall mounted thermostat for user control
  • Sensors for compressor and evaporator
  • Sensors for water flow/return
  • Humidity sensor to avoid dew forming in summer when in cooling
  • Real time clock
  • Relays for compressor (solid state), fan (2 speeds), reversing valve, circulating pump
  • Ethernet interface for status
  • RS485 interface for thermostat
  • Small display for local status information
  • Keyboard for programming

And obviously a processor board to run it all :-)

For many years I have been using pic processors to control my projects and have avoided the Arduinos. My reason has mainly been the lack of range of Arduino boards and the poor support for debugging, there's nothing like single stepping through code to see where you messed up.

I decided to take the plunge though and bought myself a UNO, loaded up the Arduino IDE and wrote a few lines of code. All worked well however the IDE is very basic so I went looking for alternatives. I use Visual Studio extensively so I was really happy to find someone had developed an plugin for VS for programming Arduinos - Visual Micro Arduino Plugin (new version, simpler & more powerful). The plugin works well and is being actively supported, it also includes a debugger that can be activated and although it's not single step it can help - I've not yet tried out much of it's functionality.

The great thing about the Arduino is the number of libraries there are available for almost any peripheral you can think of. Most work first time however some need a bit of coaxing into life. Compared to the pic it's luxury.

I started putting together some modules for the controller using the various libraries I found and then ran out of memory space on the UNO, it really is very limited. So I moved up to a Mega 2560. The great thing is all the code works just the same.

Anyone who programs these small boards will know the typical program structure is a single loop that contains all the logic and calls to read the various sensors, write to displays, set relays etc. All good if you have a fairly simple program with few peripherals but this project quickly exceeded this, especially with the Ethernet interface which runs a web server for (initially) displaying status information.

The solution to this problem is a 'Real time operating system' (RTOS). This allows you to have what seems like separate programs all running at the same time on the same processor, just like your pc or mac. Each 'program' runs in its own thread and has its own memory allocated to it. The individual threads can interact with each other or just run autonomously but they can share the same program variables. The RTOS I found and use is called NilRTOS, it is very small and has been ported to the Arduino.

So, for example, a thread running to read temperature sensors can set values for variables 'sensor1, sensor2, sensor3' etc. and a thread that is running completely separately that displays stuff on an lcd can display these values.

Using this approach allows the ever more complex single thread program to be split up into individual mini 'programs' or threads, each one independently running a peripheral and with the main program loop now free to handle the control of the heat pump without worrying about what is going on around it with the lcd, the Ethernet, reading sensors etc. Hopefully this is clear!

The threads I have in my controller are:
  • Temperature sensors (digital ones - ds18b20)
  • Temperature sensors (analogue 10K NTC thermistors)
  • Display (rather than LCD I use a small OLED display)
  • RS485 to communicate with the BAC thermostat
  • Ethernet for the web server
  • Humidity sensor - I use a DHT11 temperature/humidity sensor
  • Defrost algorythm

... to be continued


TechShop 11-16-15 03:29 AM

Cool to see other guys thinking about tackling this item too. I'm interested to see what you come up with.

I'm working on a similar project to control the GSHP I assembled this summer. I just posted some (admittedly sloppy) Arduino code that I'm using for datalogging the DS18B20's. It's a little bloated for the 328P chip, but runs fine on chips with more memory.

The direct control of the GSHP is working now using two OMRON ZEN PLC units with some thermister / voltage divider circuits. I plan to indirectly control everything with a Raspberry Pi / Raspian / Apache web server.

Have you considered using a tablet or cheap smart phone with Android or Linux and a custom UI as a thermostat interface? I am considering something in that direction.

Acuario 11-16-15 01:18 PM

I did consider various options for the thermostat but at 36.90 euros including shipping on AliExpress it would have been difficult to find or build something comparable.

Acuario 11-16-15 02:04 PM

2 Attachment(s)
The benefit of having each part of the program running in its own thread is that it becomes somewhat easier to debug the program as you can disable individual threads and concentrate on the bit you are writing.

A couple of the oddities I found that didn't occur with a single threaded program is that many of the Arduino string class functions failed to work.
Sorry if this gets technical.. the reason appears to be that calls to malloc do not allocate memory as they should do, the return is a null pointer and so any function that relies on the dynamically allocated memory fails. Sadly this means allocating fixed length strings to hold, for example, http requests.

The other oddity was that I started getting odd results when reading analogue peripherals. Initially I was using a 4 button keypad using a single analogue input and a resistor divider to give 4 distinct values (a neat way to use a single pin for a simple keyboard). I was also reading NTC thermistors in a separate thread. Individually the peripherals worked fine but when running in threads they failed. Finally I realised that it was because the threads would clash and both try to read analogue voltages at the same time. It turns out that although the Arduino has multiple analogue pins it only has a single adc (analogue to digital converter) so can only do a single conversion at a time. A flag to indicate an analogue read is in progress that stops any other analogue read taking place sorted that problem out.

Initially I was going to use a keyboard to program the various parameters for such things as defrost temperature (start/stop), defrost cycle time, maximum temperature etc. but it started to become very complex and with 4 buttons and a small display it was getting over complex.

As the controller has an inbuilt web server for displaying status information it seemed the easiest option to use the same server to set up all the settings. A 'few' lines of code, a bit of html and response processing and now programming the controller is dead easy.

The status page looks like this:

The web pages aren't pretty but they are functional. You could 'beautify' them with some css but the Arduino itself isn't really up to serving up complex web pages, css files etc.

The status page auto updates every 15 seconds using a technique called ajax whereby it only receives the values and then fills in all the spaces on the page with the current values - this saves sending the whole web page each time a refresh is requested.

jeff5may 11-16-15 04:52 PM

Cheater, cheater, pumpkin eater! You've offloaded the work onto other devices! You're supposed to strain the dev board! Just kidding.

In the general purpose controller discussion, many of the contributors could not grasp the idea that the dev board (either uno or mega) should not need to do everything itself. The wish list of functions became so enormous that both ac_hacker and I could not reel in the diversity of devices that were built by many for their own specific sets of needs. My iteration is very basic: it reads a single onewire thermometer and functions as a thermostat with auto changeover. It would be AWESOME if it could speak WiFi, Ethernet or USB with a more intelligent sand-based lifeform. Having a defrost control built into the uno is a primary goal for a unit I am pondering right now.

Ok, so your arduino is acting as an Ethernet to rs485 bridge and a humidity sensor? Are you still using an rtos or did you switch back to wiring/python/c? What else does it do? I'm very interested.

TechShop 11-16-15 08:13 PM

Acuario, nice work. I don't think you need to add any frills to your web pages. That touch screen thermostat will put a nice face on the finished product.

Jeff, for the reasons you have cited, I'm an advocate of using an inexpensive PLC relay unit to do the dirty work at the heat pump as commanded by the system controller or thermostat (in this case, Arduino).

The simple ladder logic makes it possible to control a complex heat pump arrangement (compressor, pumps, fans, etc with a basic thermostat and these little PLCs can be found in the same price range as a basic Arduino.

SDMCF 11-17-15 12:56 AM


Originally Posted by TechShop (Post 47996)
these little PLCs can be found in the same price range as a basic Arduino.

Could you link to an example please?

Acuario 11-17-15 01:00 AM

2 Attachment(s)

Originally Posted by jeff5may (Post 47994)
The wish list of functions became so enormous that both ac_hacker and I could not reel in the diversity of devices that were built by many for their own specific sets of needs.

When I was searching for something already written I came across a couple of examples of this problem. Some had incredible lists of proposed functions only to then die quietly when the task of writing the code began. Breaking the code into distinct modules that encapsulate specific functionality is a great way to solve the problem - just include the bits you need and ignore the rest. Using this approach you could design/build a general purpose controller.


Originally Posted by jeff5may (Post 47994)
Ok, so your arduino is acting as an Ethernet to rs485 bridge and a humidity sensor? Are you still using an rtos or did you switch back to wiring/python/c? .

Absolutely still using the rtos as it makes the whole thing fit together as nice easy building blocks. Everything is written in c and using various Arduino libraries I found on the internet to run the core peripherals.


Originally Posted by jeff5may (Post 47994)
What else does it do? I'm very interested.

I have included a start up delay and power fail restart procedure. Basically it regularly saves the current time (as it has a real time clock) and in event of a power off/on (or power fail) delays the compressor start-up if necessary. It also restores the system to its last known operating state.

Using the web setup it allows the system to be remotely controlled, overriding the digital thermostat and setting the thermostats settings. Operating mode (heat/cool), on/off, desired temperature can all be set via the web page. With the correct settings in my router I can access this from anywhere making it an iot (internet of things) device.

Here are a couple of (not very pretty!) pictures, one of the whole controller mounted on a board and one of the oled status display. The only bit I needed to actually build was a small board (just visible at the bottom left) that acts as a break-out board for various connections. It has the balance resistors for the NTC thermistors, screw connectors for the ds18b20 temperature sensors, the pins for the dht22 humidity sensor and several rows of common pins for vcc, ground, I2C. The small red board with green terminals is a RS485 to serial converter, the rest of the bits should be easily identified.


Acuario 11-17-15 01:19 AM

1 Attachment(s)

Originally Posted by jeff5may (Post 47994)
It would be AWESOME if it could speak WiFi, Ethernet or USB with a more intelligent sand-based lifeform.

Adding Ethernet is really easy. Either use an Ethernet shield with a Wiznet W5100 or an ENC28J60 board. There is also a mini Ethernet board with a W5100 on it. I have another mini-project running that has 4 ntc thermistors on it using a nano. Originally I used the ENC board but I changed to a mini W5100 board as the ENC used quite a bit of program memory and (as usual!) I was running out of memory. This project also serves up a very basic web page with the temperatures of the 4 sensors.

You could add WiFi quite easily too. Check out the ESP8266 module which has built in WiFi plus lots more.


TechShop 11-17-15 02:04 AM

1 Attachment(s)

Originally Posted by Acuario (Post 47984)
Here are a couple of (not very pretty!) pictures, one of the whole controller mounted on a board and one of the oled status display.

Keep in mind your audience in a place like this. There's a special beauty in a pile of hardware assembled and functioning as it's creator intended. Either way, your bundle of jumpers and components approach seems familiar to me and similar to my prototype. :o

I presume the big 40 Amp SSR is meant for your compressor?

RJ-11 (telephone) jacks and plugs seem to be the ticket for the sensors. You can use inexpensive telephone wire for long sensor runs too.


Originally Posted by SDMCF (Post 47999)
Could you link to an example please?

12v - 24v (low voltage input and power version) Good for HVAC
Omron CPU Unit Zen 10C1DR D V2 | eBay

100v - 240v (line level input and power version)
Omron Zen 10C3AR A V2 Smart Relay AC100 240V | eBay

I have attached the manual for the ZEN here as well.

All times are GMT -5. The time now is 10:40 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Ad Management by RedTyger