Pinterest Stumbleupon Whatsapp
Ads by Google

Raise the perfect bread, brew beautiful beer, and rear happy chicks with an Arduino temperature controller. If you live in a less than reliable climate like England, directions that tell you to keep something at a set temperature aren’t particularly helpful – we don’t have air conditioners, and raising the thermostat for the whole house isn’t practical for just making a loaf of bread. Even kept inside, chicks can die if the temperature drops at night; and getting them to hatch in the first place has an even stricter temperature range. But I need my bread, and the chicks need hatching – so instead of purchasing expensive equipment, we can cobble together a competent temperature controller with an Arduino and household bits.

The same is also true for keeping items cool – it can be wasteful to run a whole fridge just to make yoghurt – but with a temperature controller, the principle is the same. Instead of activating a heating element, you’ll be activating the plug on a mini-fridge or other cooling element, like a Peltier (thermoelectric cooler) – and of course, the logic will be reversed.

What You Will Need

This is an Arduino project – if you’ve never worked with Arduino before, our free beginner’s guide is a fantastic place to start.

  • Arduino
  • Temperature sensor – I’m using a TMP36, a cheap single package device that comes with the Oomlout (UK) / Sparkfun (US) beginner’s kit.
  • Relay or RC plug switches
  • Screw terminals
  • Box to trap the heat
  • Heating element or incandescent bulb and fixture (or both)

The last item has been left deliberately vague. If you have an incandescent bulb (the kind that gets hot, not an energy-saving bulb), or a hot lamp for sporting injuries and such, it’s probably the easiest to set up. I’m using a heating band – basically a band of rubber that gets warm when electricity is passed through, used on carboys and kegs for initial fermentation stages in wine or beer making – technically, this can be a fire risk when not wound around something, so please don’t do this, I’m only using it to test. You can also buy heating pads for the same purpose.

For safety reasons, I’m using these RC plugs to switch AC devices, with a controller hacked apart detailed in this home automation article Control Appliances From An Arduino: The Start Of Home Automation Control Appliances From An Arduino: The Start Of Home Automation Last time, I showed you a few ways of making your Arduino projects speech controlled via SiriProxy, OS X's built-in speakable items, and some Automator scripting, or even a dedicated voice recognition hardware chip. I... Read More . It’s wireless, so at no point need I actually touch live wires.

Temperature Sensing

Let’s start by wiring up and testing the sensor. [Diagram from Adafruit]

Ads by Google

adafruit-tmp36

With the flat side toward you and legs face down, the TMP36 temperature sensor is wired up +, signal, GND in that order. The + goes to the 3.3 V output from Arduino; you also need another line going from the +3.3 V to the AREF pin – this tells the Arduino to use 3.3 V for analog input reference instead of 5 V. Connect the signal pin of the sensor to A1. In previous attempts, I had used the TMP36 directly on the 5 V line; it works, bit unfortunately when paired with a relay, there was a power drop whenever the relay was activated, resulting in highly fluctuating readings.

I used an old network cable as signal cable – very useful to have around, since there are 8 wires inside. The cable is quite thin though, so be sure to strengthen the other end with solder where it’ll be screwed into a terminal block.

tmp36-sensor-cabling

The formula in the code assumes you’re using the tMP36 sensor; you should be able to find a code sample for other sensors. This sample code is from Adafruit – load it up and open the Serial console to examine the output.

tmp36-testing

Compare with a thermometer if possible. Readings not right?

  • Check the voltage being supplied is actually 3.3 V
  • Is the AREF connected to 3.3 V too?

Adding in Switch Logic

To control the heating element, I’m using these RC plug sockets from Maplin, and have taken apart the controller. Only the ground and control pin need be connected. I’ve modified the code to include the relevant libraries which you can download from here.

rc-switches

At this point, I’m also going to remove all references to Farenheit and continue working with Celsius only. I’ve then defined a desired temperature to maintain, and added in a simple control structure like so:

if(temperatureC < desiredTempC){
    mySwitch.switchOn(1,1);
    Serial.println("Heater ON");
  }
  else{
    Serial.println("Heater OFF");
    mySwitch.switchOff(1,1);
  }

There’s nothing complex here that you won’t understand – just comparing the current temperature reading to the desired one, and turning on the switch if it’s lower; otherwise, turn it off.

The complete code can be found here, though you will need to adjust this if you’re using a relay (it’s not hard). Here’s the complete wiring diagram I used:

wiring

Putting It All Together

Tape the sensor inside the box you’re using, and place the heating element wherever is appropriate. Set the desired temperature, and turn it all on. If you keep your PC connected for now, you can use the Serial console to observe changes as your box heats up.

temperature-controller-box

