The DS18B20 probe is sealed in steel, so it can sit in a water tank, an aquarium or soil. On the XIAO ESP32C3 it needs one data pin — D3 — and one 4.7 kΩ pull-up to 3V3.
The sketch counts the probes on the bus at start-up and prints the first probe’s temperature every second.
Wiring
| XIAO ESP32C3 | DS18B20 (1-Wire) | Wire | Notes |
|---|---|---|---|
| 3V3 | VDD | red | |
| D3 | DQ | yellow | |
| 3V3 | DQ | red | Via 4.7 kΩ — Pull-up between DQ and 3V3. |
| GND | GND | black |
3.0–5.5 V part, 3.3 V board. Power it from your board's logic voltage (3.3 V on ESP32/Pico, 5 V on Uno) so DQ never goes above the GPIO limit. DQ needs a 4.7 kΩ pull-up to that same supply.
Board quirks
- D3 is GPIO5. It is the C3’s ADC2 pin, which only matters for analog readings — for a digital 1-Wire bus it is a good, boot-safe choice.
- Avoid D0, D8 and D9 for the bus: they are strapping pins, and D9 is the BOOT button.
- The XIAO’s 3V3 regulator easily powers several probes (about 1.5 mA each while converting).
Code
// DS18B20 probe on a Seeed XIAO ESP32C3.
// VDD → 3V3, DQ → D3 (GPIO5) with a 4.7 kΩ pull-up to 3V3, GND → GND.
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(D3);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(115200);
delay(1500);
sensors.begin();
Serial.printf("DS18B20 on D3 (GPIO5) - %u sensor(s) found\n", sensors.getDeviceCount());
}
void loop() {
sensors.requestTemperatures();
float t = sensors.getTempCByIndex(0);
if (t == DEVICE_DISCONNECTED_C) Serial.println("No sensor answered - check the 4.7 kOhm pull-up");
else Serial.printf("Temperature: %.2f C\n", t);
delay(1000);
}// DS18B20 probe on a Seeed XIAO ESP32C3.
// VDD → 3V3, DQ → D3 (GPIO5) with a 4.7 kΩ pull-up to 3V3, GND → GND.
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(D3);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(115200);
delay(1500);
sensors.begin();
Serial.printf("DS18B20 on D3 (GPIO5) - %u sensor(s) found\n", sensors.getDeviceCount());
}
void loop() {
sensors.requestTemperatures();
float t = sensors.getTempCByIndex(0);
if (t == DEVICE_DISCONNECTED_C) Serial.println("No sensor answered - check the 4.7 kOhm pull-up");
else Serial.printf("Temperature: %.2f C\n", t);
delay(1000);
}Library: DallasTemperature (Miles Burton (also install OneWire by Jim Studt / Paul Stoffregen)) — compiled with OneWire 2.3.8.
Expected serial output
DS18B20 on D3 (GPIO5) - 1 sensor(s) found
Temperature: 24.88 C
Temperature: 24.94 CDS18B20 on D3 (GPIO5) - 1 sensor(s) found Temperature: 24.88 C Temperature: 24.94 C
Common errors
Reads −127 °C
Pull-up missing or DQ on the wrong pad. Full fix.
Serial Monitor blank after upload
Press RESET once and reopen the port; the C3’s native USB re-enumerates after flashing.