Hi, I'm working on cooling/heating automation. I already have working Arduino with esp8266 as WiFi shield. I'm reading dht22 sensor and analog thermistor sensor on blynk app. This will work as temperature controller. I want my project to turn on heating and keep temperature stable for several hours at settable temp. I'm working now on programming this part, but I have problem, because I don't know how to implement timer. I would like to use blynk software RTC. I would set the time of heating (for example for 4 hours), but I want Arduino to check real time when I press start, and then add that 4 hours, this time will be available in virtual pin, I want Arduino to calculate real time on start + 4 hours and run case1 loop for that time. Then, when time is over, it switches to other case(2), which will cool the space and keep temperature low for undefined time. I could do this without soft RTC, even easier, but I want to have fail-safe, so heating won't be too long - heating stops at calculated real time. (loop checks time every time, if it is still in that time, it run again, if not, it runs case 2.
Sorry for my mistakes, hope You can understand. Thanks in advance!
Lenart
read blink without delay to study about times.
You can try to use the Arduino internal time keeping.
We know it can be off for a each day.
When you say 4 hours, how critical is that ?
You should be able to get your project running with the internal clock,
Then add the time from an external clock to get more precise time.
most programming is done in steps or stages to get one bit working, then add the next.
blink without delay is the foundation.
one way could be :
you would turn on and set a timer.
get the 'actual' time, note the difference
then use the internal timer
re-set the internal by the actual time
as you get close, you can re-set again
allow for the difference in the second step so your 4 hours is 4 hours from start, not 4 hrs from setting the time.
if you break this down, blink without delay does the timing.
you only use your external time as a way of calibrating local time.
I am sure there are other ways, but you can use blink without delay to work out your sketch, then just refine the accuracy when needed.
What's the role of the Arduino in this? The ESP8266 is more than capable of such a simple job.
Time: just get that from the Internet over NTP. The ESP even has some kind of RTC built in.
Hi,
You are doing something that is a little complex. Code can get out of control (speaking from experience)..
Here's an example that might help thinking about organizing your code:
https://arduinoinfo.mywikis.net/wiki/YourDuinoStarter_AutomationExample
Just tossing in, you should consider once you get your target time, save that time to eeprom so if there is a power fluctuation your arduino will still try to keep to the schedule.
So your loop would be
Check for input and if so, write to eeprom time and cycle to run until.
(If your using RTC even better to write to its memory.)
Read the eeprom for time to run until and wether heat or cool.
Set output variables according to current time and what’s stored in eeprom
Read current temperature and set output variables based on setpoints.
Process variables and output.
Loop
Thanks everyone for help. It will get in good use
Long time has passed while I finally had time to continue this project.
So now I managed to add RTC from server to the Arduino. I think it would be the easiest way and least resource consumptive, if I calculated time from RTC + timer set. When this time on RTC is achieved, it sets virtual pin to 1. Is this good approach or should I do it other way?
Timer should start when V5 (virtual pin) is high.
Thank you in advance!