Arduino 1-Wire communication protocol

The 1-Wire bus can handle multiple uniquely addressed devices over a single data line. This tutorial introduces the communication sequence, device identification and the key points involved in using 1-Wire with Arduino.

Difficulty: Beginner

Created: June 2023

Technically reviewed: August 2026

Reference platform: Arduino Uno family / general Arduino API

After Serial communication, I²C and SPI, we will explore another bus with a different operating model. 1-Wire allows us to communicate with one or more compatible devices over a single data line.

In this lesson, we will examine the structure of the 1-Wire bus, unique device identification, the basic communication sequence, power-supply options and use of the Arduino OneWire library.

The DS18B20 temperature sensor is a common 1-Wire device, but it is mentioned here only as an example. Temperature measurement and detailed use of the DallasTemperature library will be covered in a separate practical lesson.

What is 1-Wire?

1-Wire is a short-range, bidirectional serial communication bus. It was originally developed by Dallas Semiconductor; the technology later became part of the Maxim Integrated and subsequently the Analog Devices product families.

The fundamental characteristic of the bus is that it uses a single data line for communication. A common reference is also required between separate circuits, so the basic connection consists of at least:

  • DQ or DATA: the bidirectional data line;
  • GND: the common ground.

A normally powered device also requires a separate supply line. Some 1-Wire devices can obtain energy from the data line; this is known as parasite power.

The term “one wire” therefore refers to the communication data line. It does not mean that literally one physical connection is sufficient between two separate circuits.

Controller and target devices

On a 1-Wire bus, a controller initiates and times the communication. In this lesson, the Arduino performs this role.

One or more target devices can be connected to the bus. Older documentation often uses the terms master and slave instead of controller and target.

1-Wire communication is strictly timed. The controller initiates the reset sequence and data time slots, while target devices respond within the time windows defined by the protocol.

Bus structure

Multiple compatible devices can be connected to the same data line and common GND:

Arduino DATA ─────┬──── 1-Wire device 1
                  ├──── 1-Wire device 2
                  └──── 1-Wire device 3

Arduino GND ──────┴──── common GND

The devices do not require separate data lines to the Arduino. The controller can select them using their unique ROM identifiers.

The role of the pull-up resistor

The 1-Wire data line is HIGH when idle. Bus participants pull the line LOW and then release it, while a pull-up resistor connected to the supply voltage restores the HIGH level.

VCC
 │
[R pull-up]
 │
 ├──────── DATA
 │
 ├──────── 1-Wire device 1
 ├──────── 1-Wire device 2
 └──────── Arduino

For short, simple circuits, 4.7 kΩ is a common starting value, but it is not a universal rule. The suitable value is influenced by factors including:

  • the supply and logic voltage;
  • the capacitance of the wires and connectors;
  • the physical length and topology of the bus;
  • the number of devices;
  • the communication speed;
  • the requirements in the data sheets of the devices used;
  • the use of parasite power.

The resistor value must not be determined solely from the wire length. If the resistance is too high, the signal may rise too slowly. If it is too low, the bus participants must sink excessive current to produce a LOW level.

Multidrop 1-Wire bus with a shared data line, pull-up resistor, common GND, and externally powered and parasite-powered devices
Multiple devices can share the same data line on a 1-Wire bus. A pull-up resistor establishes the HIGH level; devices can use a separate power supply or, if supported, parasite power.

External power

With external power, the 1-Wire device receives a separate supply connection:

  • DATA;
  • VCC;
  • GND.

The data line must still have a pull-up resistor connected to the appropriate voltage.

A separate power supply is generally the simpler and more reliable choice. Operations requiring more energy do not rely exclusively on power obtained from the data line, making it easier to use the bus for other communication during this period.

Parasite power

Some 1-Wire devices can operate without a separate VCC connection. While the data line is HIGH, an internal energy-storage element in the device is charged and then supplies the device while the line is LOW.

