You can find on github
That gives you possibility to drive multiple devices in order to control temperature. In my case I have installed two fans on my attic in order to cool it down in summer. There are no windows, so I had to force airflow. First fan gets started when temperature reaches 30 degrees, second over 35.
You can control any reasonable amount of units, it's all configurable. You have also access to basic statistics:
|Runtime of whole system|
|ON time for each relay|
|Statistics for 14 days|
|Statistics for 7th day|
ConfigurationWhole configuration is stored in Config.h. You can change PINs controlling relays, reading temperature, thresholds or timings.
Let's assume that we would like to have 3 relays:
You have to edit Config.h and configure PINs, thresholds and amount of relays. Obviously some properties already exists, so you have to just edit them.
Now we have to setup relays and controller, this happens in RelayDriver.cpp
It's the one chosen in example above, it has few additional configurations:
RELAY_DELAY_AFTER_SWITCH_MS gives wait time for switching next relay. Imagine that configuration from our example would start working in 40 degrees environment. This would result in enabling of all three relays at the same time. This could eventually lead to high power consumption - depending on what you are controlling, electric engine for example consumes more power during start. In our case switching relays has following flow: first relay goes, wait 5 minutes, second goes on, wait 5 minutes, third goes on.
RHC_RELAY_MIN_SWITCH_MS defines hysteresis, it's the minimum frequency for particular relay to change it's state. Once its on, it will remain on for alt least this period of time, ignoring temperature changes. This is quiet useful it you are controlling electric motors, since each switch has negative impact on live time.
This is advanced topic. Implementing such controller is simple task, finding right amplitude settings is a different story.
In order to use PID controller you have to change initRelayHysteresisController(.....) to initRelayPiDController(....) and you need to find right settings for it. As usual you will find them in Config.h
I've implemented simple simulator in Java, so that it's possible to visualize the results. It can be found in folder: pidsimulator.
Below you can see simulations for two controllers PID a P. PID is not perfectly stable because I did not apply any sophisticated algorithm to find right values.
Different software modules have to communicate with each other, hopefully not both ways ;)
- statistics module has to know when particular relay goes on and off,
- pressing a button has to change display content and it also has to suspend services that would consume many CPU cycles, for example temperature reading from sensor,
- after some time temperature reading has to be renewed,
- and so on....
Every module is connected to Message Bus and can register for particular events, and can produce any events.
For example pressing Next button results in following flow:
Some components have some tasks than needs to be executed periodically. We could call their corresponding methods from main loop, since we have Message Bus it's only necessary to propagate right event:
Following libs are required to compile Thermostat: