Looking for ultra simple method of scheduling heating

Hi, I am looking for the most simple method of controling heating in my house. At the moment i have control over my heating, (i can turn it off and on manually with arduino)

What i want to do now, is to be able to set a 1 day schedule for my heating. ie Turn zone 1 on at 8am and zone 2 off. and then turn zone 1 off at 10pm and zone 2 on at say 8pm.

Currently i dont want thermostatic control over the heaters, as this is already built into the heaters, so for this stage i am happy to leave it like that.

I have seen examples of control using google calendar etc, and that might be a future step, but just for now i want to turn it off and on as above.

What simple options are available to me? just hook up realtime clock and control from there? or is there something even more simple than that.

Please, if you are reading this and have seen a project that you can link me to that would be great, or even just drop a small comment, no matter how simple.

Thanks in advance :smiley:

Write a simple clock program. Easy to do.

void loop(){
currentMillis = millis();  // all time related variables are unsigned long
elapsedMillis = currentMillis - previousMillis; 
if (elapsedMillis >=oneHour){  // oneHour = 1000mS/Sec * 60 Sev/min * 60 min/Hr = 3600000UL
hours = hours +1;
if (hours == 24){hours = 0;} // reset after 24 hrs
if (hours == 8){ // morning change over
// switch stuff
}
if (hours == 22){ // evening changeover
// switch stuff
}

} // end one Hour check

} // end loop

fill in the variable declarations, pinModes, etc.
Press Reset at midnight to sync it up. Or set hours to some known time, say 8, at 8AM, & restart the code then.

Thanks, that should get me up and running, just want to plug the hole in my electric bill caused by kids leaving heating on and doors open all day. and then i can start to make it smart!

Much appreciated.
Kudos!

Hey "Crossroads" or anyone else who can help a noob... I have to admit that i am struggling to get the code working for this. Coding is really not my thing, any chance you could help me a little more with the declarations at the start.. I really am new to c-programing, and i cant find any directly comparable examples elsewhere..

How do i handle "oneHour" do i need to include a library?

Thanks in advance.

unsigned long currentMillis;
unsigned long elapsedMillis;
unsigned long previousMillis
unsigned long oneHour = 3600000UL; // 1000 * 60 & 60
byte hours = 8; // assumes Reset occurs at 8AM to start the program.

no Libraries needed.

Ok, i wasn't too far off with my attempt at getting that right.... So i've gotten to this point.. well.. you've gotten me to this point.. Thanks again.

unsigned long currentMillis;
unsigned long elapsedMillis;
unsigned long previousMillis;
// ^^  I guess just declare that they will be used?
unsigned long oneHour = 3600000UL; // 1000 * 60 & 60  define 1 hour
byte hours = 0; // hours = 8; would assume Reset occurs at 8AM to start the program. will use in next phase

void setup() {

pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}
void loop(){

currentMillis = millis();  //  all time related variables are unsigned long  ???should this be here??? or just declared above 
elapsedMillis = currentMillis - previousMillis; // defining elapsed millis
if (elapsedMillis >=oneHour){  // oneHour = 1000mS/Sec * 60 Sec/min * 60 min/Hr = 3600000UL
hours = hours +1;  // tick over into the next hour
if (hours == 24){hours = 0;} // reset after 24 hrs
if (hours == 1){ // morning change over
digitalWrite(6, HIGH); // set the LED  on
digitalWrite(7, LOW); // set the LED off
// switch stuff on or off
}
if (hours == 4){ // evening changeover
digitalWrite(6, LOW); // set the LED off
digitalWrite(7, HIGH); // set the LED on
// switch stuff
}

} // end one Hour check  ? should this be here?


} // end loop

So.. i ran this on two led's connected to 6 and 7, to trigger as listed, so i expected 6 to be on and 7 off after 1 hour, and then after another 3 hours, the other way round. but instead it waits for the hour, and then i have both led's on all the time..

Can anyone point me in the right direction