This can reduce the required number of wires, but it also introduces practical limitations:

  • not every 1-Wire device supports it;
  • some device operations may require more current than usual;
  • a simple passive pull-up resistor may not supply enough current;
  • a strong pull-up may then be required as specified in the device’s data sheet;
  • the bus may not be available for other communication while the strong pull-up is active;
  • the available energy margin may decrease on longer networks or networks with higher capacitance;
  • failures may occur intermittently and depend on load and transmitted data.

The optional second parameter of the OneWire library’s write() function can request that the data line remain actively driven HIGH after the write:

oneWire.write(command, 1);

This is not a general substitute for a correctly designed power supply. The need for a strong pull-up, its duration and its electrical implementation must always be determined from the device’s data sheet, the Arduino platform in use and the library’s current platform support.

If the program does not immediately start another read or write operation after requesting active power, the library’s depower() function can stop the active drive:

oneWire.depower();

The unique 64-bit ROM identifier

Every 1-Wire device has a factory-programmed, unique 64-bit ROM identifier. This allows multiple devices to operate on the same bus.

The ROM identifier consists of eight bytes:

PartSizePurpose
Family code8 bitsIdentifies the device family
Serial number48 bitsUniquely identifies the device
CRC8 bitsChecks the integrity of the ROM code

The family code does not replace the complete device identifier. For example, multiple DS18B20 devices can have the same family code while their 48-bit serial numbers differ.

The final byte of the ROM code allows a CRC check. If the calculated CRC does not match the value stored in the ROM, the address must not be used as a valid result.

Reset and presence pulse

1-Wire communication begins with a reset and presence-detection sequence:

  1. the controller pulls the bus LOW for a defined period;
  2. it releases the data line, which the pull-up resistor begins to raise to the HIGH level;
  3. a target device that is present pulls the bus LOW again briefly;
  4. this is called a presence pulse.

The presence pulse indicates that at least one compatible device responded. It does not identify which device responded and does not prove that all functions of the device are operating correctly.

The OneWire library’s reset() function performs this sequence:

uint8_t presenceDetected = oneWire.reset();

if (presenceDetected)
{
    Serial.println("At least one 1-Wire device responded.");
}
else
{
    Serial.println("No presence pulse was detected.");
}

A zero result does not necessarily mean that no device is connected. Incorrect wiring, a short circuit, an unsuitable pull-up, a power-supply problem or a timing error can produce the same result.

Why timing matters

The 1-Wire bus transfers bits in time slots. The controller starts every read and write time slot by briefly pulling the data line LOW.

The signal value is determined by when the participants pull the line LOW and when they release it. Correct operation therefore depends not only on logic levels but also on the timing of the operations.

In an Arduino program, this timing is normally handled by the OneWire library. We should not attempt to replace the library’s protocol operations with our own general-purpose delays.

Time-critical operation can be affected by factors including:

  • the Arduino platform being used;
  • the library implementation for that platform;
  • interrupt handlers that run for too long;
  • the operation of other time-critical libraries;
  • slow signal rise caused by bus capacitance;
  • electrical noise and unsuitable wiring.
Simplified timing sequence of the 1-Wire reset, presence pulse, write slot and read slot
1-Wire communication begins with a reset and presence-pulse sequence, followed by bit writes and reads in time slots initiated by the controller.

The principle of ROM commands

After the reset and presence pulse, the controller uses a ROM command to determine which device or devices it wants to communicate with.

ROM commandCodeBasic purpose
Search ROM0xF0Discovers the ROM identifiers of devices on the bus
Read ROM0x33Reads the ROM code of a single device; it cannot be used for general identification on a multidrop bus
Match ROM0x55Selects a specific device using its complete ROM code
Skip ROM0xCCSkips individual ROM selection; it is safe only when the following device command will not make simultaneous responses from multiple devices ambiguous

The ROM command is followed by function commands specific to the selected device family. Their meanings are always defined by the relevant device’s data sheet.

The Arduino OneWire library

The Arduino software does not automatically include the OneWire library in every installation. If it is not installed, search for the OneWire library in the Arduino IDE Library Manager and check its author, version and compatibility with the board being used.

Include the library header at the beginning of the program:

#include <OneWire.h>

