Does any know how to override control automatic relay?

The neatest way is described in the “Overriding a Timer (auto/manual mode)” of this tutorial:

The relevant section says this:

Overriding a Timer (auto/manual mode)

It is possible to enable, disable and delete timers, and I’ll cover that in the next section, but in most situations it’s not necessary to do this.

Consider a situation where we are using one timer to take a reading from a temperature sensor every 5 seconds, then another timer which runs every 30 seconds and checks whether the temperature is below the target temperature and turns on a heater if it is, and off if it isn’t.

In addition, there is a manual override, which can be used to turn the heater on regardless of the temperature reading.

One approach to tackling this is to disable the 30 second timer when we are in manual mode, but the other is to leave the timer running all the time - but only execute the code in the temperature comparison function if we are in automatic mode.

That 30 second timed function to turn the heater on/off might look like this:

void control_heater()
{
  If(auto_mode == true)
  {
    // compare temperature and switch relay accordingly
  }
}

This code structure allows us to keep calling the control_heater() function with a timer, but only process the code within the function if our auto_mode variable is set to true. This variable would be switched between true and false elsewhere within our sketch.

Pete.

1 Like