Central heating controller sketch question

Hi all :slight_smile:

I'm going to try and build a central heating controller, but am struggling with a couple of concepts. It branches out a bit more from the 'do more than one thing at once' classic question - I have read this, but think it's a little different. I'm a newbie, please don't be too harsh on me!

The central heating controller is quite simple - all it involves is closing a circuit to heat, and opening the circuit again when the room reaches the desired temp. I have absolutely no problem writing the sketch to monitor the temp and switch on/off the system to control the temp. I don't even really need to worry about building a variable in there I can set as we only ever have it on one temp.

I would really like to build in a few extra functions, that the controller doesn't have, namely
-a timer
-SMS/ethernet control capability

I'm fine with the hardware aspect of these features, but what really confuses me is knowing how to write the code so if for example, the timer code monitors and determines a criteria is met, how do I get that to 'kick off' the 'core' element of the sketch (i.e. switch on the system, and have it controlled by the thermostat)? Also, when I add the GSM capability, how would I get an SMS 'command' to override the timer, and switch on/off the system when the timer code says to do otherwise?

Again, I am more than capable of teaching myself how to code to receive SMS commands etc, the issue I'm having is I don't have enough programming experience to know how to 'structure' something like this - all the coding I've ever done is procedural.

I don't expect complete answers, but if someone could tell me what I would search for/read about to learn how to do this, it would be a massive helping hand. I don't really know what to search for, or more importantly, how to logically design the code.

Any pointers would be greatly appreciated!

boolean Timer_OK = false;
boolean SMS_OK = false;
boolean Temp_LOW = false;


loop()
{
   CheckTimer();
   CheckSMS();
   CheckTemp();
  if(Timer_OK && SMS_OK && Temp_LOW)
  {
       turn on switch
  }
  else
  {
     if switch on, turn it off
  }   
}

CheckTimer();
{
    //check timer setting and set Timer_OK to true if OK to run, otherwise false
}

CheckSMS();
{
     // Check SMS status and set SMS_OK if OK to run, otherwise false
}

CheckTemp();
{
    // Check temp and set Temp_LOW to true if it is too low,  otherwise false
}

Get a pencil and paper.
Write down, stepwise, what you want the controller to do.
Probably there will be several IFs, ANDs and ORs in there, as well as many crossings/rubbings out. :slight_smile:
This will be the starting point for your program.
Get one part working before trying to add the next part.
If you can't get something to work, post your code here and we'll check it out for you.

Functions are your friend here, as they only run when you tell them to. You can have a bit of code in your main loop determining if it's getting SMS or timer signals, and fire a function based on that.

Don't forget some hysteresis to avoid rapid cycling of your heating system.

Just start out with the simplest system you can and add the rest of your functionality gradually. Lemming's example shows one way this could be done.

You need a bit more definition around how the various triggers interact e.g. when you've received an SMS message to turn the heat on, what happens when you get to the next scheduled turn off controlled by the timer?