Next, create a OneWire object and specify the digital pin used for the data line:

const uint8_t oneWirePin = 10;
OneWire oneWire(oneWirePin);

One OneWire object manages one bus. If we use several independent 1-Wire buses on separate pins, each bus requires its own object.

Pin 10 is only an example. Select the actual pin according to the board being used, the library’s platform support and the other peripherals in the project.

The most important library operations

OperationPurpose
reset()Performs the reset/presence sequence
search(address)Finds the next device’s eight-byte ROM code
reset_search()Resets the library’s internal search state
select(address)Selects a specific device using Match ROM
skip()Sends the Skip ROM command
write(value)Writes one byte
read()Reads one byte
crc8(data, length)Calculates the Dallas/Maxim CRC-8
depower()Stops the active HIGH drive requested after a write

The select(), skip(), write() and read() operations cannot be used in an arbitrary order. The required reset, ROM selection and device command must follow the communication sequence defined for the relevant device.

Searching for devices and reading ROM addresses

The following program searches for devices on the bus, checks the CRC of each ROM code and prints valid identifiers in hexadecimal form to the Serial Monitor.

#include <OneWire.h>

const uint8_t oneWirePin = 10;

OneWire oneWire(oneWirePin);

void printRomAddress(const uint8_t address[8])
{
    for (uint8_t index = 0; index < 8; index++)
    {
        if (address[index] < 0x10)
        {
            Serial.print('0');
        }

        Serial.print(address[index], HEX);

        if (index < 7)
        {
            Serial.print(':');
        }
    }
}

void scanBus()
{
    uint8_t address[8];
    uint8_t deviceCount = 0;

    oneWire.reset_search();

    while (oneWire.search(address))
    {
        Serial.print("Found: ");
        printRomAddress(address);

        if (OneWire::crc8(address, 7) != address[7])
        {
            Serial.println(" - ROM CRC error");
            continue;
        }

        Serial.print(" - family code: 0x");

        if (address[0] < 0x10)
        {
            Serial.print('0');
        }

        Serial.println(address[0], HEX);
        deviceCount++;
    }

    if (deviceCount == 0)
    {
        Serial.println("No valid 1-Wire device found.");
    }
    else
    {
        Serial.print("Number of valid devices: ");
        Serial.println(deviceCount);
    }

    oneWire.reset_search();
}

void setup()
{
    Serial.begin(9600);
    delay(1000);

    Serial.println("Starting 1-Wire bus scan.");
    scanBus();
}

void loop()
{
}

Open the Serial Monitor at 9600 baud.

What does the program do?

  1. reset_search() prepares a new search.
  2. On each successful call, search(address) returns the eight-byte ROM code of the next device found.
  3. The program checks the CRC calculated from the first seven bytes of the ROM code.
  4. It prints the valid address and family code in hexadecimal form.
  5. The search ends when there are no more results.

The search order is deterministic, but it does not replace a persistent, unambiguous association between ROM addresses and physical devices. If a project must know which identifier belongs to which sensor, document or configure this separately during installation.

A successful search shows that the library could read a valid ROM code. It does not prove that all application functions of the device operate correctly.

Selecting a specific device

If several devices are present on the bus, communication typically begins as follows:

uint8_t address[8] =
{
    0x28, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00
};

if (oneWire.reset())
{
    oneWire.select(address);

    // The command defined by the device data sheet follows here.
}

The ROM code in this example illustrates only the required format; it is not a real device address. In your program, use a complete address discovered by the scanner and verified by CRC.

select(address) transmits the Match ROM command and the eight-byte address. The following device-specific command is therefore addressed to the selected target device.

Using skip()

skip() omits selection by an individual ROM address:

if (oneWire.reset())
{
    oneWire.skip();

    // The device command follows here.
}

This does not automatically mean that only one device on the bus will respond. When several devices are present, a command issued after Skip ROM may affect all of them, and simultaneous responses may collide or produce an ambiguous result.

Before using skip(), always check the relevant device’s data sheet and verify how many compatible devices are actually operating on the bus.

Wiring and topology

