Heating System – Arduino Tutorial

3,876 views

Introduction

Controlling the temperature of a space or an environment is a crucial task in many fields of engineering, such as HVAC systems, industrial process control, and home automation. One of the most effective ways to generate heat is by using a DC heating element. In order to automate the control of the heating element based on temperature, an Arduino microcontroller, a DS18B20 temperature sensor, and a 5V SPDT relay can be used.

The DS18B20 temperature sensor is a digital thermometer that can measure temperatures in a range of -55°C to +125°C with a resolution of 9 to 12 bits. The Arduino microcontroller reads the temperature value from the sensor and compares it to a pre-defined threshold temperature value. If the temperature is below the threshold, the relay is activated (turned on) which allows power to be supplied to the DC heating element, turning it on. If the temperature is above the threshold, the relay is deactivated (turned off) which cuts power to the heating element, turning it off.

Hardware Components

You will require the following hardware for making a Heating System with Arduino.

S.noComponentValueQty
1.Arduino UNO1
2.USB Cable Type A to B1
3.Temperature Sensor DS18B201
4.Relay1
5.Heating Element1
6.DC Power Jack1
7.Power Adapter for Arduino1
8.Resistor4.7KΩ1
9.Power Adapter1
10Jumper Wires1

Heating System with Arduino

  1. Start by including the necessary libraries for the OneWire and the DallasTemperature at the beginning of your code:
#include <OneWire.h> 
#include <DallasTemperature.h>
  1. Define the pin number for the relay, the temperature sensor, and the threshold temperature value in your code:
const int relayPin = 3; 
const int tempSensorPin = 2;
const float thresholdTemp = 25; // Threshold temperature value in Celsius
  1. Create an instance of the OneWire and DallasTemperature library
OneWire oneWire(tempSensorPin);
DallasTemperature sensors(&oneWire);
  1. In the setup() function, initialize the serial communication, set the relay pin as an output and start the temperature sensor:
void setup() {
  Serial.begin(9600); // Initialize serial communication
  pinMode(relayPin, OUTPUT); // Set relay pin as output
  sensors.begin();
}
  1. In the loop() function, read the temperature value from the DS18B20 sensor and compare it to the threshold temperature value. If the temperature is above the threshold, turn on the relay and print the status on the serial monitor. If the temperature is below the threshold, turn off the relay and print the status on the serial monitor:
void loop() {
  sensors.requestTemperatures();
  float temperature = sensors.getTempCByIndex(0); // Read temperature value
  if (temperature < thresholdTemp) {
    digitalWrite(relayPin, HIGH); // Turn on relay
    Serial.println("Heating Element ON: Temperature Below threshold");
  } else {
    digitalWrite(relayPin, LOW); // Turn off relay
    Serial.println("Heating Element OFF: Temperature above threshold");
  }
  delay(1000); // Wait for 1 second before repeating the loop
}

Schematic

Make connections according to the circuit diagram given below.

Wiring / Connections

ArduinoDS18B20 SensorRelay
3V3VCC
GNDGNDGND
D2DATA
A5INP
5VVCC

Installing Arduino IDE

First, you need to install Arduino IDE Software from its official website Arduino. Here is a simple step-by-step guide on “How to install Arduino IDE“.

Installing Libraries

Before you start uploading a code, download and unzip the following libraries at /Progam Files(x86)/Arduino/Libraries (default), in order to use the sensor with the Arduino board. Here is a simple step-by-step guide on “How to Add Libraries in Arduino IDE“.

Code

Now copy the following code and upload it to Arduino IDE Software.

#include <OneWire.h>
#include <DallasTemperature.h>

#define SENSOR_PIN  2   // Arduino pin connected to DS18B20 sensor's DQ pin
#define RELAY_PIN   A5  // Arduino pin connected to relay which connected to heating element

const int TEMP_THRESHOLD_UPPER = 20; // upper threshold of temperature, change to your desire value
const int TEMP_THRESHOLD_LOWER = 15; // lower threshold of temperature, change to your desire value

OneWire oneWire(SENSOR_PIN);         // setup a oneWire instance
DallasTemperature sensors(&oneWire); // pass oneWire to DallasTemperature library

float temperature;    // temperature in Celsius

void setup() {
  Serial.begin(9600); // initialize serial
  sensors.begin();    // initialize the sensor
  pinMode(RELAY_PIN, OUTPUT); // initialize digital pin as an output
}

void loop() {
  sensors.requestTemperatures();             // send the command to get temperatures
  temperature = sensors.getTempCByIndex(0);  // read temperature in Celsius

  if(temperature > TEMP_THRESHOLD_UPPER) {
    Serial.println("The heating element is turned off");
    digitalWrite(RELAY_PIN, LOW); // turn off
  } else if(temperature < TEMP_THRESHOLD_LOWER){
    Serial.println("The heating element is turned on");
    digitalWrite(RELAY_PIN, HIGH); // turn on
  }

  delay(500);
}

Working Explanation

In the setup() function, the microcontroller initializes the serial communication, sets the relay pin as an output, and starts the temperature sensor. This allows the microcontroller to send data to the serial monitor and control the relay.

In the loop() function, the microcontroller reads the temperature value from the DS18B20 sensor and compares it to the threshold temperature value. If the temperature is above the threshold, the microcontroller deactivates the relay by setting the relay pin to a low state and it prints the status on the serial monitor. If the temperature is below the threshold, the microcontroller activates the relay by setting the relay pin to a High state and it prints the status on the serial monitor.

Applications

  • HVAC Systems
  • Industrial Process Control
  • Home Automation
  • Greenhouses
  • Automotive
  • Outdoor Applications
  • Medical Devices
  • Food Processing

Conclusion.

We hope you have found this Heating System Circuit very useful. If you feel any difficulty in making it feel free to ask anything in the comment section.