<!-- Source: https://docs.smartcitizen.me/knowledge/air/temperature_rel_humidity/DS18B20/ -->

# Dallas DS18B20

One-wire weather-proof temperature sensor.

![](https://docs.smartcitizen.me/assets/images/dallas-ds18b20.png){.banner-box}

_Image Credit: **Seeed Studio**_{.image-credit-banner-box}

!!! warning "Experimental support"
    The DS18B20 is not enabled in any of the default firmware builds. To use it, you need to compile the firmware with one of the flags described [below](#usage-and-considerations). Check the guide on [enabling additional features](https://docs.smartcitizen.me/guides/firmware/enabling-additional-features.md).

## Working principle

The DS18B20 is a digital temperature sensor, originally by Dallas Semiconductor (now part of Analog Devices). It measures temperature with an integrated sensor and converts it into a digital value with a configurable resolution from 9 to 12 bits [^1].

It communicates using the **1-Wire** protocol: data and commands go through a single data line, and several sensors can share the same line, since each one has a unique 64-bit address. This makes it very simple to wire, even with long cables.

The sensor is very popular in a **waterproof probe** format: the chip is sealed inside a stainless steel tube at the end of a cable, which makes it suitable for measuring the temperature of water, soil, or air in harsh environments.

## Usage and considerations

There are two ways to connect a DS18B20 to the SCK, each with its own firmware flag:

| Flag | Connection | Shell name | Units | API |
|:- |:- |:- |:-: |:- |
| `SCK_WITH_DALLAS_TEMP` | Directly to the [Auxiliary connector](https://docs.smartcitizen.me/hardware/boards/data-board.md#auxiliary-connector) | `Direct Dallas Temperature` | ºC | [96](https://api.smartcitizen.me/v0/sensors/96) |
| `SCK_WITH_DS18B20` | Through a [DS2482-100](https://www.analog.com/en/products/ds2482-100.html) I2C to 1-Wire bridge (I2C address `0x18`) | `DS18B20 Water temperature` | ºC | [42](https://api.smartcitizen.me/v0/sensors/42) |

### Direct connection

With `SCK_WITH_DALLAS_TEMP`, the sensor is connected directly to the Auxiliary connector, and the firmware uses the `SCL` pin of the connector as the 1-Wire data line. You can use a [grove to screw connector](https://docs.smartcitizen.me/guides/getting-started/third-party-sensors.md#sensors-with-open-leads) to connect a waterproof probe:

| DS18B20 wire | Auxiliary connector pin |
|:- |:- |
| Data (normally yellow) | `SCL` |
| VDD (normally red) | `VCC` (3.3V) |
| GND (normally black) | `GND` |

!!! warning "Pull-up resistor"
    The 1-Wire data line needs a pull-up resistor (typically 4.7kΩ) between the data and VCC lines. Many breakout modules for waterproof probes already include it. If you are using a bare probe, add it to your connection.

!!! info "Other auxiliary sensors"
    In this mode, the `SCL` line of the Auxiliary connector is shared with the I2C sensors. If you see problems with other auxiliary sensors, use the DS2482-100 bridge instead.

The firmware reads the first sensor found on the line, with a resolution of 12 bits.

### Through an I2C bridge

With `SCK_WITH_DS18B20`, the sensor is connected to a DS2482-100 I2C to 1-Wire bridge, which is connected to the Auxiliary connector as any other I2C sensor. This keeps the 1-Wire line separate from the I2C bus.

You can check the readings with the `read` and `monitor` commands, for instance:

```
read direct dallas temperature
```

### Performance

|Property               |Value                                                                          |
|:-                     |:-                                                                             |
|Sensor type            |Digital temperature sensor with 1-Wire interface                               |
|Measurement range      |-55 ºC – 125 ºC                                                                |
|Accuracy               |±0.5 ºC (from -10 ºC to 85 ºC)                                                 |
|Resolution             |0.0625 ºC (12 bits)                                                            |

### Limitations

- In the waterproof probe format, the steel tube and the cable add some thermal inertia, so the sensor responds slowly to fast temperature changes
- When measuring air temperature, the probe needs to be protected from direct sunlight, otherwise it will measure a higher temperature than the air
- There are many counterfeit DS18B20 sensors in the market, which might not meet the specifications of the datasheet

## Resources

- [Official product page and datasheet](https://www.analog.com/en/products/ds18b20.html)
- [Firmware implementation](https://github.com/fablabbcn/smartcitizen-kit-2x/blob/master/sam/src/SckAux.cpp)

### References

[^1]:
    Analog Devices. “DS18B20 Programmable Resolution 1-Wire Digital Thermometer - Datasheet.” https://www.analog.com/en/products/ds18b20.html.