Further Work

  • To lessen the impact of any temperature fluctuations, you can try smoothing the results. Create an array to store 10 readings, and calculate an average on each loop.
  • To avoid rapid activation and deactivation of the heating element, create a variable to store a countdown. Each time you activate or deactivate, record the current time in the countdown, then before switching the state again check to see if X amount of time has elapsed since the last state change.
  • For a computer-less project, hook up a small LCD screen to display current temperature and allow you to see the current and desired temperature.

Putting It To The Test

Finally, what would this project be without a little test? I whipped up a batch of ready-mixed dough in the bread machine and split it into two loaves. The one leavened inside the box was mildy bigger, but then the ambient air temperature today is about 26 degrees Celsius anyway – this would be much more useful in winter. Regardless, I better go make some soup to accompany this lovely bread.

bread-test

So, what would you make that requires a constant temperature?

Image credit: Ian Watkins/flickr

  1. Doodman
    September 9, 2016 at 8:24 am

    I'm looking to build a meat curing chamber in an old refrigerator. I'd like to hook the arduino straight to the compressor so I can use it to control the temp rather than the fridges thermostat, as well as a relay to turn a humidifier on and off to control the humidity. Is that possible?

  2. Mingfei D.
    July 23, 2016 at 10:58 pm

    Everything is working now... except my temperature controller has gone crazy? Every now and then the analog reading drops to 1 or 2, giving an extreme negative temperature and I don't know why. It also in general gives wrong temperatures (too low), but funnily enough not when using the adafruit program. It was working before...
    help?

    • Mingfei D.
      July 31, 2016 at 4:43 pm

      Nevermind
      The fluctuations have stopped (for now), and I discovered that I set the aref voltage to 3, not 3.3 *facepalm*

  3. Mingfei D.
    June 19, 2016 at 6:44 pm

    Where exactly should the signal wire and ground be soldered onto the remote? Thanks

    • James Bruce
      June 20, 2016 at 7:57 am
    • Mingfei D.
      June 20, 2016 at 9:56 pm

      Wait
      So the wire should be soldered directly onto the chip? And what about the ground? It's just that in the picture in this article it looks like there's just one connection and it's right above the chip, aside from the wires connected to where the battery went.
      Sorry, it's just my first time trying to hack stuff :)

    • James Bruce
      June 21, 2016 at 8:12 am

      Oddly enough, I had more luck when the ground *wasn't* soldered, but I'm not sure why. But yes, solder the wire either straight to the chip or on the track from it after scraping off the layer of protection. If you're not comfortable possible breaking your remote, you might want to look at the other solutions in the link I posted - like a relay. There's no easy way to mess with AC electrical power!

      You could also look at a DC powered heating element, which would be low voltage and safer to mess with.

  4. Rey
    April 27, 2016 at 5:26 am

    I'm having an issue right now. It is easier to find LM35 rather than TMP36 here in my country. And I find out that it uses different source code to control. Can anybody help me out this issue?

  5. Mingfei D.
    April 23, 2016 at 12:11 am

    Sorry for my noobiness
    What role does the screw terminal play in this setup? I don't see it on the diagram...

    • James Bruce
      April 23, 2016 at 6:23 am

      It's just a connector. If you check out the finished setup, it's on the breadboard, so the long wire from the sensors screws in then the jumper wires go to the Arduino.

    • Mingfei D.
      April 23, 2016 at 7:10 pm

      So the temperature sensor is not on the breadboard?

    • James Bruce
      April 24, 2016 at 7:04 am

      No, the sensor is in the box, as it needs to detect the temperature there.

  6. Joakim Rönning
    January 7, 2016 at 5:42 pm

    What would you recommend use as the temperature regulator in a computerless build? I'm building a food dehydrator and would like to use a temperature knob and a small LCD display that shows current and target temperature.

  7. Erik
    January 1, 2016 at 6:27 pm

    Hi, I'm looking to use this process to control a heating element on a timer. Essentially it's going to be on an alarm setting where at a certain time the relay will turn on the current in order to cause the heating element to turn on and increase the temperature in an enclosed space. What would the programming be for that. This project seems to be more of an always on always adjusting. I would like my project to turn on and off during certain periods of the day.

  8. jay castor
    August 28, 2015 at 1:13 am

    Hello, anyone can help me? I have arduino project that detects the room temperature, and humidity and the display is in a webpage provided by an IP Address. My problem, I want this data to be save in an SQL Database. how to do this? please help me. email me @ squatic@gmail.com or jtcastor87@yahoo.com

    Thank you so much!

    • ashik
      November 16, 2015 at 5:09 pm

      You can Use SQLite in Rasberry and save it to a database table and also a lighttp server as web server. :)

    • Kenneth
      February 16, 2016 at 7:39 pm

      I agree with Ashik; if you're not already familiar with linux, start using raspberry and sqlite.

  9. Archie Mujar Berizo
    August 15, 2015 at 7:58 am

    i want to build an hot compress using arduino anyone there want to teach me how please i want it for my thesis

    • Archie Mujar Berizo
      August 15, 2015 at 8:01 am

      first time doing project:(

    • Archie Mujar Berizo
      August 15, 2015 at 8:02 am

      using arduino

    • zain
      December 10, 2015 at 7:57 pm

      give me your email i'll help u

  10. Perrie Iles
    June 5, 2015 at 10:28 am

    I am trying to make a precision temp well for thermometers. We have a reference thermometer (-20 to +50 C +/-0.025 C) i have machining tools (lathe mill etc) ,
    but no design. needs to be adjustable and very stable. I thought a fet/peltier and arduino properly calibrated could do the job. but i have no idea how to turn theory into practice.
    any sources of info you might direct me to would be greatly appreciated. Love to build a gallium melt chamber, they are useful to about +/-0.000020 C (20uK) !!

  11. Aisha
    May 15, 2015 at 5:20 am

    Hello I am interested in using this guide to build my own temperature controller.

    I have everything I need but I need to use a relay instead of this RC board. You say it's easy to modify the code but don't say how.

    I'm also confused because you say I should see 3.3v in my serial monitor but I only see 1.5 average, the temperature readings are also a lot higher then they should be reading in the 90s in a 75 degree room..

    I just need to switch on and off a fan (maybe 2 in the future) based on the temperature of a room.

    • James Bruce
      May 15, 2015 at 6:53 am

      Relays work by sending a pin high, so instead of MySwitch.On(), you would use digitalWrite(relayPin, HIGH).

      Are you using the same temperature sensor, the TMP36? Other sensors will require different code for their change from voltage to temperature. Check that you're putting 3.3v into the sensor, as thats the reference voltage it uses. If you put 5v in, youll get a wrong reading. I believe it can also vary with altitude, so you may need to adjust the calculation for extreme locations.

  12. Alex
    April 26, 2015 at 9:41 am

    Hi,
    I need to controll the temperature with 22 sensors, and have no idea how to.
    Is there some board where i can connect them all and read one by one, because there's not enought pins for all XD.
    If you know of commercial things that can do it it's ok for me to.
    Thanks in advance.

    • KWM
      May 2, 2015 at 5:24 am

      I think you're looking for a multiplexer (MUX) - should be several off-the-shelf chips out there from which to choose. Worst case you need two layers of muxing and nested for loops for the mux select lines to get the fan out you want.

  13. George Ekman
    April 4, 2015 at 6:08 pm

    What kind of heating element are you using?
    I am making a bread proofing chamber for my Father's birthday.
    (Link please)

  14. Taimur Khan
    December 2, 2013 at 12:29 am

    Here is my code using https://code.google.com/p/rc-switch/ and
    http://learn.adafruit.com/tmp36-temperature-sensor/using-a-temp-sensor

    I have added a bit of hysteresis, so the heater turns off when temperature more than 25, and then turns on when temperature less tan 20. Also made sure that it sends On or Off command every time as I have seen that the wireless transmitter /receiver can miss a transmission or two some times

    ___

    /*
    Example for different sending methods

    http://code.google.com/p/rc-switch/

    Need help? http://forum.ardumote.com
    */

    #include

    RCSwitch mySwitch = RCSwitch();
    //TMP36 Pin Variables
    int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
    //the resolution is 10 mV / degree centigrade with a
    //500 mV offset to allow for negative temperatures

    int SwitchState=0;
    void setup() {

    Serial.begin(9600);

    // Transmitter is connected to Arduino Pin #10
    mySwitch.enableTransmit(10);

    // Optional set pulse length.
    // mySwitch.setPulseLength(320);

    // Optional set protocol (default is 1, will work for most outlets)
    // mySwitch.setProtocol(2);

    // Optional set number of transmission repetitions.
    // mySwitch.setRepeatTransmit(15);

    }

    void loop() {

    //getting the voltage reading from the temperature sensor
    int reading = analogRead(sensorPin);

    // converting that reading to voltage, for 3.3v arduino use 3.3
    float voltage = reading * 5.0;
    voltage /= 1024.0;

    // print out the voltage
    Serial.print(voltage); Serial.println(" volts");

    // now print out the temperature
    float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
    //to degrees ((voltage - 500mV) times 100)
    Serial.print(temperatureC); Serial.println(" degrees C");

    if (SwitchState ==1 ) {
    mySwitch.switchOn(3,1);
    if (temperatureC >25.0){
    mySwitch.switchOff(3,1);
    SwitchState=0;
    }
    }
    else if (SwitchState ==0 ){
    mySwitch.switchOff(3,1);
    if (temperatureC<20){
    mySwitch.switchOn(3,1);
    SwitchState=1;
    }
    }
    // Wait 10 second
    delay(1000);

    }

  15. catprog
    September 2, 2013 at 6:14 am

    For a more accurate temperature look up a PID algorithm.

    • James B
      September 2, 2013 at 12:41 pm

      Good advice, though I thought that would be a bit much for this article.

Leave a Reply

Your email address will not be published. Required fields are marked *