In short

Choose the DS18B20 probe for temperature alone, in water, soil or anywhere wet: it reads -55 to +125 °C, ±0.5 °C from -10 to +85 °C, and many probes share one pin by their 64-bit codes (Maxim DS18B20 datasheet, pp. 1, 19). Choose the DHT22 when you also need humidity, 0 to 100 %RH at ±2 %RH, but it measures air only, reads -40 to 80 °C and needs its own pin per sensor (Aosong AM2302/DHT22 datasheet, pp. 1, 2). Both run on 3.3 V to 5.5 V with a pull-up on the data line.

Side by side

DS18B20DHT22
MeasuresMaxim DS18B20 datasheet, p. 1; Aosong AM2302/DHT22 datasheet, p. 1TemperatureTemperature and relative humidity
Temperature rangeMaxim DS18B20 datasheet, p. 1; Aosong AM2302/DHT22 datasheet, p. 1-55 °C to +125 °C-40 °C to 80 °C
Temperature accuracyMaxim DS18B20 datasheet, pp. 1, 19; Aosong AM2302/DHT22 datasheet, p. 1±0.5 °C from -10 to +85 °C, ±2 °C over full range±0.5 °C
ResolutionMaxim DS18B20 datasheet, p. 3; Aosong AM2302/DHT22 datasheet, p. 19 to 12 bits, 0.0625 °C at 12 bits0.1 °C, 0.1 %RH
Reading timeMaxim DS18B20 datasheet, p. 1; Aosong AM2302/DHT22 datasheet, p. 3750 ms max per 12-bit conversion2 s minimum between reads
BusMaxim DS18B20 datasheet, p. 1; Aosong AM2302/DHT22 datasheet, p. 2Dallas 1-Wire, unique 64-bit code, many sensors per pinOwn single-wire protocol, not 1-Wire compatible, one sensor per pin
SupplyMaxim DS18B20 datasheet, p. 1; Aosong AM2302/DHT22 datasheet, pp. 1, 23.0 V to 5.5 V, or parasite power from DATA3.3 V to 5.5 V
CurrentMaxim DS18B20 datasheet, p. 19; Aosong AM2302/DHT22 datasheet, p. 51 to 1.5 mA converting, 750 nA typical standby1 to 1.5 mA measuring, 40 to 50 µA standby
Pull-up on dataMaxim DS18B20 datasheet, p. 6; Aosong AM2302/DHT22 datasheet, p. 44.7 kΩ to VDDRequired; 10 kΩ is the usual value

Which one to pick

Pick the DS18B20 when
  • Liquids, aquariums, soil, freezers and outdoor enclosures: the sealed probe goes where a DHT22 cannot, from -55 to +125 °C (Maxim DS18B20 datasheet, p. 1).
  • Several temperature points on one pin, each addressed by its 64-bit code (p. 1).
  • Faster updates than a DHT22: a 12-bit reading every 750 ms or less (p. 1), quicker still at lower resolution.
Pick the DHT22 when
  • Any project that needs relative humidity: rooms, greenhouses, dehumidifier control (0 to 100 %RH at ±2 %RH, Aosong AM2302/DHT22 datasheet, p. 1).
  • Air temperature and humidity from one part and one pin.
  • When the second sensor would be a hygrometer anyway, replacing a DS18B20 plus a humidity sensor.

Swapping one for the other

What changes in the wiring and the code.

  • The protocols differ even though both use one data wire: the DS18B20 is Dallas 1-Wire, which Aosong states the DHT22 is not compatible with (DHT22 datasheet, p. 2). Use OneWire with DallasTemperature for the probe, the DHT library for the DHT22.
  • Keep a pull-up: 4.7 kΩ from DATA to VCC for the DS18B20 (Maxim datasheet, p. 6), 10 kΩ is the usual value for the DHT22. One resistor serves a whole DS18B20 bus.
  • Check the probe's colours: red is VCC, black or blue GND, yellow or white DATA, and batches differ, so verify before powering up.
  • Change the timing: request a conversion and wait up to 750 ms for the DS18B20 (p. 1), or leave 2 s between DHT22 reads (DHT22 datasheet, p. 3).
  • On 3.3 V boards power either sensor and its pull-up from 3.3 V so the data line never rises above the GPIO's level.

DS18B20 or DHT22: questions

Which is more accurate for temperature?

Both are specified at ±0.5 °C: the DS18B20 from -10 to +85 °C (Maxim DS18B20 datasheet, p. 1), the DHT22 over its range (Aosong AM2302/DHT22 datasheet, p. 1). The DS18B20 reads a wider span, -55 to +125 °C, with 0.0625 °C steps at 12 bits (p. 3).

Can the DHT22 go in water?

No. Its humidity element must be exposed to the air it measures. For liquids use the stainless-steel DS18B20 probe, which reads temperature only.

Can I put a DS18B20 and a DHT22 on the same pin?

No. The DHT22's protocol is not compatible with Dallas 1-Wire (DHT22 datasheet, p. 2), so it needs its own pin. Several DS18B20 probes can share one pin, each found by its 64-bit code (Maxim datasheet, p. 1).

Why does my DS18B20 read 85 °C or -127 °C?

+85 °C is the register's power-on value, read before a conversion finished (Maxim datasheet, p. 4). -127 °C is the DallasTemperature library's code for a sensor it cannot reach: check the 4.7 kΩ pull-up (p. 6) and the wire colours.

Do both work on an ESP32?

Yes. The DS18B20 runs from 3.0 V to 5.5 V and the DHT22 from 3.3 V to 5.5 V (Maxim datasheet, p. 1; DHT22 datasheet, pp. 1, 2). Power them and their pull-ups from 3.3 V.

The two references

Checked on 2026-10-29 against 2 sources, the makers’ datasheets first.

For AI assistants

This comparison as plain Markdown. /compare/ds18b20-waterproof-vs-dht22.md

What will you build with it?