Postlad/Guides/DS18B20 temperature logger online

DS18B20 temperature logger online (aquarium, fridge, brewing)

A waterproof DS18B20 probe on an ESP32 makes a cheap, accurate temperature logger for a fish tank, a fridge or freezer, or a fermenter. The ESP32 sends one HTTP GET a minute and the readings appear on a live chart you can open from your phone, share or embed.

ESP32 and DS18B20 probe wiringA DS18B20 probe connects its red wire to ESP32 3V3, yellow data wire to GPIO4 and black wire to ground, with a 4.7 kilohm pull-up between 3V3 and data.ESP32 DevKitDS18B20 probeVCCDATAGNDredyellowblack3V3GPIO4GND4.7 kΩ
The 4.7 kΩ resistor goes between DATA and 3V3. Wire colours are the usual ones, not a guarantee; check your probe.

Reviewed, not yet bench-tested on this exact board and sensor combination.

The program below is what the Postlad setup wizard produces. At app.postlad.com/setup you can choose your board and sensor, get this program with your key filled in, and skip pasting the key by hand.

Parts

  • ESP32 development board
  • Waterproof DS18B20 probe (stainless tip, usually 1 to 3 m of cable)
  • 4.7 kΩ resistor, unless your probe came on a small adaptor board that already has one
  • Breadboard or screw terminals and jumper wires
  • USB cable and a steady USB power supply
  • Arduino IDE 2.x with the ESP32 board package
  • Libraries OneWire and DallasTemperature
  • Free Postlad account and a stream write key

Wiring

Probe wireUsual colourESP32
VCCRed3V3
DATAYellowGPIO4
GNDBlackGND
Pull-up4.7 kΩ resistorBetween DATA and 3V3

Colours vary by seller. Red, black and yellow is the most common scheme, but some probes use other colours, and listings are not always right about their own cables. Check the seller's sheet before connecting. A DS18B20 wired backwards gets hot within seconds; if the probe is warm to the touch, unplug it at once.

The resistor is not optional. The data line needs the 4.7 kΩ pull-up to 3V3 to work at all. Without it the probe does not answer and the library reports -127 °C. Nine times out of ten a probe that is "not found" is the missing 4.7 kΩ resistor.

The program powers the probe from 3V3 on its red wire. The DS18B20 also has a "parasite power" mode that uses only two wires; it is less forgiving and this program does not use it.

Complete program

  1. Install the Arduino IDE and the ESP32 board package.
  2. Install the libraries OneWire and DallasTemperature from the Library Manager.
  3. Wire it up as above.
  4. Make a new sketch, paste the program into the main tab, and add a second tab called secrets.h.
  5. Put your Wi-Fi name and password, and your write key, in secrets.h.
  6. Choose the board and the port, then press Upload.
  7. Open the serial monitor at 115200 baud.
  8. Open your stream.
cpp
// ESP32 -> Postlad
//
// Made by app.postlad.com/setup. Two things to change, both in secrets.h:
// your Wi-Fi name and your Wi-Fi password. Nothing in THIS file needs editing.
//
// Readings appear at https://app.postlad.com/streams
//   DS18B20 temperature probe -> f1 temperature
//
// Plain http:// is deliberate and supported. A board with no room for a
// certificate store still works, which is the whole point of this service.

#include <WiFi.h>
#include <HTTPClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include "secrets.h"

const char* POSTLAD_URL = "http://api.postlad.com/u";
const char* STREAM_PAGE = "https://app.postlad.com/streams";
const unsigned long SEND_INTERVAL_MS = 60000UL;

WiFiClient client;

OneWire oneWire(4);
DallasTemperature probe(&oneWire);

void connectWiFi() {
  if (WiFi.status() == WL_CONNECTED) return;
  Serial.print("Joining ");
  Serial.println(WIFI_SSID);
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.print("\nJoined. This board is ");
  Serial.println(WiFi.localIP());
}

// One attempt. Returns true only when Postlad stored the reading.
bool sendOnce(const String& url) {
  HTTPClient http;
  if (!http.begin(client, url)) {
    Serial.println("Could not start the request.");
    return false;
  }
  int status = http.GET();
  String reply = http.getString();
  http.end();
  reply.trim();
  if (status == 200) {
    Serial.print("stored -> ");
    Serial.println(reply);
    return true;
  }
  Serial.print("not stored (HTTP ");
  Serial.print(status);
  Serial.print("): ");
  Serial.println(reply);
  return false;
}

void setup() {
  Serial.begin(115200);
  delay(300);
  Serial.println();
  Serial.print("Your readings will appear at ");
  Serial.println(STREAM_PAGE);
  probe.begin();
  connectWiFi();
}

