ESP32 Bench
Boards: ESP32, S3, C3
Flash and monitor: Web Serial
← All projects

DS18B20 to ProbeHarbor

Read a waterproof DS18B20 probe and post the temperature to ProbeHarbor once a minute.

Starter20 min115200 baud
Board
Fig. 1. Pins this project uses on the ESP32-DevKitC V4, 38 pin. USB connector at the bottom.

Wiring

FromTo boardNote
DS18B20 red3V3
DS18B20 blackGND
DS18B20 data, usually yellowGPIO 44.7 kΩ pull-up from data to 3V3

Tested on this board

Not run on this board yet. Treat the wiring and code as a first draft.

Firmware, Arduino sketch for ESP32 Dev Module

/**
 * DS18B20 → ProbeHarbor push ingest (Arduino: ESP32 / ESP8266 / Pico W).
 *
 * Libraries: OneWire, DallasTemperature, WiFi, HTTPClient.
 * Pico W / Pico 2 W: install Earle Philhower’s “Raspberry Pi Pico/RP2040” board package
 * (not the Arduino mbed RP2040 core). GPIO4 is GP4.
 * Set WIFI_SSID, WIFI_PASS, and INGEST_URL (full URL including device key).
 */
#include <OneWire.h>
#include <DallasTemperature.h>

#if defined(ESP32) || defined(ESP8266) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_RP2350)
#include <WiFi.h>
#include <HTTPClient.h>
#else
#error "This sample targets ESP32/ESP8266 or Pico W (Earle Philhower core). Adapt WiFi/HTTP for your board."
#endif

#ifndef WIFI_SSID
#define WIFI_SSID "your-wifi"
#endif
#ifndef WIFI_PASS
#define WIFI_PASS "your-password"
#endif
#ifndef INGEST_URL
#define INGEST_URL "https://probeharbor.dev/api/ingest/YOUR_DEVICE_KEY"
#endif

#ifndef ONE_WIRE_PIN
#define ONE_WIRE_PIN 4
#endif

OneWire oneWire(ONE_WIRE_PIN);
DallasTemperature sensors(&oneWire);

const unsigned long INTERVAL_MS = 60UL * 1000UL;
unsigned long lastPost = 0;

void setup() {
  Serial.begin(115200);
  sensors.begin();
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  Serial.print("WiFi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(400);
    Serial.print(".");
  }
  Serial.println(" ok");
}

bool postTempF(float tempF) {
  if (WiFi.status() != WL_CONNECTED) return false;
  HTTPClient http;
  http.begin(INGEST_URL);
  http.addHeader("Content-Type", "application/json");
  char body[128];
  snprintf(body, sizeof(body), "{\"temp1\":%.2f,\"rssi\":%d}", tempF, WiFi.RSSI());
  int code = http.POST(body);
  Serial.printf("POST %d %s\n", code, body);
  http.end();
  return code >= 200 && code < 300;
}

void loop() {
  unsigned long now = millis();
  if (now - lastPost < INTERVAL_MS) return;
  lastPost = now;

  sensors.requestTemperatures();
  float c = sensors.getTempCByIndex(0);
  if (c == DEVICE_DISCONNECTED_C) {
    Serial.println("DS18B20 disconnected");
    return;
  }
  float f = c * 9.0f / 5.0f + 32.0f;
  postTempF(f);
}

Parts

QuantityPartWhere to buy
1×ESP32 dev boardBuy at Amazon
1×DS18B20 waterproof probeBuy at Adafruit
1×4.7 kΩ resistorBuy at Amazon

Amazon buy links may include an Associates tag, and this site may earn a commission from qualifying Amazon purchases at no extra cost to you. Adafruit links are direct.

Libraries

OneWire, DallasTemperature

Load it

  1. In the Arduino IDE, install the esp32 board package and pick the board named above the sketch.
  2. Install the libraries listed above from the Library Manager.
  3. Paste the sketch, choose the board's port and upload. Hold BOOT if the upload stalls at Connecting.
  4. Close the IDE's serial monitor, then open the bench here to watch the output.

Sketch source on GitHub

Field notes

  • Set WIFI_SSID, WIFI_PASS and INGEST_URL at the top of the sketch. The ingest URL comes from a push device under Dashboard, Devices at probeharbor.dev.
  • GPIO 4 is the probe data pin ProbeHarbor's own firmware uses on all three boards. This sketch itself has no recorded hardware test.