24Views1Replies

Author Options:

Arduino code. Air-con temp controller. Please help if you can! Answered

The hardware is an R3 with a custom LDR interface for reading the mode of the air con, and relay interface for changing modes. There are 2 digital probes, one for temp control and the other just for display. This was made for climate control of a small room using a portable air-con.

The controller switches between 3 modes; Heat, Cool and Fan.

What we need is for it to turn the fan on when SP is reached. When starting from a power failure it will switch to fan mode if the temp is within the range of SP+-1. This makes it look like it's working correctly but after that it loops between hot and cold; the fan is never turned on again, although the readout on the controller reflects the temp is OK, so the fan mode should be activated.

I have attached the coding as well as a print out from the serial monitor showing the errors on the controller.

The guy who wrote this for me is unable to figure this out.

Would appreciate any help!

Discussions

0
None
Downunder35m

4 weeks ago

I might be able to give you some insight to address a few few of the hickups.
I assume you are not actually replacing the original controller in the aircon but just add jusr on top so to say.
If so then please reconsider using just your controller alone but to include the sensors from the aircon (or use your own).

First the basic and recommended operation:
When switched on the compressor should stay off, only the fan runs.
This is required so the temp sensors can get an accurate reading but most importantly to prevent the compressor to jump right back on after a power failure.
A delay of 5 minutes before normal operations start is minimum to allow a possible pressure differencial in the system to equalise.

General operation:
Based on selected mode the temps are checked and if outside SP range the corresponding mode and compressor will be activated.
From here it starts to get complicated with a self made controller....

Required checks, delays and readings:
The temp probes in a normal airconditioner are usually a pair.
One checks the incoming temp of the airstream, the other checks the temp of the cold side to detect possible freezing over.
Reverse cycle models often have sensors on the cold and hot side.
For a controller the problem is to actually detect the reality in the room AND inside the aircon.
You should include a part in your code that deals with room temps and aircon temps seperately!
For example: read the incoming airtemp to determine if the setpoint is reached or not.
Read the the temp on the outgoing cold side (when in cooling mode) to ensure it won't go below freezing point.
Once the cold temp gets close to freezing a shut off delay should start where only the fan works but not the compressor.
Same story for heating of course.
With this approach you seperate hardware functions from temp control functions for the user.
The aircon will use this safety net for example when you need to cool for a long time on a humid day ;)
To get the actual user part done:
In a second code set you only deal with just that!
Display shows the required values, user can select heating or cooling/fan and the desired temperature.
SELECT is the key here! You don't want any automatic mode changes at this stage!
Now for the really tricky parts...
Take cooling mode as an example here.
The Aircon is turned on, the fan runs for a few inutes and once that delay is off the set mode is checked and activated.
Your temp sensors will read the incoming and condeser temps, which might be the point where you courrently struggle.
Depending on where you read these temps they can go literally nuts.
In the direct airstream you might need to compensate the temp reading if the sensor is cooled down too much.
Let's say the room temp is 27°C but the sensor starts reading only 25° once the fan runs.
Here you would just use 2° as the compensation value.
With the seperated temp controls from before your code now only needs to switch the functions off once SP is reached and turn them back on once the temp is too different.
You need a delay here!
For example when the temp reached SP you want to keep all active for a minute or so longer to check if the temp is still going down - if not the mode keep active.
If the temp still goes down below SP the actual shut off is like a fridge with 1-3° hysteresis.
Otherwise your aircon would try to cycle on an off far to quickly.
Keep in mind you deal with compressed gas and a heat pump here, it is not like switching lights on and off ;)
Also keep in mind that OFF in heating or cooling mode only means the compressor, the FAN MUST stay ON for at least the time required to equalise the pressure in the system!
But in heating or cooling mode a fan is usuallly kept on anyway...

Automatic modes...
Once you have the cooling mode sorted out to do it properly it is quite similar in terms of the changes for the heating mode.
Only difference is that you monitor the cold side for freezing and have the SP operation reversed so to say.
It is then of course really tempting to fully automate this.
Set a temp and forget about anything, it heats when it gets cold and it cools when it is hot.
Problem here is that you really need to get your delay right!
The 3° hystersis for the individual mode would mean you constantly jump between heating and cooling if you don't add additional delays for the automatic mode.
The room temp should be monitored in 1 or 2 minute intervals to detect change.
The automatic SP temp is only used as a reference point.
What you want is a little logic that tracks the room temp and decides when it is time to activate more than just the fan.
For example:
Starting with a cold night followed by a hot day...
Aircon is turnedon before you went to bed and after about 10 minutes it realises the temp stays too cold and might even drop further.
That means it has to activate the heating mode.
Once SP is reached the normal mode delays are active as in manual operation but additionally you check if the temp keeps rising, is steady or drops down again.
Dropping down again means the heating mode stays active.
You can set this check to be done after every 5 to 10 cycles of the compressor.
At some stage the controller will realise the sun is out as the time to fall back to SP increases.
From here on the SP check for the automatic mode should be done after every compressor cycle.
Once it is decided the temp is steady only fan stays active and another delay is activated, preferably in the range of 15-20 minutes.
The measured temp will slowly creep over the SP with the sun out and the aircon should switch to cooling.
However, it makes no sense to do for a minor rise.
Only once the detected temp kept rising either too quickly (sun in the window) or above the delay hystersis the cooling mode should be activated.
From there cooling mode stays active with the same parameter definations as for heating, just again in reverse so to say.

Protections to consider...
The compressor does not like being turned on when the system has a pressure differencial between cold and hot side.
And it certainly won't like being switched between cooling and heating without the condenser temps being back to room temp first.
The added delay whenever the controller is powered up is part of the same "master control" that should be used on top of all operations.
Ok, sounds complex, so let's break it down a bit...
The master control is just a set of fixed delays for the compressor with the added check of the condenser temperatures.
Once the delay is over a variable that needs to be true for all following operations is set to indicated all is good to go.
So no matter the selected mode or power state, without this variable set the compressor will never turn on when the controller is activated.
Same for the cycle check.
A mode change between heating and cooling will only activate the compressor once the set varible that states the required delay has passed it set true.
With all those in place there won't be any unwanted and harmful cycling between heating and cooling.
These compressors need a certain time to get the system to working temperatures.
The cool outgoing airstream will stabilise to a temp of about 10° under room temp.
The time required for this should be set as the minimum time the compressor needs to stay activated even if the SP check says it would be fine to shut off again.
A similar delay should be considered for the basic heating and cooling operation as an addition.
For example you don't want the compressor to only stay on for as long as it takes to get to normal operating temps, you NEED to keep it on longer to have any effect on the room temperatur and to not waste energy.

If you start the approach from a modular point of view with the delays and protections standing over all normal operations the coding can get surprisingly simple ;)
The benefit of this approach is of course that once established and working you can modify the temp control sections and cycle control without having to warooy that you mess something up.
Should be relatively easy then to optimise your parameters to best suit the aircon capabilities.
Could even end up to be more efficient than any original controller ;)