Constant Temperature Control - Compensate Outside Temperature

I want to keep a constant temperature in a terrarium to mitigate the day night drop.

But I have no idea how to approach it. I was thinking of:
If temperature is above x then drop voltage by small increment, wait 15 min, repeat and the opposite if the temperature is too low. Plus some way to set limits so that It does not fry the system should some day it get crazy cold outside.

What are you using to heat the terrarium? How are you planning to control voltage?

Not sure what you mean by limit to keep from frying the systemâŚIs there a limit to how long your heater can run at full heat? I would suggest that in addition to dropping in increments above set temp, that you turn heater off completely if it gets above a higher set temp (in case you are not dropping voltage fast enough). You could do the same to turn heater on full if temp gets below a certain point.

You should probably also quit raising the voltage if temp is already climbingâŚthings are going in the right direction, but it might take time to get up to your set temp & you probably donât want max heat all the time.

There is not much sense in getting much code done before you have very explicit/specific requirements specified, but you will need to keep track of the current voltage setting (and maybe previous temp setting), so you will need to use âbufferâ nodes to store those values.

1 Like

Through a dc motor driver like this (not as powerful):

https://www.amazon.com/MELIFE-Controller-10-50V-Driver-Extension/dp/B08PK6G7B2/ref=sr_1_15?keywords=dc+motor+driver&qid=1693827065&sr=8-15

and that drives an infrared led.

I used to have a simple temp on off relay but the constant clicking is annoying. I would like some smoothness and more control.

So yes the buffer nodeâŚ something like this but automated:

I dropped some nodes and tried to think of something beyond that but I am drawing a complete blank:

1 Like

Formatting hint: Your defer & add nodes line up, making it very difficult to see where wires are actually connected. Moving âdeferâ up & to the right one position might make things a little more clear.

This look pretty good, except for the fact that âbufferâ only updates when Temp changes to more than 30 or less than 30. It doesnât continue to change each time Temp is checked. (âselectâ only gets a pulse when one of the conditions changes to true)

I think you said you wanted to check the temp every 15 minutes (900 seconds). I assume that is what the âdelayâ node is for. You COULD use delay (have DONE trigger SET to keep repeating), but âclockâ would be a better option. Set clock-IVAL=900, then feed clock-tick to Temp-UPD to check Temp every 15 minutes. Now delete the link between buffer-UPD and âselectâ and link Temp-DONE to buffer-UPD and buffer will update every 15 minutes. Just to be safe, you might want to put a âdeferâ before buffer-UPD. This is a direct link from Temp to buffer, and the values you want to use pass through conditional & select nodes. Adding defer will make sure those values get updated before you update buffer.

A slight âbugâ with what you end up with: when Temp is equal to 30, you will continue to adjust the power in whatever direction you were going, but it would probably be better to keep the same power level. Since Temp is a floating point number, it will almost never be exactly 30, so this is a very minor issue.

Looking closer, I think you need to switch your âgreaterâ and âlessâ nodes. You want to add power when temp is <30, not when temp is >30.

You can add fail-safe checks by expanding your select. If Temp>40, set power to 0. If Temp <20, set power to 1.

Just noticed another bug: there is nothing to keep buffer from going below zero of over 1. You can add if-else between âaddâ and âselectâ to output 1 if add output is >1 and between âsubtractâ and âselectâ to return 0 if subtract output is <0
For example:

The down-side of this solution is that you will always be over-shooting the target temperature. A better option might be to set power based on how far we are from target temperature. For example, if you want to stay within 5 degrees of 30, you can calculate 30-Temp, then map [-5âŚ5] to [0.0âŚ1.0] using âmap-clipâ. Now you donât need to wait 15 minutes to check temp & you can get smoother power transitions and steadier temperature. If you want to improve performance even more, you can factor in âoutsideâ temperature (outside of the terrariumâif it is in the house, this might be a non-issue).

You might find that this results in temp always holding steady just above or below target temp, so adjustments might be neededâit is assuming 50% power is needed at set temp, which may well be wrong. You might also find power ramps up/down too fast, in which case easiest solution is probably to expand the Smin/Smax. Using [-10âŚ10] will change power setting half as fast.

1 Like

Hi - it might be worth looking at the xod/core/pid-controller (proportionalâintegralâderivative controller) node in XOD. It computes a fuzzy output value based on a current input value and the target value. It is designed for maintaining a precise target with on-off inputs - sounds like your heater problem?

I used it for a precisely controlled heater for biochemical reactions. The PID values need to be tuned for best performance - so it would be worth setting up a temperature logger to map performance - this is also relatively easy in XOD. The project was documented in our recently updated Biomaker handbook for Rapid Prototyping - relevant extract is attached - and the original is at the website below. Itâs part of a free, open source project based in Cambridge. The full handbook also has information about interfacing temperature sensors, etc.

There is a lot of background information about PID controllers available online - they are widely used in industrial control.

AirFlowReactor.pdf (2.8 MB)