Arduino UNO Temperature-Controlled Heating System with DS18B20 and Relays
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to control the temperature using an Arduino UNO and a DS18B20 temperature sensor. The circuit includes two 5V relays to control two heating mats based on the temperature readings from the DS18B20 sensor. The relays are activated or deactivated depending on the temperature to maintain a desired temperature range.
Component List
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
DS18B20
- Description: A digital temperature sensor.
- Pins: signal, GND, vcc
Resistor
- Description: A resistor with a resistance of 47k Ohms.
- Pins: pin1, pin2
- Properties: Resistance: 47000 Ohms
5V Relay (Relay 1)
- Description: A relay module that operates at 5V.
- Pins: Normally Open, Common terminal, Normally Closed, In, GND, VCC
5V Relay (Relay 2)
- Description: A relay module that operates at 5V.
- Pins: Normally Open, Common terminal, Normally Closed, In, GND, VCC
Heating Mat (Mat 1)
- Description: A heating mat.
- Pins: +, -
Heating Mat (Mat 2)
- Description: A heating mat.
- Pins: +, -
AC Supply
- Description: An AC power supply.
- Pins: +ve, -ve
Wiring Details
Arduino UNO
- D5 is connected to VCC of Relay 1.
- D6 is connected to VCC of Relay 2.
- 5V is connected to:
- pin1 of the Resistor
- vcc of the DS18B20
- In of Relay 1
- In of Relay 2
- D2 is connected to:
- pin2 of the Resistor
- signal of the DS18B20
- GND is connected to:
- GND of Relay 1
- GND of DS18B20
- GND of Relay 2
DS18B20
- signal is connected to D2 of the Arduino UNO.
- GND is connected to GND of the Arduino UNO.
- vcc is connected to 5V of the Arduino UNO.
Resistor
- pin1 is connected to 5V of the Arduino UNO.
- pin2 is connected to D2 of the Arduino UNO.
5V Relay (Relay 1)
- VCC is connected to D5 of the Arduino UNO.
- In is connected to 5V of the Arduino UNO.
- GND is connected to GND of the Arduino UNO.
- Normally Open is connected to + of Heating Mat 1.
- Common terminal is connected to +ve of the AC Supply.
5V Relay (Relay 2)
- VCC is connected to D6 of the Arduino UNO.
- In is connected to 5V of the Arduino UNO.
- GND is connected to GND of the Arduino UNO.
- Normally Open is connected to + of Heating Mat 2.
- Common terminal is connected to +ve of the AC Supply.
Heating Mat (Mat 1)
- + is connected to Normally Open of Relay 1.
- - is connected to -ve of the AC Supply.
Heating Mat (Mat 2)
- + is connected to Normally Open of Relay 2.
- - is connected to -ve of the AC Supply.
AC Supply
- +ve is connected to Common terminal of Relay 1 and Relay 2.
- -ve is connected to - of Heating Mat 1 and Heating Mat 2.
Documented Code
/* Temperatursteuerung mit einem ArduinoUno und dem DS18B20 */
#include <OneWire.h>
#include <DallasTemperature.h>
//===================== Einstellungen ==============================
#define DS18B20_DATA 2 //==> Daten-Pin für TemperaturSensor DS18B20
#define Relais_PIN1 5 //==> Pin für Relais
#define Relais_PIN2 6 //==> Pin für Relais
//=============================================================================
OneWire oneWire(DS18B20_DATA);
DallasTemperature sensors(&oneWire);
void setup(){
Serial.begin(9600);
Serial.println("Sensor temperature initialisation");
sensors.begin();
pinMode(Relais_PIN1, OUTPUT);
pinMode(Relais_PIN2, OUTPUT);
digitalWrite(Relais_PIN1,LOW);
digitalWrite(Relais_PIN2,LOW);
}
void loop(){
Serial.print("Requesting temperatures...");
sensors.requestTemperatures();
Serial.println("DONE");
float tempC = sensors.getTempCByIndex(0);
// Check if reading was successful
if(tempC != DEVICE_DISCONNECTED_C)
{
Serial.print("Temperature for the device 1 (index 0) is: ");
Serial.println(tempC);
if(tempC < 37.0)
{
digitalWrite(Relais_PIN1,HIGH);
digitalWrite(Relais_PIN2,HIGH);
}
else
{
digitalWrite(Relais_PIN1,LOW);
digitalWrite(Relais_PIN2,LOW);
}
}
else
{
Serial.println("Error: Could not read temperature data");
}
}
This code initializes the DS18B20 temperature sensor and the relays. It reads the temperature and activates or deactivates the relays based on the temperature reading to control the heating mats.