in arduino, tutorial

How to Build a Heater with Arduino – Part 2

Share Button

This is the second part of a tutorial that will teach you how to build a portable heating device with Arduino. In this post, we will explore how to control a heating resistor with Arduino. This allows to keep your setup at the desired temperature.

Introduction

In the first part of this tutorial, How to Build a Heater with Arduino – Part 1, we’ve discussed how to create and calibrate the component that will generate the heat. The problem so far is that there is no control over the temperature. If you’ve done your calculation correctly and respected the wattage of your resistors, there is no risk of overheating. However, there’s nothing that prevents your resistors from getting hotter than what you initially intended. This is particularly true if there is no ventilation, or if the heater is in direct contact with a surface that does not dissipate heat very well. The correct (and safe) approach to solve this problem is to introduce a sensor to measure the temperature. If it’s too cold, we’re turning the heating on; if it’s too hot, we’re turning it off. Please, keep in mind that what seems a trivial problem is in actuality incredibly challenging. Designing a responsive device that control an actuator (the heater) based on the reading of a sensor (the temperature) can be a major engineering challenge. This tutorial will provide a very simple solution, and point out how the design can be improved with a little bit of extra Maths.

Choosing the Sensor

Is important to understand that when it comes to temperature, there are a large number of choices. It’s important to understand that different sensors are based on different technologies, hence come with differed limitations and advantages. The main two classes of temperature sensors that are mostly used are integrated circuits and thermistors. Distinguishing them is very easy: the former have three pins, the latter only two.

4472743Like the name suggests, thermistors are components which resistance value is very sensitive to temperature changes. Then a voltage difference is applied to its ends, its resistance will vary in response to changes in temperature. Thermistors are somehow a pain to use, since they require additional resistors and a deeper understanding of electronics. The relationship between resistance and temperature is in fact calculated using the Steinhart-Hart equation, which can be scary at first.

images-4For the above-mentioned reasons, this tutorial will focus on the more Arduino-friendly integrated circuit sensors. For this tutorial, I have used the very common LM35. Two pins are reserved for the reference voltage (ground and 5V); the voltage on the other one will vary between these two, depending on the temperature.

If you want to expand your knowledge on sensors, Arduino sensor temperature comparison has ready-to-use recipes for the most used sensor types.

Powering the Heater

As seen in the previous part of this tutorial, the heater we have designed is likely to require much more current than the one that Arduino can provide. For this reason, it has to be powered separately. A safe and reliable option is to use a traditional phone charger. They usually range from 5V to 9V, and have a limit on the amount of current they can provide. This makes them perfect for this application, as they operate in the a safe range. If you need a serious heating device, you can power you heater directly from the main, although this is going to be very dangerous.

4191WLdikjLThe problem we have now is to control the flow of current to the heater, using Arduino. This is the perfect time to use a transistor. Transistors are, de-facto, switches. They allow or prevent the flow of current in one direction, based on a specific input. We can use Arduino to turn the switch on and off based on the reading from the sensor. The one I am using for this project is a TIP120, which can operate high voltages. Make sure you have one that can be controller by the voltage provided by an Arduino.

Calculating the Base Resistance

The previous part of this tutorial referred to a battery-operated heater. The new schematics will assume that power comes from a phone charger instead. This changes the input voltage from 9V to 5V. If we want to dissipate 4W of power, we need a total resistance of 6.25\Omega, safely distributed on 8 resistors of 50\Omega each (all the calculations are explained in the Part 1). Our new setup requires, to operate at full power, a current of 0.8A=\frac{5V}{6.25\Omega}. Make sure that the charger you’re using can provide this amount of current, since most of them are capped at 0.5A.

It’s common practice to wire a resistor to the base of the transistor. This is the prevent an excessive flow of current that might damage both the transistor and the Arduino. Most designs use resistors between 1K\Omega and 10K\Omega. If you have the datasheet of your transistor, you can calculate how much resistance you actually need to be safe. The formula is:

    \[R_B = \left(V_{CC}-V_{BE}\right) \frac{DC_{gain}}{I_C}\]

Where:

  • R_B: the base resistance to connect to the transistor base;
  • V_CC: the voltage provided to the base (for Arduino: 5V);
  • V_BC: the voltage of the transistor when fully on (see below);
  • I_C: the load current the transistor has to withstand (as calculated previosuly: 0.8A);
  • DC_{gain}: the gain of the transistor, when subjected to a current of I_C amps (see below).

To calculate the DC_{gain} we need to refer to the datasheet of the transistor in use. We can read from this graph (TIP120 datahseet) that the TIP120 has a DC_{gain} of 3000 at a current of 0.8A. Similarly, it has a V_{BE} around 1.5V:

gain

By plugging all the numbers, we can calculate that R_B=13125\Omega, meaning we can use a 13K\Omega resistor.

Connecting the Components

The following diagram shows how all the components have been wired up. The transistor used, TIP120, is a NPN; it means that its emitter pin must be grounded.

heater_bb

Remember that in order for this design to work, you have to keep the temperature sensor close to the heating elements.

The Code

The final part is to write the logic that operates our heater. During every iteration, Arduino samples the temperature from the sensor and switches the transistor accordingly.

The equation to read the temperature from the LM35 comes from the official documentation on Arduino Playground (LM35 Higher Resolution).

Conclusion

The code provided in this tutorial is simple, possibly too simple for this application. The sensor used is unreliable, making the system excessively sensitive to temperature small oscillations and noise. A better approach would be to take repeated samples over a longer period of time. Averaging them reduces the effect of noise on the final measure. If you want an optimal solution, however, you can use a Kalman filter. It’s a powerful tool that allows to attenuate and to remove noise from sensors. To read more about it, check the tutorial A Gentle Introduction to Kalman Filters.

Secondly, even the way the heater is controller can be improved. There are several techniques to control an actuator based on a sensor reading. A common approach is to use a PID controller. This will be the topic of a future tutorial.

Other Resources

📧 Stay updated

A new tutorial is released every week.

💖 Support this blog

This websites exists thanks to the contribution of patrons on Patreon. If you think these posts have either helped or inspired you, please consider supporting this blog.

Paypal
Ko-fi
Twitter_logo

Write a Comment

Comment

      • I want to design a pocket heater using flexible elements and an Arduino board, which has four elements and four temperature sensors, and how can I connect and use the Bluetooth phone with the desired temperature and control it. . Use PowerBank as a power source for this heater and control the four thermal elements completely independently. The user interface of the heater will be on the mobile phone. MOSFETs are used to turn on and off the elements, and therefore there is no need for relay embedding.
        I have no information about the theory of things.
        But I have almost all the components.

    • Hi Daniel.
      I believe you can use a very similar approach.
      Get the data from your sensor, and then turn the fan on or off based on the temperature.
      You can simply replicate this three times, to get the three fans to work. It all depends on which type of fan you have.

      You might have to power your fans from an external power supply, like I did for the resistor ladder.

Webmentions

  • How to Build a Heater with Arduino - Part 1 - Alan Zucconi September 10, 2018

    Hi Daniel.
    I believe you can use a very similar approach.
    Get the data from your sensor, and then turn the fan on or off based on the temperature.
    You can simply replicate this three times, to get the three fans to work. It all depends on which type of fan you have.

    You might have to power your fans from an external power supply, like I did for the resistor ladder.