ESP8266 Waterproof DS18B20 Temperature Sensor
The ESP8266 Waterproof DS18B20 Temperature Sensor project demonstrates how to use a waterproof DS18B20 probe with an ESP8266‑based board (such as NodeMCU or Wemos‑D1) to measure temperature in liquids or harsh environments. The DS18B20 communicates over a 1‑Wire bus, supporting high accuracy and allowing multiple sensors on a single GPIO pin. The ESP8266 can read the temperature, display it locally, or send it over Wi‑Fi to a cloud dashboard or IoT platform.
How the DS18B20 Works
The DS18B20 is a digital 1‑Wire temperature sensor that outputs temperature values in 9–12‑bit resolution without needing an external ADC. Each DS18B20 has a unique 64‑bit address, so you can connect many sensors to the same data line and read them individually. The waterproof probe consists of a stainless‑steel sheath containing the DS18B20 chip and a 3‑wire cable (VCC, GND, data), making it suitable for immersion in water, tanks, or high‑humidity areas.
To work correctly, the DS18B20 needs a 4.7 kΩ pull‑up resistor between the data line and VCC, and the ESP8266 must use the OneWire and DallasTemperature libraries to handle the 1‑Wire protocol.
Components Needed
- ✓ESP8266 development board (e.g. NodeMCU‑v2 or Wemos‑D1)
- ✓Waterproof DS18B20 temperature sensor probe (with 3‑wire cable)
- ✓4.7 kΩ resistor (pull‑up for DS18B20 data line)
- ✓LED or small OLED (optional, for local display)
- ✓Jumper Wires
- ✓Breadboard
Circuit Diagram
Circuit Setup
Typical wiring for one DS18B20 probe to ESP8266 (NodeMCU‑style):
- ✓Red wire (VCC) → 3.3 V on ESP8266 (or 5 V on boards that keep DS18B20 within datasheet limits).
- ✓Black wire (GND) → GND on ESP8266.
- ✓Yellow/white wire (data / DQ) → GPIO 2 (D4 on NodeMCU).
Add a 4.7 kΩ pull‑up resistor: one leg to the data line (DQ), the other leg to VCC. This keeps the 1‑Wire line high when idle so the DS18B20 can drive it low when needed.
You can connect multiple DS18B20 probes in parallel:
- ✓All red wires → VCC.
- ✓All black wires → GND.
- ✓All data wires → the same GPIO (e.g. GPIO 2), with a single 4.7 kΩ pull‑up from that line to VCC.
Instructions
Configure the Arduino IDE for ESP8266 (e.g. board: NodeMCU‑v2). Install the OneWire and DallasTemperature libraries from the Library Manager. Add proper Wi‑Fi configuration if you plan to send data to ThingSpeak, Blynk, or a custom server.
Initialize the OneWire bus on the chosen GPIO, then create a DallasTemperature object. In setup(), call sensors.begin(); in loop(), request a temperature conversion with sensors.requestTemperatures() and then read the value with sensors.getTempCByIndex(0) for the first sensor.
Once the ESP8266 reads the temperature, use HTTP or MQTT to send it to a cloud service (ThingSpeak, Blynk, or an MQTT broker). This enables remote monitoring of tank, aquarium, or outdoor temperatures even when you are away from the sensor location.
Before submerging the DS18B20 probe, ensure the stainless‑steel sheath is intact and the cable is not damaged. Avoid pulling on the wire when the sensor is immersed. For long‑term outdoor use, seal the cable entry point suitably so water cannot migrate inside, and keep the ESP8266 and connectors in a dry, weather‑protected enclosure.
C++ Example Code (ESP8266 with Waterproof DS18B20)
#include <ESP8266WiFi.h>#include <OneWire.h>#include <DallasTemperature.h>
// Replace with your Wi‑Fi credentialsconst char* ssid = "YOUR_WIFI_SSID";const char* password = "YOUR_WIFI_PASSWORD";
// GPIO where DS18B20 DQ is connectedconst int oneWireBus = 2; // D4 on NodeMCU
// Setup OneWire instanceOneWire oneWire(oneWireBus);
// Pass oneWire reference to DallasTemperatureDallasTemperature sensors(&oneWire);
void setup() { Serial.begin(9600); // Optional: connect to Wi‑Fi // WiFi.begin(ssid, password); // while (WiFi.status() != WL_CONNECTED) delay(1000); // Start DS18B20 sensor sensors.begin(); Serial.println("=== ESP8266 WATERPROOF DS18B20 READY ===");}
void loop() { // Request temperature readings sensors.requestTemperatures(); // Read temperature in Celsius for first sensor float temperatureC = sensors.getTempCByIndex(0); // Optional: convert to Fahrenheit float temperatureF = sensors.getTempFByIndex(0); // Print to Serial Monitor Serial.print("Temperature: "); Serial.print(temperatureC); Serial.print(" °C, "); Serial.print(temperatureF); Serial.println(" °F"); // Optional: send to cloud service here (HTTP/MQTT) delay(3000);}Applications
Aquarium and Tank Monitoring: Use the waterproof DS18B20 to monitor water temperature in aquariums, hydroponic tanks, or industrial process tanks, and send alerts if the temperature drifts outside safe limits.
Outdoor Environmental Monitoring: Deploy the probe in weather stations or crops to track soil or ambient water temperature, helping with irrigation or climate‑condition management.
Industrial and HVAC Systems: Integrate the sensor into boilers, chillers, or HVAC units to monitor liquid temperatures and control heating or cooling components via the ESP8266 or a PLC.
Notes
The DS18B20 uses a 1‑Wire bus, which allows many sensors on a single GPIO with one pull‑up resistor. Each sensor has a unique address, so the ESP8266 can read temperatures from several probes independently by using getTempC(address) or iterating over device addresses.
Use the Serial Monitor to verify that temperature values update when the DS18B20 is moved between different environments. If the sensor returns an error (e.g., 85 °C), check the wiring, pull‑up resistor, and OneWire library initialization.
You can extend this project by connecting the ESP8266 to Wi‑Fi and sending the DS18B20 readings to a cloud dashboard or IoT platform, enabling real‑time visualization, historical graphs, and threshold‑based alerts for temperature excursions.