void loop() {
  connectWiFi();

  probe.requestTemperatures();
  float probeTemp = probe.getTempCByIndex(0);
  if (probeTemp < -100) {
    Serial.println("The DS18B20 did not answer. Check the 4.7k resistor between the data wire and 3V3.");
    delay(2000);
    return;
  }

  String url = String(POSTLAD_URL) + "?k=" + POSTLAD_KEY
             + "&f1=" + String(probeTemp, 1)
             ;

  // Three tries, waiting longer each time. A router that is rebooting takes
  // a few seconds; giving up after one attempt loses a reading for nothing.
  unsigned long backoff = 2000;
  for (int attempt = 1; attempt <= 3; attempt++) {
    if (sendOnce(url)) {
      break;
    }
    if (attempt < 3) {
      delay(backoff);
      backoff = backoff * 2;
    }
  }

  delay(SEND_INTERVAL_MS);
}

The second file holds everything private:

cpp
#pragma once
// secrets.h — the only file with anything private in it.
//
// Keep this file off forums, out of screenshots and out of shared folders.
// The program file beside it can be pasted anywhere safely.

// Type your own Wi-Fi name and password between the quotes. 2.4 GHz only.
const char* WIFI_SSID     = "YOUR_WIFI_NAME";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";

// Your Postlad write key. It can only add readings to one stream — it cannot
// read anything, change anything, or reach your account.
const char* POSTLAD_KEY   = "YOUR_KEY";

A working logger prints something like this once a minute. ok 1 means one field was taken.

text
Your readings will appear at https://app.postlad.com/streams
Joining YOUR_WIFI_NAME
....
Joined. This board is 192.168.1.42
stored -> ok 1

On the stream page, name f1 "Temperature", unit °C, 1 decimal. The name and unit change how the chart, CSV export and share page read; they do not change what the device sends.

-127 °C and 85 °C are errors, not temperatures

Two values from a DS18B20 are almost never real readings:

ValueWhat it meansUsual cause
-127 °CThe library got no answer from the probeMissing pull-up, a loose or broken wire, wrong pin, or wires swapped
85 °CThe probe's power-on reset value: it was read before it finished a measurementA power glitch or brown-out at the probe, or a read straight after power-up

Neither should ever reach your chart as a reading. A fridge line that drops to -127 °C squashes the useful part of the graph flat, wrecks the hourly averages, and looks like a real event to anyone reading the shared link. A gap is more honest.

What the program above does: when the reading is below -100 °C it prints a warning and skips the cycle, so -127 is never sent. That matters because the server cannot catch it for you: -127.0 is a perfectly valid number and would be stored, unlike nan, which gets a 400 bad_value reply and is not stored. The program does not check for 85 °C. For anything you leave running, replace the five lines that start with if (probeTemp < -100) with this, so both error values are skipped:

cpp
  if (probeTemp == DEVICE_DISCONNECTED_C || probeTemp == 85.0) {
    Serial.print("Probe error value ");
    Serial.print(probeTemp);
    Serial.println(", not sending it. Check the 4.7k resistor and the wiring.");
    delay(SEND_INTERVAL_MS);
    return;
  }

DEVICE_DISCONNECTED_C is -127, defined by the DallasTemperature library. Skipping 85 °C is right for an aquarium, fridge or fermenter, where 85 °C is never a real value. If you log a mash or anything else that genuinely passes through 85 °C, skip only -127 and treat a lone 85 next to readings far from it as suspect.

Skipping error values has a useful side effect: if the probe fails for good, the stream stops receiving readings, and the stream-stopped email described below tells you.

Several probes on one wire

DS18B20 probes can share one data line: wire every probe's DATA to GPIO4, VCC to 3V3 and GND to GND, with a single 4.7 kΩ pull-up. Each probe has its own 64-bit address. The program above only reads the first probe it finds (getTempCByIndex(0)), so logging several needs a change to read each probe and send it in its own field, f2, f3 and so on. If you do that, identify the probes by address rather than index, because the index order follows the addresses, not the order you plugged them in.

Aquarium temperature monitor

  • Put only the stainless probe and its cable in the water. Keep the ESP32, the resistor and every joint outside the tank and above the waterline, with a drip loop in the cable so water runs off before it reaches the electronics.
  • Clip the probe away from the heater and the filter outlet, where it reads the tank, not the heater.
  • For saltwater or reef tanks, check the probe is sold for permanent saltwater use; many inexpensive stainless probes are not.
  • Compare against a thermometer you trust for a day. A steady offset of a few tenths of a degree is within the DS18B20's ±0.5 °C.
  • Heaters tend to fail stuck on or stuck off. The chart shows both clearly; once a minute is more than enough to see it.

