Make Your Own Temperature Controller with an Arduino

James Bruce 30-08-2013

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 Getting Started With Arduino: A Beginner's Guide Arduino is an open-source electronics prototyping platform based on flexible, easy-to use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments. Read More 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 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]



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.



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.


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.



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){
    Serial.println("Heater ON");
    Serial.println("Heater OFF");

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:



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.


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.


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

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

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

  1. Rodrigo
    February 19, 2020 at 5:46 pm

    Hi, How many wires did you use?

  2. Tomas Delaveau
    November 1, 2017 at 11:46 pm


    I'm trying to develop a on/off controller. The idea is to keep the temperature in element B equal to the temperature in element A, so I would need to connect two sensors and a heater. I would also need to record the temperature in each element. The algorithm would be as simple as:

    if tempA-tempB>0:

    The distance between the sensor and the controller can be up to 50 feet and the heater would have a power of around 2000W.

    What type of sensors should I use? How can I turn on a off a heater with that power using Arduino?

  3. Russell Riffin
    January 28, 2017 at 2:27 pm

    I also live in MEXICO, now in the mountains after 20 yrs on the Pacific Coast. I am curious where you have such an ideal climate. I am new to arduino but have putter Ed with electronics since I was 7 y.o. Drop me a line. Qué tenga un muy buen día...

  4. Saurav
    December 28, 2016 at 7:35 am

    Does this sensor measure high temperatures like 500clsius? if not what sensors do you suggest?

  5. Neil Mendoza
    November 18, 2016 at 3:36 am

    will try to make a chicken incubator but i would need to also add humidity control

    • Mark Elias
      October 27, 2019 at 2:04 am

      If you want humidity then do not go with the TMP36. Instead do some more reading and learn to use the DHT22 sensor. It does temp and humidity. Don't go cheap with the DHT11. I have made a controller that controls fans on my grain storage bins to only turn on during ideal time of day.

  6. Neil Mendoza
    November 18, 2016 at 3:31 am

    I'll probably try making an incubator for chicken eggs. but i need input and control for humidity as well

    • Manolis
      January 2, 2017 at 10:39 am

      Hi! I am making the same project. You need a DHT22 sensor which works for both humidity and temperature.

  7. na ri
    October 14, 2016 at 4:32 am

    im noob here. may i know what is that green little thing board called and how it works?

  8. suzy
    October 14, 2016 at 3:58 am

    Do help me please! Im noob here.
    1. What is that green board thing called and how it help/works witjin the circuit?
    2. Im making yogurt maker (only fermentation process). The question is the heating element is separately connected out of the circuit?
    3. Does the arduino control it too when the sensor detects the temp more/less within the desired temp. Im using bulb as the heating element. The idea is that the bulb will on/off within the range of the temperature.

    Im waiting for your help.

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

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

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

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

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

        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.

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

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

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

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

  16. Anonymous
    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 @ or

    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.

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

    • Anonymous
      August 15, 2015 at 8:01 am

      first time doing project:(

      • Anonymous
        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

  18. Anonymous
    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) !!

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

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

    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.

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

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

    Here is my code using and

    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

    Need help? [Broken URL Removed]


    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() {


    // Transmitter is connected to Arduino Pin #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 ) {
    if (temperatureC >25.0){
    else if (SwitchState ==0 ){
    if (temperatureC<20){
    // Wait 10 second


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

      • FAHAD Alsharari
        February 1, 2017 at 4:13 pm

        Hi there,

        Please tell me If I can Use a small coli heater instead of the lamb in this circuit?
        I am aiming to get heat in the range of 45 deg. to 50 deg in my small Incubator.
        and if possible, please provide me the coli type.
        I don't need to use a remote controller, I want it simple to build.
        I need more information on how I can do my small project.