1.. _ds18b20_sample:
2
3DS18B20 1-Wire Temperature Sensor
4#################################
5
6Overview
7********
8
9This sample shows how to use the Zephyr :ref:`sensor` API driver for the
10`Maxim DS18B20`_ temperature sensor.
11
12.. _Maxim DS18B20:
13   https://www.maximintegrated.com/en/products/sensors/DS18B20.html
14
15The sample periodically reads temperature data from the
16first available DS18B20 device discovered in the system. The sample checks the
17sensor in polling mode (without interrupt trigger).
18
19Building and Running
20********************
21
22The devicetree must have an enabled node with ``compatible = "maxim,ds18b20";``.
23See below for examples and common configurations.
24
25If the sensor is not built into your board, start by wiring the sensor pins
26as shown in the Figure Hardware Configuration of the `DS18B20 datasheet`_ at
27page 10.
28
29.. _DS18B20 datasheet:
30   https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf
31
32Boards with a built-in DS18B20 or a board-specific overlay
33==========================================================
34
35Your board may have a DS18B20 node configured in its devicetree by default,
36or a board specific overlay file with an DS18B20 node is available.
37Make sure this node has ``status = "okay";``, then build and run with:
38
39.. zephyr-app-commands::
40   :zephyr-app: samples/sensor/ds18b20
41   :goals: build flash
42   :board: nucleo_g0b1re
43
44DS18B20 via Arduino Serial pins
45===============================
46
47Make sure that you have an external circuit to provide an open-drain interface
48for the 1-Wire bus.
49Once you have wired the sensor and the serial peripheral on the Arduino header
50to the 1-Wire bus, build and flash with:
51
52.. zephyr-app-commands::
53   :zephyr-app: samples/sensor/ds18b20
54   :goals: build flash
55   :gen-args: -DDTC_OVERLAY_FILE=arduino_serial.overlay
56
57The devicetree overlay :zephyr_file:`samples/sensor/ds18b20/arduino_serial.overlay`
58should work on any board with a properly configured Arduino pin-compatible Serial
59peripheral.
60
61Sample Output
62=============
63
64The sample prints output to the serial console. DS18B20 device driver messages
65are also logged. Refer to your board's documentation for information on
66connecting to its serial console.
67
68Here is example output for the default application settings, assuming that only
69one DS18B20 sensor is connected to the standard Arduino Serial pins:
70
71.. code-block:: none
72
73   *** Booting Zephyr OS build zephyr-v2.6.0-1929-gf7abe4a6689e  ***
74   Found device "DS18B20", getting sensor data
75   [00:00:00.000,039] <dbg> w1_serial: w1_serial_init: w1-serial initialized, with 1 devices
76   [00:00:00.015,140] <dbg> DS18B20: ds18b20_init: Using external power supply: 1
77   [00:00:00.021,213] <dbg> DS18B20: ds18b20_init: Init DS18B20: ROM=28b1bb3f070000b9
78
79   Temp: 25.040000
80   Temp: 25.030000
81