Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Based Dual DS18B20 Temperature Sensing Circuit

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based Dual DS18B20 Temperature Sensing Circuit

Circuit Documentation

Summary

This circuit consists of an Arduino UNO microcontroller connected to two DS18B20 temperature sensors. The sensors are interfaced with the Arduino using a 1-Wire bus protocol, which allows multiple sensors to be connected to a single data line. Each DS18B20 sensor is connected to the Arduino with a pull-up resistor to ensure proper communication on the data line. The circuit is designed to measure temperatures from both sensors and output the readings to the serial console.

Component List

Arduino UNO

DS18B20 (x2)

Resistor (x2)

Wiring Details

Arduino UNO

DS18B20 Sensors

Resistor (x2)

Documented Code

Arduino Sketch (sketch.ino)

/*
 * This Arduino sketch reads temperature data from two DS18B20 sensors
 * connected to pin D2 and prints the temperatures to the serial console.
 * Pin D3 is set to HIGH to act as a pull-up resistor for the DS18B20 data line.
 */

#include "OneWire.h"
#include "DallasTemperature.h"

#define ONE_WIRE_BUS 2
#define PULLUP_PIN 3

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

DeviceAddress sensor1, sensor2;

void setup() {
  // Set D3 as output and set it HIGH for pull-up
  pinMode(PULLUP_PIN, OUTPUT);
  digitalWrite(PULLUP_PIN, HIGH);

  // Start serial communication
  Serial.begin(9600);
  // Start up the library
  sensors.begin();

  // Locate devices on the bus
  if (!sensors.getAddress(sensor1, 0)) {
    Serial.println("Unable to find address for Sensor 1");
  }
  if (!sensors.getAddress(sensor2, 1)) {
    Serial.println("Unable to find address for Sensor 2");
  }

  // Set the resolution to 12 bit (each Dallas/Maxim device is capable of several different resolutions)
  sensors.setResolution(sensor1, 12);
  sensors.setResolution(sensor2, 12);
}

void loop() {
  // Request temperature readings
  sensors.requestTemperatures();

  // Fetch and print the temperature in Celsius for Sensor 1
  float temperatureC1 = sensors.getTempC(sensor1);
  Serial.print("Temperature 1: ");
  Serial.print(temperatureC1);
  Serial.println(" °C");

  // Fetch and print the temperature in Celsius for Sensor 2
  float temperatureC2 = sensors.getTempC(sensor2);
  Serial.print("Temperature 2: ");
  Serial.print(temperatureC2);
  Serial.println(" °C");

  // Wait 1 second before repeating
  delay(1000);
}

DallasTemperature Library (DallasTemperature.h, DallasTemperature.cpp)

The DallasTemperature library provides functions for working with the DS18B20 sensors. It handles the communication over the 1-Wire bus, including device discovery, temperature reading, and setting sensor resolution.

OneWire Library (OneWire.h, OneWire.cpp)

The OneWire library is used for low-level communication on the 1-Wire bus. It provides functions for sending and receiving data over a single wire, which is used by the DallasTemperature library to interface with the DS18B20 sensors.

(Note: The full code for the DallasTemperature and OneWire libraries is not included in this document due to their length. They are standard libraries available within the Arduino IDE or through their respective repositories.)