Arduino - Heating System
In this tutorial, we are going to control room temperature using a heating element and DS18B20 temperature sensor. When the temperature is too cool, turn on the heating elemment. When the temperature is warm, turn off the heating elemment. You can also adapt the code for other temperature sensor such as DHT11 or DHT22, LM35 instead of the DS18B20 sensor.
|1||×||Arduino UNO or Genuino UNO|
|1||×||USB 2.0 cable type A/B|
|1||×||Temperature Sensor DS18B20|
|1||×||4.7 kΩ resistor|
|1||×||12V Power Adapter|
About Heating Element and DS18B20 Temperature Sensor
The heating elemment used in this tutorial uses the 12v power supply. If power is supplied for the heating elemment, the heating elemment emits heat. To control heating elemment by Arduino, we need to use a relay in between.
If you do not know about temperature sensor and heating elemment (pinout, how it works, how to program ...), learn about them in the following tutorials:
Image is developed using Fritzing. Click to enlarge image
How System Works
- Arduino reads the temperature from the temperature sensor
- If the temperature falls below an lower threshold, Arduino turn on the heating elements
- If the temperature rises above a upper threshold, Arduino turn off the heating element
The above process is repeated infinitely in the loop.
Arduino Code for Cooling System with DS18B20 sensor
In the above code, the Arduino turn on the heating element when the temperature falls below 15°C, and keep the heating element on until the temperature is above 20°C
- Connect Arduino to PC via USB cable
- Open Arduino IDE, select the right board and port
- On Arduino IDE, Go to Sketch Include Library Manage Libraries
- Search “OneWire”, then find the OneWire library by Paul Stoffregen
- Click Install button to install OneWire library.
- Search “Dallas”, then find the DallasTemperature library by Miles Burton.
- Click Install button to install DallasTemperature library.
- Copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to upload code to Arduino
- Make enviroment around sensor hotter or colder
- Check the temperature of heating element and your room
The above controlling method is the on-off controller, also known as a signaller or "bang-bang" controller. This method is very simple to implement.
There is an alternative method called the PID controller. With the PID controller, the desired temperature is more stable but very difficult to understand and implement. Therefore, the PID controller is not popular in temperature control.