ESP32 DS18B20 temperature sensor wiring including 4.7k pull-up

In this easy CircuitMagic tutorial you will build measure water temperature using esp32 and ds18b20 sensor using ESP32 DevKit and one simple sensor. The project needs only a few connections and a short Arduino IDE sketch.

What does the sensor do?

The DS18B20 is a one-wire digital thermometer. The 4.7kΩ resistor pulls the DATA line high so the sensor can communicate reliably.

Required components

ESP32 DevKit, waterproof 3-wire DS18B20, 4.7kΩ resistor, jumper wires, USB cable.

Connection diagram

The diagram below is a pin-to-pin connection map: each colored line shows one separate wire between labeled terminals, not a photograph of a particular board’s header layout.

DS18B20 temperature sensor wiring diagram for ESP32

Pin connections

Unplug USB power before wiring. The pin table is authoritative; always verify your board’s printed pin labels and your module’s pinout.

ESP32 DevKit pin / connectionwaterproof DS18B20 sensor connection
3V3DS18B20 VDD
GNDDS18B20 GND
GPIO4DS18B20 DATA
3V3 and DATA4.7kΩ resistor between these two nodes

Arduino IDE setup

Install OneWire and DallasTemperature from Arduino IDE Library Manager. Select the matching board and serial port, then upload this sketch.

Complete Arduino code

#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(4);
DallasTemperature sensors(&oneWire);
void setup() {
  Serial.begin(115200);
  sensors.begin();
}
void loop() {
  sensors.requestTemperatures();
  float c = sensors.getTempCByIndex(0);
  if (c == DEVICE_DISCONNECTED_C) {
    Serial.println("Sensor not found");
  } else {
    Serial.print("Water temperature: ");
    Serial.print(c, 1);
    Serial.println(" C");
  }
  delay(2000);
}

Expected output

Water temperature: 22.5 C (your reading will vary). Open Serial Monitor at the baud rate specified by Serial.begin().

Troubleshooting

Waterproof probe lead colours are not universal. Verify the exact VDD/GND/DATA wire order using the probe supplier’s datasheet before powering it.

If there is no output, double-check the board and port, USB data cable, common ground, sensor pin labels and Serial Monitor speed.

Try next

Once the basic example works, experiment with the sampling delay, add an LED indicator, or log the sensor output to a computer. See more CircuitMagic electronics projects for related beginner tutorials.

0 Comments

Leave a reply

Your email address will not be published. Required fields are marked *

*

or

Log in with your credentials

Forgot your details?