Arduino Nano - Heating System
This tutorial instructs you how to use Arduino Nano to control the temperature of a room using a heating element and a DS18B20 temperature sensor.
- If the temperature is too low, Arduino Nano turns on the heating element.
- If the temperature is warm enough, Arduino Nano turns off the heating element.
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables.
Buy Note: Many DS18B20 sensors available in the market are unreliable. We strongly recommend buying the sensor from the DIYables brand using the link provided above. We tested it, and it worked reliably.
Overview of Heating Element and DS18B20 Temperature Sensor
The heating element utilized in this tutorial requires a 12v power supply. When power is supplied to the heating element, it will emit heat. In order to control the heating element with Arduino Nano, a relay must be used as an intermediary.
If you are not familiar with temperature sensor and heating element (pinout, functionality, programming ...), the following tutorials can help you:
Wiring Diagram
- Wiring diagram using a breadboard.
This image is created using Fritzing. Click to enlarge image
- Wiring diagram using a terminal adapter (recommended).
This image is created using Fritzing. Click to enlarge image
We recommend buying a DS18B20 sensor along with its accompanying wiring adapter for a seamless setup. This adapter includes an integrated resistor, removing the need for an additional resistor in the wiring.
How System Works
- Arduino Nano obtains the temperature from the temperature sensor.
- If the temperature drops below a certain lower limit, Arduino Nano activates the heating elements.
- When the temperature exceeds an upper limit, Arduino Nano deactivates the heating element.
The loop is repeated continuously.
Arduino Nano Code for Cooling System with DS18B20 sensor
In the code mentioned above, the Arduino Nano will activate the heating element when the temperature is less than 15°C and will keep it on until the temperature exceeds 20°C.
Detailed Instructions
- Connect Arduino Nano to a computer using a USB cable
- Launch the Arduino IDE, select the correct board and port
- Click to the Libraries icon on the left bar of the Arduino IDE.
- Search for “Dallas”, then locate the DallasTemperature library created by Miles Burton.
- Click the Install button to add the library.
- You will be asked to install the dependency. Click Install All button to install OneWire library.
- Copy the code and open it with the Arduino IDE.
- Click the Upload button on the Arduino IDE to compile and upload the code to the Arduino Nano.
- Change the temperature of the environment around the sensor.
- Check out the temperature of the heating element and the temperature of the room.
Advanced Knowledge
The above technique of control is called the on-off controller, which is also known as a signaller or "bang-bang" controller. It is very easy to put into practice.
An alternative approach known as the PID controller exists. This method of temperature control is more stable, however it is complicated to comprehend and put into practice. As a result, the PID controller is not widely used.