Yes, the stuff questioned should be there.
// ^^ I guess just declare that they will be used?
Yes, can set to 0 if you want, but not needed.

currentMillis = millis(); // all time related variables are unsigned long ???should this be here??? or just declared above
Yes, this is capturing the "time" at the star of loop.

} // end one Hour check ? should this be here?
Yes - use CTRL-T to format the code, you will the changes only occur inside the 1 hour check:

unsigned long currentMillis;
unsigned long elapsedMillis;
unsigned long previousMillis;
// ^^  I guess just declare that they will be used?
unsigned long oneHour = 3600000UL; // 1000 * 60 & 60  define 1 hour
byte hours = 0; // hours = 8; would assume Reset occurs at 8AM to start the program. will use in next phase

void setup() {

  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
}
void loop(){

  currentMillis = millis();  //  all time related variables are unsigned long  ???should this be here??? or just declared above 
  elapsedMillis = currentMillis - previousMillis; // defining elapsed millis
  if (elapsedMillis >=oneHour){  // oneHour = 1000mS/Sec * 60 Sec/min * 60 min/Hr = 3600000UL
    hours = hours +1;  // tick over into the next hour
    if (hours == 24){
      hours = 0;
    } // reset after 24 hrs
    if (hours == 1){ // morning change over
      digitalWrite(6, HIGH); // set the LED  on
      digitalWrite(7, LOW); // set the LED off
      // switch stuff on or off
    }
    if (hours == 4){ // evening changeover
      digitalWrite(6, LOW); // set the LED off
      digitalWrite(7, HIGH); // set the LED on
      // switch stuff
    }

  } // end one Hour check  ? should this be here?


} // end loop

Any chance you have the LEDs miswired?

I don't understand why the digitalWrite LOW did not take effect. That is pretty standard.

ok, I checked the led's, and they are correctly wired, i changed the code a little on the hunch that they led's arent turning on at the same time, but flashing with every loop.. and so i added delay 1000 after each instruction, and it is like this, after 1 hour, the arduino starts cycling through the different states.

i am trying to figure out the logic here, it seems maybe the section

