Home / Learn Chip Programming / 1-Wire, IR Remote and Other Simple Protocols

1-Wire, IR Remote and Other Simple Protocols

Single-wire protocols like DS18B20 and the NEC infrared remote.

In shortSingle-wire protocols like DS18B20 and the NEC infrared remote.

Theory in plain words

NEC IR frame9 ms leader burst4.5 ms spaceaddress (8 bit + inverse)command (8 bit + inverse)final burst
NEC IR frame

What it is

1-Wire carries power and data on a single line with an open-drain bus and 4.7 k pull-up. Each chip has a 64 bit ROM ID. NEC IR encodes bits by the length of the gap between 560 us bursts on a 38 kHz carrier.

Why we use it

Many cheap parts use these timing-based protocols: temperature probes, TV remotes, WS2812 LEDs, DHT22.

How it works

Master sends reset pulse, devices answer with presence pulse, then bits are time slots. IR receivers (VS1838) demodulate 38 kHz so your MCU sees clean pulses.

Where it is used

  • DS18B20 temperature probes
  • IR remote control of projects
  • WS2812 (NeoPixel) LED strips

NEC remote decoder

Encode a command and see the pulse timingTry it Yourself

In firmware you measure the gaps with input capture (previous lesson) and decide 0 or 1 by comparing to a threshold near 1.1 ms.

Decode NEC by gap length
uint32_t nec_decode(const uint16_t *gap_us /* 32 values */) {
    uint32_t v = 0;
    for (int i = 0; i < 32; i++)
        if (gap_us[i] > 1100) v |= (1UL << i);        // long gap = 1, short gap = 0
    uint8_t cmd = (v >> 16) & 0xFF, ncmd = (v >> 24) & 0xFF;
    return (cmd == (uint8_t)~ncmd) ? cmd : 0xFFFF;     // 0xFFFF = error
}
ProtocolWiresChip / useIdea
1-Wire1 + GNDDS18B20, iButtontime slots, unique 64 bit ID per chip
DHT221 + powerhumidity sensorhost start pulse, 40 bits by pulse length
WS28121NeoPixel LEDs800 kHz, 24 bits per LED, chained
NEC IRIR LED / receiverTV remotepulse distance coding at 38 kHz

Quick quiz

1. NEC IR carrier frequency?

2. 1-Wire pull-up value?

Common questions

NEC IR carrier frequency?

38 kHz. Receivers are tuned to 38 kHz.

1-Wire pull-up value?

About 4.7 k. The bus is open-drain with a pull-up.