Fridge and freezer temperature logger

  • Keep the ESP32 outside. A fridge is a metal box that blocks Wi-Fi, and cold boards collect condensation. Run the probe cable through the door seal and check the door still closes fully.
  • Air temperature jumps every time the door opens. To log what the food sees, put the probe in a small bottle of water, or a water and glycol mix in a freezer, so it reads a buffered temperature.
  • The DS18B20 works down to -55 °C. Its ±0.5 °C accuracy is specified from -10 °C to +85 °C; at freezer temperatures the datasheet allows a wider error, so check it against a reference if the exact figure matters.
  • Every 60 seconds is a sensible interval. A door left open shows up within minutes.

Fermentation and brewing

  • Fermentation heat comes from the inside. A probe in a thermowell, or taped to the side of the fermenter under a patch of insulation, reads the beer rather than the room.
  • Use a separate stream, or a second field, for the room or chamber temperature, so you can see how hard the chamber works.
  • Before putting a probe in hot wort, check the cable's rated temperature. The sensor itself is rated to 125 °C, but the cable and the seal on cheap probes often are not.
  • Share the secret link with whoever else is brewing; they can watch without an account.

Get an email when it stops

On every plan, including Free, you can turn on an email for when a stream stops sending. It is opt-in, per stream. For a fridge or a tank that is the alarm you most need: a power cut, a router fault or a dead probe all end with silence.

Value alerts, such as a freezer warmer than -12 °C or a tank below 24 °C, start at the Hobby plan. On Free, a fridge that warms up while still sending will show on the chart but will not send an email. See pricing for what each plan includes.

Sending interval and the free plan

The program sends every 60 seconds, which is 44,640 readings in a 31-day month. The Free plan gives you 2 streams and 100,000 readings a month across the account, at most 1 reading every 5 seconds per stream, so two loggers at 60 seconds, a fridge and a freezer for example, fit with room to spare. Every 30 seconds uses 89,280 readings a month on one stream. To change the interval, edit SEND_INTERVAL_MS; it is in milliseconds.

The write key stays on the device. Viewers get a public or secret link and never see the key. If it leaks, rotate it on the stream page and update secrets.h.

Raspberry Pi Pico W instead

The setup wizard also makes a MicroPython version for the Pico W with a DS18B20 on GP15. See the Pico W cloud data logger guide for flashing MicroPython and running the program in Thonny, and use the wizard to get the DS18B20 version with your key filled in.

Troubleshooting

The serial monitor says the DS18B20 did not answer

The library got -127 °C, which means the probe is not answering, so the program skipped that reading rather than sending it. If it happens every time, nothing reaches your chart. Check the 4.7 kΩ resistor between DATA and 3V3, that DATA goes to GPIO4, and the probe's colour scheme. A broken joint inside heat-shrink is the next most likely cause.

It reads 85 °C now and then

The probe reset before it finished a measurement. Look for a weak USB supply, a loose VCC wire or a long thin cable. Skip the value as shown above; do not average it away.

Readings drop out on a long cable

Long runs add capacitance and noise to the data line. Use a decent twisted cable, keep it away from mains wiring, and test the full length on the bench before you install it.

The HTTP status is negative

That number comes from the ESP32's HTTP client, not the server: no route, a DNS failure or a timeout. Check the board joined Wi-Fi; the ESP32 only sees 2.4 GHz networks.

The server replies 429

Readings are arriving faster than the stream accepts. Raise SEND_INTERVAL_MS. The reply says the reading was not stored.

FAQ

Why does my DS18B20 read -127 °C?

-127 °C is the DallasTemperature library's value for a probe that did not answer. It is almost always the missing 4.7 kΩ pull-up resistor between DATA and 3V3, or a wiring fault. It is not a temperature and should not be logged; the program on this page skips it instead of sending it.

Why does my DS18B20 read 85 °C?

85 °C is the value the DS18B20 holds after power-up, before it has made a measurement. Seeing it in normal running usually points to a power glitch at the probe. Skip it rather than logging it.

Do I need the 4.7 kΩ resistor?

Yes, unless your probe came on an adaptor board that already has one. The one-wire data line needs a pull-up to 3V3, and without it the probe does not answer.

Can I log several DS18B20 probes from one ESP32?

Yes. Several probes can share one data pin and one pull-up, and each can be sent in its own field from f1 to f16. The program on this page reads only the first probe, so it needs a small change to read the others.

Will Postlad email me if my fridge logger stops?

Yes, if you turn it on. An email when a stream stops sending is available on every plan, including Free. Alerts for values, such as a freezer getting too warm, start at the Hobby plan.

How long does Postlad keep the readings?

On the Free plan: every reading kept at full detail for 30 days, then an hourly minimum, maximum and average for 12 months.

Create the stream

Create a free account, make a stream, and either paste its write key into secrets.h or let the setup wizard fill it in for you.

Create your free account →

Sources and verification