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.
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!
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?
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.
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..
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.
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 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.
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.
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
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
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.
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.
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.