1-Wire does not have a universal maximum bus length that applies to every installation. Reliability is determined jointly by:

  • the total wire length;
  • the capacitance of the cable and connectors;
  • the length and number of branches;
  • the network topology;
  • the pull-up arrangement;
  • the number of devices;
  • the power-supply mode;
  • electrical noise;
  • grounding and voltage levels;
  • the drive and timing capabilities of the controller.

For short, simple circuits, start with a line-shaped main cable and short branches. Long star-shaped branches can cause signal reflections and unreliable operation.

On larger networks, do not try to conceal topology problems solely by changing the resistor. Suitable cable, shorter branches, an active pull-up, a dedicated 1-Wire controller or division of the network into multiple buses may be required.

Voltage levels and Arduino platforms

The HIGH level of the bus is determined by the voltage to which the pull-up resistor is connected. Before connecting the Arduino and a 1-Wire device, check:

  • the logic level and current capability of the Arduino pin being used;
  • the permitted supply and data-line voltage of the 1-Wire device;
  • the voltage to which the pull-up resistor is connected;
  • the presence of a common GND;
  • whether level shifting is required.

The same general OneWire API can be used on the Uno R3 and Uno R4 when the installed library version supports the relevant board core. The internal time-critical implementation is platform-dependent, however, so AVR-specific details must not be treated as rules that apply to every Arduino board.

Common problems and troubleshooting

No device is found

  • Check the common GND.
  • Check the Arduino pin assigned to the data line.
  • Inspect the pull-up resistor and its supply voltage.
  • Check the device’s power supply and pinout.
  • Try short wires and a single device.
  • Verify that the library supports the Arduino board being used.

ROM CRC error

A CRC error indicates that the eight bytes read do not form a valid ROM code. Possible causes include noise, an unsuitable pull-up, excessive bus capacitance, a poor connection or a timing disturbance.

Do not store or use a ROM address with a CRC error as a device identifier.

The device disappears intermittently

Intermittent failure is particularly likely on a long, branched or parasite-powered bus. Check whether the failure occurs during an energy-intensive operation, and test the device with a separate power supply.

Only one of several devices works

Check that the program actually selects devices using their complete ROM addresses. Do not use Read ROM or Skip ROM in a situation where simultaneous responses from multiple devices can cause a collision.

The scanner works, but the application does not

The ROM search checks only device identification. Application commands, register or scratchpad formats, CRC, conversion times and power requirements are device-specific and must be implemented according to the relevant data sheet.

🧪 Try it!

1. Check the presence pulse

Run the reset() example first with a device connected and then with the data line disconnected. Observe how the return value changes.

2. Search for ROM addresses

Connect a known 1-Wire device and run the scanner. Record the complete eight-byte ROM address and the family code.

3. Multiple devices on one bus

If you have two compatible devices, connect them to the same data line. Check whether the scanner finds two different, valid ROM addresses.

4. Investigate a wiring problem

Document the wire length, topology, supply voltage and pull-up resistor of a working circuit. If operation becomes unreliable, change only one factor at a time and then run the scanner again.

Summary

In this lesson, we learned that:

  • 1-Wire is a serial communication bus using one bidirectional data line;
  • a common GND is also required between separate circuits;
  • a pull-up resistor establishes the HIGH level of the bus;
  • one controller can communicate with multiple target devices on the same bus;
  • every device has a unique 64-bit ROM identifier;
  • the ROM code consists of a family code, serial number and CRC;
  • communication begins with a reset and presence-pulse sequence;
  • data is transferred in timed read and write slots;
  • ROM commands allow devices to be discovered or selected;
  • external power and parasite power have different practical requirements;
  • parasite power may require a strong pull-up during energy-intensive operations;
  • wire length, topology, capacitance, pull-up and device count jointly affect reliability;
  • the Arduino OneWire library handles the time-critical protocol operations;
  • search() allows us to read the ROM addresses of devices on the bus;
  • a ROM address must not be considered valid without a CRC check;
  • application commands for specific sensors must always be used according to their data sheets.

← Further Arduino Tutorials