søndag den 19. juni 2016

The Logic Behind my Temperature and Humidity Control

Hello again.

Well no matter how good the intentions are, reality has its way of kicking in, and I never got around to do an “as we go” blog on the build. Now a year, and some, later, the build is done.

Figure 1 and 2

I ended up adding a load cell as well. This will allow me to log changes in weight, humidity and temperature, for easy comparison and trouble shooting. 

In this blog I want to go a little further into how I control the environment inside the curing chamber.

For controlling the temperature, the cooling circuit of the fridge was connected to one of the relays. Also, an incandescent lightning bulb was painted black, hooked up with a relay, and hung inside the fridge, for heating. The control scheme used, is simple hysteresis control. See figure 3 below.

Figure 3 The basic temperature and humidity control scheme

Using temperature as an example; If the chamber is situated in a cold room and the chamber temperature drops below the minimum setting the heater will turn on, and keep running until the temperature goes above the set point. Alternately if the ambient temperature is high, causing the chamber temperature to rise above the Max level, then the cooler will turn on and keep running until the temperature falls below the set point.
This solution was chosen due to its simplicity, and because it quite easy to implement in the code as well.

To define the different parameter boundaries, I have set the bands for the controller illustrated in figure 3, with the blue circles. These are used in the code itself, as well as to ease communication here.

For humidification, a small desktop USB humidifier was installed in the fridge. For this small space the capacity of this humidifier is plenty big. So as shown with the temperature, the humidity spectrum was also divided into four bands, centred on the set point. For the humidifier the control logic was as simple as for the heater, shown in the previous example. It would turn on, when the current humidity crosses from band 1 into band 0, and turn off again when crossing from band 1 to band 2. The rest of the time, it is off.

Since the fridge available to me wasn’t very roomy, I didn’t want to cramp it any further, by adding a huge dehumidifier in there. I had earlier tried to dehumidify by adding a fan, for circulating outside air through the chamber, but for most of the year, this actually worsened the humidity. So another method had to be applied.

During the tests of the chamber we had observed that condensation on the cooling element, made the humidity drop drastically during cooling. So this gave an obvious way to keep the humidity in the chamber down. But since this now made the dehumidification controller intertwine with the temperature control, close mind had to be paid.

So what I did was to add two humidity dependent conditions to the logic of the heater controller.
The conditions are quite simple. If the current humidity is above humidity band 2 and the current temperature is within temperature bands 0, 1 or 2, the heater turns on. This will drive the temperature up into temperature band 3. Here the cooler will engage, and stay engaged until the temperature falls below band 2. This fall in temperature will happen slower than usual due to the fact that the heating element is turned on as well. I have tried to illustrate the scheme in figure 4.

Figure 4 This Temperature control scheme will run, as long as the current humidity is above humidity band 2.

Since the heating element now forces the cooler to be running more frequently and for longer periods of time, the humidity should be driven down below humidity band 3. And the temperature control scheme should return to normal one shown in figure 3.

As an example of the code in action I will show you a graph from a curing a few legs of venison. See figure 5.

Figure 5 An excerpt from ½ a days curing

So what we see in the figure is temperature fluctuations within approximately 3 degrees Celsius. And humidity fluctuations within 10% RH. In figure 6 I have taken a detailed view of a 1½ hour span, and included an I/O indication for the heater and cooler. The humidifier was left out, since it wasn’t on at all during the time span.

Figure 6 Detail of figure 5. This figure also includes indications of when the cooler and heater turns on and off.

So in this detailed view it is very easy to see how the heater turns on whenever the humidity rises above band 2. We can also see how this increase in temperature actually causes the RH to fall. This is because of the temperature dependence between the relative humidity, absolute humidity and temperature.  So when the temperature rises faster than the absolute humidity we will see a fall in RH.

Well guys this was a small presentation of the logic which I have built in to my curing chamber control unit. I hope that you find it use full!

And of course, if you have any questions to what you have just read, or any general questions to the blog or curing chamber unit, please feel free to put them in the comments section. You might help someone else out there having the same doubts or questions.

Until next time! Have a good one!


