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.

Please help.

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):

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)

Link to new Biomaker Handbook

That is pretty impressive… thanks!
But your mosfets are directly wired to your arduino (btw i can’t seem to find them in your code i just have an h bridge node).
I got a dc moto driver that uses a potentiometer and made the mistake of assuming i could simply take it out and plug in the arduiono as a controller instead but that does not seem to work. Now i am stuck. I either have to buy something like this:

Or just bypass all this nonsense and plug a stepper motor into this screw:

Not sure if this needs another topic but it just seems silly that i need 2 modules to turn a damn screw.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.