Climate controller for air-conditioner - coding issue.

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 on the air-con; Heat, Cool and Fan.

What I 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 PDF print out from the serial monitor showing that the fan does not switch on at SP and the loop between heat & cool.

Would appreciate any help.

SerialDataSP25.pdf (59.4 KB)

AirConControl.ino (15.5 KB)

I started to look at it. Then I saw a goto and gave up. Your functions are really long too.

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.

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

Thanks… Tom… :slight_smile:

Hi Tom

Thanks for the effort. Apologies for incorrect posting.

I haven't been able to get the circuit.

I am certain it is a coding issue. It works perfectly to keep the temperature within the range of SP+-1. It heats if temp is too cool and cools if temp too hot. It repeats this cycle, which means the air con works twice as much as is required.

So at SP+1 it cools till SP-1, then heats till SP+1, then cools till SP-1 etc...

All I want changed is that when SP is reached, the fan is turned on.

All other functioning is perfect.

And when powered up after power failure, if the temp is in the zone so SP+-1; it does turn the fan on. But after that it reverts to the heating & cooling, the fan is never turned on again.

So the turning on of the fan is not in the loop, only in the start up. I need it in the main loop.

My code is too long to be posted here;

The message exceeds the maximum allowed length (9000 characters).

Hi,
Post your .ino file as an attachment.

Tom... :slight_smile:

Thanks Tom, herewith attached…

AirConControl.ino (15.5 KB)

It looks like you loop forever between MAINLOOP and the goto. This is a really bad idea.

Maybe this will help..

In your programming envoroment, you are given setup(); called once, and loop(); called a lot.

The part you don't see, outside of all this looks kinda' like..

main() {

setup(); // Your setup call.
while(true) {
doInternal things(); // Things the processor needs to do.
loop(); // Your loop call.
}

You keep looping internally and you have no idea what internal things you are blocking that need to happen. I know its a fundamental change in your thinking, but like you already saw; as soon as people see a goto, they tend to move on to help someone else.

-jim lee

Thanks jimLee.

I think I understand what you mean but don't know how to change it..

Are you the original author of this code or did you find/inherit it?

-jim lee

I inherited it. it's beyond my level.