OneWire (verified community library)


Name Value
Name OneWire
Version 2.0.4
Installs 756257
Verification verified
License MIT
Author Hotaman, Julien Vanier
Download .tar.gz
All Versions 2.0.4, 2.0.3, 2.0.2, 2.0.1, 2.0.0, 1.4.1

Dallas 1-Wire protocol with support for DS18B20, DS1820, DS1822

Example Build Testing

Device OS Version:

This table is generated from an automated build. Success only indicates that the code compiled successfully.

Library Read Me

This content is provided by the library maintainer and has not been validated or approved.

One Wire

The One Wire (1-Wire) protocol is used in the popular DS18B20 temperature sensor and other devices from Maxim (formerly Dallas).

This library implements the Dallas One Wire (1-wire) protocol on the Particle Photon, Electron, Core, P0/P1, Red Bear Duo and compatible devices.


If you are using a DS18B20, DS1820 or DS1822 temperature sensor, you can simply use the DS18 object to read temperature.

Connect sensor:

  • pin 1 (1-Wire ground) to ground.
  • pin 2 (1-Wire signal) to D0 (or another pin) with a 2K-10K resistor to pin 3.
  • pin 3 (1-Wire power) to 3V3 or VIN.
#include "DS18.h"

DS18 sensor(D0);

void loop() {
if ( {
Particle.publish("temperature", String(sensor.celsius()), PRIVATE);

If you use another chip or you want to customize the behavior you can copy-paste one of the examples and modify it.


DS18 sensor(pin);
DS18 sensor(pin, parasitic);

Create an object to interact with one or more DS18x20 sensors connected to pin (D0-D7, A0-A7, etc).

If parasitic is true, the power will be maintained at the end of a conversion so the sensor can parasitically draw power from the data pin. This mode is discourage since it can be harder to set up correctly. The value of the pull-up resistor is important in parasitic mode. See the references.

Save yourself some trouble, buy some DS18B20 (not DS18B20-PAR) and use the 3 pin powered mode.


bool succes =;

Search for the next temperature sensor on the bus and start a conversion. Return true when the temperature is valid.

The default conversion time is 1 second.

Since it performs a 1-Wire search each time if you only have 1 sensor it's normal for this function to return false every other time.

If you have more than 1 sensor, check addr() to see which sensor was just read.

bool succes =;

Read a specific sensor, skiping the search. You could set up your code to read() once in setup(), save the addr and in loop always read this sensor only.



float temperature = sensor.celsius();
float temperature = sensor.fahrenheit();

Return the temperature of the last read device. Only call after read() returns true.

Note: on the DS18B20, 85 C is returned when there's a wiring issue, possibly not enough current to convert the temperature in parasitic mode. Check the pull up value.


bool done = sensor.searchDone();

If read() returns false, check searchDone(). If true, this is not an error case. The next read() will start from the first temperature sensor again.


bool error = sensor.crcError();

Returns true when bad data was received. ¯\(ツ)


uint8_t addr[8];

Copies the 1-Wire ROM data / address of the last read device in the buffer. All zeros if no device was found or search is done.

See the datasheet for your device to decode this.


DS18Type type = sensor.type();

The type of the last read device. One of WIRE_DS1820, WIRE_DS18B20, WIRE_DS1822, WIRE_DS2438 or WIRE_UNKNOWN if the device is not a temperature sensor, no device was found or the search is done.


int16_t value = sensor.raw();

Integer value of the temperature without scaling. Useful if you want to do integer math on the temperature. The scaling between the raw value and physical value depends on the sensor.


uint8_t data[9];;

Copies the 1-Wire scratchpad RAM / data of the last read device in the buffer. All zeros if there was a CRC error in the address search, no device was fuond or search is done.

See the datasheet for your device to decode this.



This library pauses for 1000 milliseconds while waiting for the temperature conversion to take place. Check the datasheet before reducing this value.


OneWire, the 1-Wire protocol implementation used by the DS18 object, is documented in its header file.



Copyright 2016 Hotaman, Julien, Vanier, and many contributors (see individual files)

Licensed under the MIT license.

Browse Library Files