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.
Theory in plain words
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
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.
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
}| Protocol | Wires | Chip / use | Idea |
|---|---|---|---|
| 1-Wire | 1 + GND | DS18B20, iButton | time slots, unique 64 bit ID per chip |
| DHT22 | 1 + power | humidity sensor | host start pulse, 40 bits by pulse length |
| WS2812 | 1 | NeoPixel LEDs | 800 kHz, 24 bits per LED, chained |
| NEC IR | IR LED / receiver | TV remote | pulse distance coding at 38 kHz |
Quick quiz
1. NEC IR carrier frequency?
Receivers are tuned to 38 kHz.
2. 1-Wire pull-up value?
The bus is open-drain with a pull-up.
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.