Make Your Own Temperature Controller with an Arduino

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. 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

Join live MakeUseOf Groups on Grouvi App Join live Groups on Grouvi
Raspberry Pi Projects
Raspberry Pi Projects
70 Members
DIY Tech Projects
DIY Tech Projects
67 Members
Arduino Projects
Arduino Projects
60 Members
Ads by Google
Comments (13)
  • jay castor

    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!

  • Archie Mujar Berizo

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

  • Perrie Iles

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

  • Aisha

    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

      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.

  • Alex

    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

      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.

Load 10 more
Affiliate Disclamer

This review may contain affiliate links, which pays us a small compensation if you do decide to make a purchase based on our recommendation. Our judgement is in no way biased, and our recommendations are always based on the merits of the items.

For more details, please read our disclosure.
Affiliate Disclamer

This review may contain affiliate links, which pays us a small compensation if you do decide to make a purchase based on our recommendation. Our judgement is in no way biased, and our recommendations are always based on the merits of the items.

For more details, please read our disclosure.