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 Mini | DS18B20 (1-Wire) | Wire | Notes |
|---|---|---|---|
| 3V3 | VDD | red | |
| 16 | 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
- 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 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);
}// 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
DS18B20 on GPIO16 - 1 sensor(s) found
Temperature: 25.81 C
Temperature: 25.87 CDS18B20 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.