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
- Description: A microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D13-D0.
DS18B20 (x2)
- Description: Programmable resolution 1-Wire digital thermometer.
- Pins: VDD, DQ, GND.
Resistor (x2)
- Description: Pull-up resistor for the 1-Wire data line.
- Resistance: 200 Ohms.
Wiring Details
Arduino UNO
- 5V: Provides power to the VDD pins of both DS18B20 sensors.
- GND: Connected to the GND pins of both DS18B20 sensors.
- D2: Connected to the DQ pins of both DS18B20 sensors through the pull-up resistors.
- D3: Set to HIGH to act as a pull-up for the 1-Wire data line.
DS18B20 Sensors
- VDD: Connected to the 5V output from the Arduino UNO.
- DQ: Data line connected to digital pin D2 on the Arduino UNO through a 200 Ohm resistor.
- GND: Connected to the ground (GND) on the Arduino UNO.
Resistor (x2)
- One end connected to the DQ pin of each DS18B20 sensor.
- The other end connected to the D3 pin on the Arduino UNO.
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.)
