Home Thermostat is under review at this time, will re post it soon.
You should take a look at this article:
Adopting this coding approach will give you a system thatâs much more stable and reliable in the long term.
Pete.
very nice project.
I think your loop() function is fine, it is using millis to ensure that things run only when needed. The CPU does not care if the instructions are generated by code within the loop or in functions called by the loop, so it all comes down to how well the code is structured, and you have structured it fine. timer would essentially do what you are already doing.
I would have expected all commercial thermostats to have a DZ. I am surprised to read that they donât!
Did you check the accuracy of the temperature readings you are getting? I am testing a temperature monitoring system using TMP36 and I am finding the readings rather inaccurate, but then the other three thermometers I am comparing it to are also all over the place!
Code under review, will re post soon
In that case, I think weâll have to agree to disagree as I stand by my comments 100%
Pete.
Iâm surprised there is no flood with this loop
Very nice project!!.. Clean looking as well. And I like the detailed info in your topic.
As usual, there is many ways to write code⌠and wire electrical⌠but generally there is only a few âapprovedâ ways or regional wiring âcodesâ.
With Blynk, using the timers like BlynkTimer (version of SimpleTimer) is the approved way primarily to keep things simple and functional for all users to understand and follow along when we teach them how to Blynk.
Often timers can be easier for some to understand than all the millis math. That is why people build these timer libraries in the first place It also avoids the âtraditionalâ âFill yer void loop()
with everythingâ concept of old, which can have dire consequences for new users with Blynk and other IoT applications where constant communication links are required.
You code seems well laid out for a self proclaimed âprogramming noobâ and if it works, great⌠but I would, as have others, recommend you look at how BlynkTimer works, as it might change how you code further projects.
Now I am going to go twist all the unused white and black wires in my electrical panels together since someone told me the recommendations donât apply and doing so will stop the unused electricity from dribbling awayâŚ
(In our youth, I had my sister convinced that static electricity came from unused electrical outlets spilling power onto the carpets )
Code under review, will re post it soon
Oh, not saying to not use millis()
, there are times you need to compare time, and timers, while great at countdowns, repetitions, or repetitions within specific counts, etc. They are not necessarily meant for clock related comparisons. The right tool for the job and all that
But glad to introduce you to the world of BlynkTimer. I have many strange uses of it here - C++ Blynk - Code Examples for Basic Tasks (Work in Progress)
The problem I have with the void loop is thisâŚ
A well written void loop should execute hundreds of times per second. It wonât do that if there are too many steps to execute, so the void loop slows down. In your loop, the following has to happen each time it runs:
-
Blynk.run executes (100% essential)
-
Blynk timer executes (not used, so a waste of processor time)
-
Update_Time function runs, this does the following:
- Evaluates a millis comparison and executes once per 24 hours
-
Heater_ON_OFF function runs, this does the following:
- Reads the value of a digital pin and assigns the result to a global variable
- Compares the result to the previous value for that pin
-
Cooling_ON_OFF function runs, this does the following:
- Reads the value of a digital pin and assigns the result to a global variable
- Compares the result to the previous value for that pin
-
Fan_ON_OFF function runs, this does the following:
- Reads the value of a digital pin and assigns the result to a global variable
- Compares the result to the previous value for that pin
-
Performs an if comparison with millis and 2 global variables
-
Performs an if comparison with millis, one global variable and one static value
-
Performs an if comparison with millis, one global variable and one static value
-
Performs an if comparison with millis, one global variable and one static value
This is the minimum that happens for each void loop cycle, assuming that all of the if statements evaluate to false (which the will most of the time).
There are 3 digital pin reads per void loop cycle, which would probably be better handled using interrupts, and a lot of if comparisons against the current millis values.
One instance of the Blynk timer function would handle all of these timer comparisons automatically, and simplify the code dramatically, whilst allowing the void loop to execute use much more quickly.
If you donât want to use Blynk timer then you should certainly remove the timer declaration and the timer.run from the void loop, as these are just taking-up memory and processor time.
Pete.
code under review , will re post soon
Thank you, Gunner, for the link. You have some good codes examples there. Of course, I will study them, etc. I like the Simple AC Power Monitor Using ACS712.
Love your work on this! Just one question, where are you getting the 12VDC from?
Code pictures under review, will re post soon
Got it thanks. I am still search for an elegant way to take power from the 24VAC and use that to power the thermostat. Even in situations where continuous 24VAC is present (typically orange wire) you could still use the 24VAC to keep a small Li-ion battery charged.
24v ac to 5 volt dc. use it to power the charger and use the charger and battery to power the esp.
I am using these and they are not expensive but you need house current.