A DS18B20 probe and a XIAO ESP32S3 make a compact water or soil thermometer. Wire the probe to 3V3, GND and D1, with a 4.7 kΩ pull-up from D1 to 3V3.
The sketch counts probes at start-up and prints the first one’s temperature every second.
Wiring
| XIAO ESP32S3 | DS18B20 (1-Wire) | Wire | Notes |
|---|---|---|---|
| 3V3 | VDD | red | |
| D1 | 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
- D1 is GPIO2 on the XIAO S3.
OneWire oneWire(D1)uses the right pin;OneWire oneWire(1)would be GPIO1, the pad printed D0. - Keep the pull-up off D2 (GPIO3), the only strapping pin on the XIAO S3’s edge.
- OneWire 2.3.8 supports the S3, so DallasTemperature works as on any ESP32.
Code
// DS18B20 probe on a Seeed XIAO ESP32S3.
// VDD → 3V3, DQ → D1 (GPIO2) with a 4.7 kΩ pull-up to 3V3, GND → GND.
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(D1);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(115200);
uint32_t t0 = millis();
while (!Serial && millis() - t0 < 3000) {}
sensors.begin();
Serial.printf("DS18B20 on D1 (GPIO2) - %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 ESP32S3.
// VDD → 3V3, DQ → D1 (GPIO2) with a 4.7 kΩ pull-up to 3V3, GND → GND.
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(D1);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(115200);
uint32_t t0 = millis();
while (!Serial && millis() - t0 < 3000) {}
sensors.begin();
Serial.printf("DS18B20 on D1 (GPIO2) - %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 D1 (GPIO2) - 1 sensor(s) found
Temperature: 25.94 C
Temperature: 26.00 CDS18B20 on D1 (GPIO2) - 1 sensor(s) found Temperature: 25.94 C Temperature: 26.00 C
Common errors
Reads −127 °C
Pull-up missing or DQ on another pad. Full fix.
Readings stop after a while on battery
Long cable and low battery. Keep the cable short or use 2.2 kΩ.