A wired and waterproof version of the DS18B20 temperature sensor is used here. Despite its sealed packaging, the probe should not be used in corrosive environments or saltwater.
Operating voltage | DC 3V to 5V |
---|---|
Measurement range | -55°C to +125°C |
Measurement accuracy | ±0.5°C from -10°C to +85°C |
Measurement speed | <750ms |
Interface |
1-Wire interface: uses only one wire for communication Unique 64-bit ID on the chip |
There are two versions: 3-wire and 4-wire:
3-wire: black=GND, red=3-5V, white/yellow=Data
4-wire: black=GND, red=3-5V, white=Data, remaining wire=Shield
DS18B20 | Arduino Uno |
---|---|
VDD | 3.3V or 5V |
Data | D2 (or other digital Pin) |
GND (Ground) | GND |
An important aspect of the wiring is the pull-up resistor placed between VDD and Data. When connecting two DS18B20 sensors, the same wiring should be used. No additional resistor is required. If especially long cables are used, it may be necessary to reduce the pull-up resistor value to as low as 1.8 kΩ.
The sensor is controlled using the "Dallas 1-Wire" protocol, which provides good measurement results with the two available libraries:
Dallas Temperature Control and
OneWire.
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin D2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a OneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass OneWire reference to Dallas Temperature
DallasTemperature sensors(&oneWire);
void setup(void) {
Serial.begin(9600);
sensors.begin(); // Start up the library
}
void loop(void) {
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
// Send the command to get temperature readings
sensors.requestTemperatures();
Serial.println("Temperature is: " + String(sensors.getTempCByIndex(0)) + "°C");
// You can have more than one DS18B20 on the same bus.
// 0 refers to the first IC on the wire
delay(1000);
}