if (elapsedMillis >=oneHour)// oneHour = 1000mS/Sec * 60 Sec/min * 60 min/Hr = 3600000UL
  {  
    hours = hours +1;  // tick over into the next hour

is perhaps missing some kind of reset? so up until 1 hour(0-1), the logic above is not tripped, but for (1-24) hours, millis is always greater than oneHour.. so the statement is always true, and then it repeats 4 times until the second if statement becomes true, and then we have the condition that i am seeing now... both statements are true..

This is my theory, but i am not sure if i know how to put it right.. maybe the intention is to reset millis after every cycle?

i will try, but please any help will be appreciated.

Regards Gambit

Ah - missing a line!

currentMillis = millis();  //  all time related variables are unsigned long  ???should this be here??? or just declared above 
  elapsedMillis = currentMillis - previousMillis; // defining elapsed millis
  if (elapsedMillis >=oneHour){  // oneHour = 1000mS/Sec * 60 Sec/min * 60 min/Hr = 3600000UL
    previousMillis = previousMillis + oneHour; // set up next interval to look for  <<<<<<<<<<<<<
    hours = hours +1;  // tick over into the next hour

Sorry about that - hazard of typing stuff up without seeing it running

Thanks again, and no apology needed, i think i am learning more like this :smiley: i will give this a try now. i've been waiting an hour for each test, as i think this is the minimum time my logic can deal with.

Sorry to say, but still something not working... now the led's just turn on immediately. :confused:

Shorten the 3600000 by a zero or two to speed up testing, then reset it for actual use when things are working as intended. Or change to say 10000 for 10 second changes.

Post your current code. This shouldn't be that complicated.

unsigned long currentMillis;
unsigned long elapsedMillis;
unsigned long previousMillis;
// ^^  I guess just declare that they will be used
unsigned long oneHour = 3600000UL; // 1000 * 60 & 60  define 1 hour
byte hours = 0; // hours = 8; would assume Reset occurs at 8AM to start the program. will use in next phase

void setup() 
{
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
}
void loop()
{

  currentMillis = millis();  //  all time related variables are unsigned long  ???should this be here??? or just declared above 
  elapsedMillis = currentMillis - previousMillis; // defining elapsed millis
  if (elapsedMillis >=oneHour)// oneHour = 1000mS/Sec * 60 Sec/min * 60 min/Hr = 3600000UL
  previousMillis = previousMillis + oneHour; // set up next interval to look for  <<<<<<<<<<<<<
  {  
    hours = hours +1;  // tick over into the next hour
    if (hours == 24)
    {
      hours = 0;
    } // reset after 24 hrs
    if (hours == 1)// morning change over
    { 
      digitalWrite(6, HIGH); // set the LED  on
      digitalWrite(7, LOW); // set the LED off
      // switch stuff on or off
    }
    if (hours == 4) // evening changeover
    {
      digitalWrite(6, LOW); // set the LED off
      digitalWrite(7, HIGH); // set the LED on
      // switch stuff
    }

  } // end oneHour check 


} // end loop

Perhaps the new line should be as a secondary condition of the first if statement? just a noob guess…

You got a little carried away with cut & paste it looks like.
Should be like this:

unsigned long currentMillis;
unsigned long elapsedMillis;
unsigned long previousMillis;
// ^^ I guess just declare that they will be used
unsigned long oneHour = 3600000UL; // 1000 * 60 & 60 define 1 hour
byte hours = 0; // hours = 8; would assume Reset occurs at 8AM to start the program. will use in next phase

void setup() 
{
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}
void loop()
{

currentMillis = millis(); // all time related variables are unsigned long 
elapsedMillis = currentMillis - previousMillis; // defining elapsed millis
if (elapsedMillis >=oneHour)// oneHour = 1000mS/Sec * 60 Sec/min * 60 min/Hr = 3600000UL

{
previousMillis = previousMillis + oneHour; // set up next interval to look for
hours = hours +1; // tick over into the next hour
if (hours == 24)
{
hours = 0;
} // reset after 24 hrs
if (hours == 1)// morning change over
{ 
digitalWrite(6, HIGH); // set the LED on
digitalWrite(7, LOW); // set the LED off
// switch stuff on or off
}
if (hours == 4) // evening changeover
{
digitalWrite(6, LOW); // set the LED off
digitalWrite(7, HIGH); // set the LED on
// switch stuff
}

} // end oneHour check 


} // end loop

Use CTRL-T to fix the formatting again.

:blush: yes, pasted it first time without the additional line, and then hadn't copied correctly so ended up repasting the whole thing inside itself. So far seems to be working. My Relay board should arrive tomorrow, so i will report back with the finished article :smiley:

Thanks again. Really appreciate this help on my first project.

My mind is boggling with the possibilities that i can imagine for future arduino use.

Regards

Gambituk

Okay, looking forward to more results.

Looks like you’re in capable hands and well on your way. But in case you are interested, there’s a library that I would call simple from the aspect of managing/specifying your schedule. However it means adding a library and consuming memory on your Arduino, so that may violate your meaning of simple.

This implements a Unix-style cron scheduler.

Well i will look at that too. This is really just a proof of concept for me at this stage, the quickest and simplest route for getting this system up. I haven't worked with libraries yet, so i will definitely look at this and try it out on my board too. I will try any suggestions posted here, and hopefully put it all together later and evaluate it all from my perspective so that anyone else can try it or use it too.

After first glance i see that it uses the rtc chip too, so i could definitely see this as a next step.

Thanks!

Gambit

I would have used a RTC like DS1307. And then google on "Arduino DS1307 alarm clock" and you will find Alarm Clock using Arduino, DS1307, buzzer, and LCD

That will give you a flying start I think...