17 kommentarer:

  1. Found your post when I was looking for information about using a Arduino to cure meats and it looks exactly like what I want to do. would it be possible to get a look at your code for the Arduino? I'll be using a Mega since I'm planning on using 8 load cells and need the analogs!

    Any ideas on using the RTC to change the Temp and RH limits as the days pass?

    1. Hi Erik

      Off course! My control is basically found in these two functions:
      int control(float reading,float target,float hystHi, float hystLo){
      //First a sensor check is performed
      int band;
      //Control: all off
      return band;
      //too high
      //upper band
      }else if(target<=reading && reading<=target+hystHi){
      //lower band
      }else if(target-hystLo<=reading && reading2){

      }else if(tempBand==2&&digitalRead(cooler)){

      else if(humBand==1&&digitalRead(humidifier)){

      With regards to the load cells i would suggest that you look into the HX711 board. It has a built in stable power supply for the strain gauge in the loadcell and really high resolution! (24bit). Hooking them through analog electronics, such as an INA125 can also be a bit tricky.

      You can of course time everything with a RTC, but i actually just use the arduino on board clock, since everything doesn't have to be super precise. There is a risk over overflow though, if you are curing anything for more than 50 days. Also you need to store your time variables in unsigned longs, for them not to overflow aswell.

      I have my different targets saved on an SD card, with the corresponding times. I then can then load the appropriate targets, with regards to the current time. For this i use this command:

      //Loading the control data if available on the SD card
      void loadControlParameters(){
      //Opening the datafile
      File dataFile = SD.open("Control/control.txt", FILE_READ);
      long controlTime=0;
      //if file is available
      controlTime=dataFile.parseInt(); //First control time is loaded (usually zero)
      //cycling through the curing program until relevant stage is reached
      while(now()>=controlTime && dataFile.available()){
      controlTime=dataFile.parseInt(); //The controlTime of the next line
      //If a file isn't available restart the sd reader
      lcd.print(" Targets:");

      Hope the answer can be off help :)

  2. Looks nice, but I'm not sure I understand it all... would you mind sharing your ino files? or even better make a project on github! I know there are many that would be interested in it!

    1. Well i have thought about making a github project, but at the moment i simply dont have the time to manage it.
      You can see my latest, entire, working ino file here:

    2. Oh I love you! That is so awsome, thanks a million for sharing it! Promise to give cred whenever someone asks how I did it :D
      could you upload the control.txt to? Are all the different values for lowering RH and temp in the same file or are you using different ones?

  3. Hi! Just want to say HUGE THANKS for sharing the arduino code and curing bot logic!
    I'm now in the middle of assembling my own and I took your code as a base.
    Since my curing chamber is going to be installed in the basement of my country house and will work unattended most of the time instead of local SD card logging and loading control parameters from it I'm using the esp8266 board and uploading data to thingspeak.com and getting control values from talkback.

  4. Hi Dmitry.
    I am glad to hear that you have been able to use my code and logic :) what is logic to one self isn't always to everyone else :D your take on the project sounds really cool!! I have been thinking of doing something similar myself. I would love to hear how it comes along and to see some pictures of your build.

    Br Niels

    1. Hopefully in the next week or 2 I'll finally find some free time to get all the components in the case and start to assembly the curing chamber itself. I decided to use a large kitchen сurbstone for a chamber as the temp in my basement all year round is 15 c and I do not need a fridge or heater. As a dehydrator I'll be using PC fan to blow humid air out of the chamber.
      So, hopefully, later this spring I'll start final testings and debugging.
      Here is the thingspeak channel of my device (going through stability test for a week) https://thingspeak.com/channels/161482

    2. Small update.
      I finally assembled the whole controller and curing chamber!
      Controller inside: https://goo.gl/photos/sJVLeercTjP3zrCB7
      Connectors and external DHT: https://goo.gl/photos/7UfS8qvaJZ2KhZRy9

      Definitely not an ideal build quality, but it works at least :)

      Unfortunately it's really humid in my basement at spring, so now I could not really test it. Hopefully outside humidity will drop in a week or to and I'll be able to do a test batch of sausages.
      Thanks again for sharing the code!

    3. Hi Dmitry, sorry i haven't had a chance to look at your pictures up until now.
      Alot of stuff has been going on at the homefront.
      I really like your build! I love how these "as long as it works"-builds sort of always look a bit like shitty bombs :D

    4. I am working on finishing a nicer looking version of the build my self, but you would not believe the time it takes to put this stuff together in a way, that looks nice and tidy.

  5. I recently have some issues with poor contact on this build so now I'm working on building v.2 too :)
    And I decided to get rid of dht sensors an use BME280.

    1. That's always how it goes, you build something that works, and then you want to build in a nicer quality :)

      How come you changed sensors? I have never had any problems with my DHT22's, but then again i have always used the AM2302 type, with the extra circuits added on.

    2. Denne kommentar er fjernet af forfatteren.

    3. Damn blogspot :)
      Danish interface confuses me a lot. Instead of editing I just delete my post :)

      "I use AM2302 too but after about 2 months of use 2 sensor outside of my chamber start to show 98-99.99% humidity, while the one inside showing around 80-82% Chamber is now empty and door is opened. SO sensor data must be somehow closer to each other :)
      And also DHT are too slow, making delay function a must, which almost blocks ESP8266 OTA functionality. Since my chamber is in the pavement OTA will be really nice to have :) "

    4. Ah i see :) Haven't had the chance to toy with the esp's myself, but i have one in the drawer for a rainy night...
      Feel free to share any progress in the future!

  6. The benchtop environmental chamber also call the small environmental chamber, it can test the temperature, thermal, etc, DGBell is the benchtop environmental chamber manufacturer. To know more information visit Benchtop temperature chamber