Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.

DS18B20 with LOLIN S2 Mini — wiring and code

Read a DS18B20 waterproof probe on GPIO16 (the D1 mini D4 position) of a LOLIN S2 Mini with a 4.7 kΩ pull-up to 3V3.

Arduino C++Verified — core esp32 3.3.12, OneWire 2.3.8, 3 Nov 2026Compile-only

Community draft — report a mistake

DS18B20 probes are the standard for tank and pipe temperatures. On the S2 Mini use GPIO16 — the same position as D4 on a D1 mini — with a 4.7 kΩ pull-up to 3V3.

The sketch counts the probes at start-up and prints the first one’s temperature every second.

Wiring

LOLIN S2 MiniOnly the pins used are shown · 3.3 V logicDS18B20 (1-Wire)4.7k → 3V33V316 · 16GNDGNDDQVDD
Also needed: 4.7 kΩ resistor.
Every connection
LOLIN S2 MiniDS18B20 (1-Wire)WireNotes
3V3VDDred
16DQyellow
3V3DQredVia 4.7 kΩ — Pull-up between DQ and 3V3.
GNDGNDblack

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

  • GPIO16 is in the D1 mini’s D4 position, the usual DS18B20 pin on D1 mini shields. On the S2 it has no boot role (unlike D4/GPIO2 on the ESP8266).
  • GPIO18 next to it has a 10 kΩ on-board pull-up. That also works for a short single probe, but 4.7 kΩ on GPIO16 is more reliable for long cables and several probes.
  • OneWire 2.3.8 supports the S2’s GPIO registers, so the usual DallasTemperature code runs unchanged.

Code

ds18b20-s2mini.inoArduino C++Open in PlaygroundOpen in PlaygroundFlash
// DS18B20 probe on a LOLIN S2 Mini.
// VDD → 3V3, DQ → GPIO16 with a 4.7 kΩ pull-up to 3V3, GND → GND.
#include <OneWire.h>
#include <DallasTemperature.h>

constexpr uint8_t ONE_WIRE_PIN = 16;
OneWire oneWire(ONE_WIRE_PIN);
DallasTemperature sensors(&oneWire);

void setup() {
  Serial.begin(115200);
  uint32_t t0 = millis();
  while (!Serial && millis() - t0 < 3000) {}
  sensors.begin();
  Serial.printf("DS18B20 on GPIO16 - %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

Serial Monitor · 115200Output
DS18B20 on GPIO16 - 1 sensor(s) found
Temperature: 25.81 C
Temperature: 25.87 C

Common errors

Reads −127 °C

Pull-up missing or DQ on the wrong pad. Full fix.

No COM port after upload

Hold the 0 button, press RST, release 0 to force download mode, then upload again.

↑↓ to move · Enter to open