ESP32 with DS18B20: The Complete Beginner-Friendly Guide You Wish You Had Earlier

0b63979cd9494aa401d1fce2d73bb002
On: December 1, 2025
ESP32 with DS18B20

Table of Contents

Beginner-friendly guide on using ESP32 with DS18B20. Learn wiring, code, troubleshooting, and multiple sensor setup for accurate temperature monitoring

If you’re planning to monitor temperature with the ESP32, the DS18B20 temperature sensor is one of the most reliable and accurate options you’ll ever use. It’s waterproof (if you buy the probe version), works on a simple digital protocol, and gives stable readings. The good part? Getting started with esp32 with ds18b20 is easier than most beginners expect.

In this guide, I’ll walk you through everything like we’re chatting over a cup of coffee: simple, clear, beginner-friendly, and practical. You’ll learn how the sensor works, how to wire it correctly, how to code it, how to fix issues when ds18b20 not working with esp32, and even how to use it with MicroPython, ESP-IDF, Home Assistant, Blynk, and multiple sensors.

By the end of this article, you’ll be able to build your own temperature-monitoring project with confidence.

What Makes the DS18B20 Perfect for ESP32?

Let’s start with a simple question: Why pair the ESP32 with the DS18B20 temperature sensor?

Here’s the real difference:

  • It’s digital. No analog noise problems.
  • It works over 1-Wire protocol. Only one GPIO pin needed.
  • You can connect multiple DS18B20 sensors on the same pin.
  • Temperature accuracy is solid (±0.5°C).
  • You can place it far away using long cables.
  • Perfect for IoT projects because ESP32 has WiFi + Bluetooth.

So whether you’re building a home-automation system, a data logger, or a smart greenhouse, ds18b20 temperature sensor with esp32 is a rock-solid combo.

Understanding the DS18B20 in 2 Minutes

The DS18B20 is a digital temperature sensor with 3 pins:

  1. VCC
  2. GND
  3. DQ (data pin)

It works using 1-Wire communication, which means:

  • One wire handles communication.
  • You need a 4.7k pull-up resistor between DQ and VCC.
  • Each sensor has a unique 64-bit address, so you can plug in multiple sensors on the same pin.

This is where the esp32 with multiple ds18b20 temperature sensors becomes useful—ESP32 handles all of them with ease.

DS18B20 Connection with ESP32 (Wiring Guide)

Here’s the easiest wiring for ds18b20 connection with esp32:

DS18B20 PinESP32 Pin
VCC3.3V
GNDGND
DQGPIO 4 (or any digital pin)

And don’t forget:

  • Connect a 4.7kΩ resistor between VCC and DQ.

If the resistor is missing or placed incorrectly, you will face the common issue:

“ds18b20 not working with esp32”

We’ll troubleshoot this later.

ESP32 DS18B20 Arduino Library You Need

To use esp32 ds18b20 temperature sensor with Arduino IDE, install these two libraries:

  1. OneWire
  2. DallasTemperature

These libraries make reading the temperature simple and stable.

ESP32 DS18B20 Code (Arduino IDE)

Here’s clean, beginner-friendly code for esp32 ds18b20 code:

#include 
#include 

#define ONE_WIRE_BUS 4  // Data pin GPIO4

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

void setup() {
  Serial.begin(115200);
  sensors.begin();
}

void loop() {
  sensors.requestTemperatures();
  float tempC = sensors.getTempCByIndex(0);

  Serial.print("Temperature: ");
  Serial.print(tempC);
  Serial.println(" °C");

  delay(1000);
}

Upload it, open the Serial Monitor, and you should see temperature readings instantly.

This code works with:

  • esp32 ds18b20 board
  • esp32 ds18b20 arduino library
  • ds18b20 temperature sensor interfacing with esp32

If you want to explore more sensor projects after setting up the ESP32 with DS18B20, you can also check out my detailed guide on using the BMP280 sensor with ESP32 here: Guide on BMP280 sensor with ESP32. It’s a great next step if you’re building a complete environment-monitoring system.

Getting the ESP32 DS18B20 Address

Each DS18B20 has its own unique address, helpful when using multiple sensors.

Use this sketch:

#include 

OneWire ds(4);

void setup() {
  Serial.begin(115200);
}

void loop() {
  byte addr[8];
  if (ds.search(addr)) {
    Serial.print("Address: ");
    for (int i = 0; i < 8; i++) {
      Serial.print(addr[i], HEX);
      Serial.print(" ");
    }
    Serial.println();
  } else {
    ds.reset_search();
  }
}

This gives you the esp32 ds18b20 address for each sensor.

Using Multiple DS18B20 Sensors with ESP32

Using esp32 with multiple ds18b20 temperature sensors is easier than it looks.
The OneWire bus supports:

  • 5 sensors
  • 10 sensors
  • Even 20 sensors with proper wiring

Just:

  • Short all DQ pins together
  • Use the same pull-up resistor
  • Read them by their unique address

This is perfect for:

  • Greenhouse monitoring
  • Multi-room temperature logging
  • Aquarium + water tank setup

ESP32 with DS18B20 Using MicroPython

If you prefer MicroPython, here’s the simplest ds18b20 esp32 micropython example.

MicroPython Code:

from machine import Pin
import onewire, ds18x20, time

dat = Pin(4)
ds = ds18x20.DS18X20(onewire.OneWire(dat))

roms = ds.scan()
print("Found devices:", roms)

while True:
    ds.convert_temp()
    time.sleep_ms(750)
    for rom in roms:
        print(ds.read_temp(rom))
    time.sleep(1)

This helps you quickly get started with temperature sensing in MicroPython.

ESP32 DS18B20 Using ESP-IDF (Professional Approach)

If you’re working on a serious project or want complete control, ESP-IDF is perfect.
Here’s a minimal esp32 ds18b20 esp idf flow:

  • Use the OneWire driver
  • Query DS18B20 ROM
  • Trigger conversion
  • Read scratchpad
  • Decode temperature

Great for automotive, energy systems, or industrial IoT.

ESP32 DS18B20 with Blynk (IoT Cloud)

Want to monitor temperature on your phone?

Use esp32 ds18b20 blynk:

  • Configure WiFi
  • Use Virtual Pin (V1)
  • Send temperature value every second

You get real-time temperature updates anywhere in the world.

Perfect for:

  • Smart home
  • Server room monitoring
  • Greenhouse automation

ESP32 DS18B20 with Home Assistant

If you use Home Assistant, esp32 ds18b20 home assistant is one of the most plug-and-play combinations.

You can use:

  • ESPHome
  • MQTT
  • HTTP API

Just flash ESPHome onto ESP32 and add this:

sensor:
  - platform: ds18b20
    pin: GPIO4
    name: "Living Room Temperature"

Home Assistant auto-detects the sensor instantly.

Bluetooth Projects with ESP32 + DS18B20

The ESP32 has excellent Bluetooth capabilities, so you can build:

  • A Bluetooth thermometer
  • Mobile-connected temperature logger
  • BLE broadcasting device

This falls under esp32 ds18b20 bluetooth projects.

You simply read the temperature and broadcast it via BLE.
Any smartphone app can read the data.

Why DS18B20 Might Not Be Working with ESP32 (Fixes)

If you’re facing the issue esp32 ds18b20 not working, check these common mistakes:

1. Missing 4.7k Pull-Up Resistor

No resistor = No readings.

2. Wrong Powering

Always use 3.3V, not 5V.

3. Long Cable Interference

Use twisted pair or shielded cable.

4. Wrong GPIO Pin

Some pins on ESP32 are not input-friendly.

Use:

  • GPIO 4
  • GPIO 5
  • GPIO 18
  • GPIO 19

5. Bad Breadboard or Loose Wires

Very common issue.

Once these are fixed, DS18B20 usually works instantly.

How to Use DS18B20 with ESP32

Here’s a quick recap of how to use ds18b20 with esp32:

  1. Wire VCC to 3.3V
  2. GND to GND
  3. DQ to GPIO4
  4. Add a 4.7k resistor between DQ and VCC
  5. Install OneWire + DallasTemperature libraries
  6. Upload code
  7. Read temperature

If you’re new to sensors, this is one of the easiest to start with.

Real-World Projects You Can Build

Here are simple ideas using how to use ds18b20 temperature sensor with esp32:

1. Home Temperature Monitor

Send data to your phone using Blynk.

2. Weather Station

Combine humidity + pressure + temperature.

3. Smart Greenhouse

Monitor soil temperature + air temperature.

4. Aquarium Temperature Monitoring

Use the waterproof probe.

5. Industrial Temperature Logger

Use multiple DS18B20 sensors.

6. Home Assistant Integration

Display temperature on your smart dashboard.

DS18B20 Advantages Over DHT11 / DHT22

Many beginners wonder:

Why use ds18b20 temperature sensor with esp32 instead of DHT11 or DHT22?

Here’s why:

FeatureDS18B20DHT11DHT22
AccuracyVery highLowMedium
Cable Length SupportExcellentPoorPoor
WaterproofYesNoNo
Multiple SensorsYesNoNo
Digital Noise ImmunityHighLowMedium

So DS18B20 is simply more professional and reliable.

Ultimate Troubleshooting Guide for ESP32 with DS18B20 (

If you’ve ever tried interfacing ESP32 with DS18B20 and saw nothing but -127°C, 85°C, or No Devices Found, trust me you’re not alone. Every beginner faces this. Even experienced engineers get stuck when the ds18b20 temperature sensor with esp32 decides to act stubborn.

This guide is your “I wish I had this earlier” troubleshooting manual. Let’s fix your DS18B20 once and for all.

Troubleshooting #1 — 4.7kΩ Pull-Up Resistor Missing or Wrong Value

✔ The MOST common reason:

You didn’t add the 4.7k resistor.
Or you added 10k.
Or the resistor is connected wrong.

Why it matters:

The 1-Wire bus needs a pull-up resistor to stabilize the DQ line.

Without it:

  • ESP32 cannot detect DS18B20 ROM
  • Temperature shows -127°C
  • Sensors don’t respond
  • Multiple sensors behave unpredictably

Fix:

Add a 4.7kΩ resistor between DQ and VCC (3.3V).

Pro tip:

If using esp32 with multiple ds18b20 temperature sensors,
use only one pull-up resistor, not more.

Troubleshooting #2 — Wrong Wiring (Most Beginners Get This Wrong)

Correct wiring for ds18b20 connection with esp32 is:

DS18B20ESP32
VCC3.3V
GNDGND
DQGPIO4

Common wiring mistakes:

❌ Using 5V instead of 3.3V
❌ Connecting DQ to GPIO34–GPIO39 (input-only pins!)
❌ Forgetting the resistor
❌ Mixing VCC and GND
❌ Using long breadboard jumper wires causing noise

Fix:

  • Double-check wiring
  • Use a short wire first
  • Use GPIO4, 5, 18, or 19 (best 1-Wire pins)

Troubleshooting #3 — ESP32 Pins Not Suitable for 1-Wire

Not every pin works well with ds18b20 interface with esp32.

Avoid these pins:

  • GPIO34–GPIO39 (input-only)
  • GPIO0, GPIO2, GPIO15 (boot pins)
  • GPIO12 (changes boot voltage)
  • GPIO13, 14 (conflicts with SPI)
  • GPIO6–11 (flash pins)

Best pins for DS18B20:

  • GPIO4
  • GPIO5
  • GPIO18
  • GPIO19

If you’re using ESP32 development board, these pins are safe.

Troubleshooting #4 — Getting Constant -127°C Reading

This means:

❌ ESP32 cannot detect the DS18B20 device.

Possible reasons:

  • Wrong wiring
  • Missing pull-up resistor
  • Wrong GPIO pin in code
  • Broken sensor
  • Code using wrong esp32 ds18b20 address

Fix checklist:

✔ Add 4.7k resistor
✔ Confirm your wire connections
✔ Use OneWire example “Search ROM” sketch
✔ Replace sensor to test
✔ Change GPIO number in code

Troubleshooting #5 — Getting Constant 85°C Reading

85°C is a default value DS18B20 returns before performing a conversion.

Reasons:

  • You forgot to call requestTemperatures()
  • Power supply is unstable
  • DS18B20 didn’t complete conversion because delay too short

Fix in Arduino code:

sensors.requestTemperatures();
delay(750);
float temp = sensors.getTempCByIndex(0);

Minimum conversion time: 750 ms.

If you send commands too fast, DS18B20 returns 85°C.

Troubleshooting #6 — Wrong DS18B20 Address When Using Multiple Sensors

When using esp32 with multiple ds18b20 temperature sensors,
each sensor has a unique 64-bit address.

If you mix addresses:

  • Readings appear swapped
  • Some sensors show zero
  • Others show wrong values

Fix:

Run the Address Finder Code, label each sensor physically, and write them correctly in your code.

Troubleshooting #7 — Using Poor Quality USB Cable

Low-quality USB cables cause:

  • Power drops
  • Random resets
  • DS18B20 disconnects
  • “No device found” errors

Fix:
Use a thick, original USB cable with stable 5V output.

Troubleshooting #8 — Long Cable Problems (Common in Waterproof Probes)

Waterproof DS18B20 probes often come with long cables.
Long cables create:

  • Noise
  • Crosstalk
  • Signal distortion

Symptoms:

  • Sensor detected but returns -127°C
  • Random readings
  • Works only when touching the wire
  • Works on Arduino but not on ESP32

Fixes for long cable:

✔ Use twisted pair cable
✔ Place pull-up resistor near ESP32
✔ Use 3.3V—NOT 5V
✔ Add 100nF capacitor between VCC and GND near sensor
✔ Lower wire length to <5 meters

For IoT homes, use Home Assistant or ESP32 DS18B20 boards with short wires.

Troubleshooting #9 — DS18B20 Not Working in Parasitic Power Mode

Parasitic mode = using only 2 wires.

ESP32 often struggles with it.

Symptoms:

  • Unstable readings
  • Only works sometimes
  • Only short wires work

Fix:

Do NOT use parasitic mode.
Always power the DS18B20 with 3.3V using 3 wires.

Troubleshooting #10 — Using Wrong DS18B20 Library in Arduino IDE

For esp32 ds18b20 arduino library, you MUST use:

  1. OneWire
  2. DallasTemperature

Using alternatives like “TinyDallas” or older libraries causes:

  • Wrong timings
  • Unstable readings
  • No device found

Fix:
Remove old libraries and install fresh ones from Library Manager.

Troubleshooting #11 — ESP32 DS18B20 Code Wrong or Missing Steps

Here are coding mistakes that break DS18B20:

❌ Not calling sensors.begin()
❌ Not calling requestTemperatures()
❌ Wrong GPIO pin number
❌ Wrong index (0) when using multiple sensors
❌ Wrong ROM address

Fix:
Use this clean base code:

#include 
#include 

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

void setup() {
  Serial.begin(115200);
  sensors.begin();
}

void loop() {
  sensors.requestTemperatures();
  Serial.println(sensors.getTempCByIndex(0));
  delay(1000);
}

This works for:

  • esp32 ds18b20 code
  • esp32 ds18b20 connection
  • esp32 ds18b20 board

Troubleshooting #12 — Sensor Works on Arduino but Not ESP32

Reasons:

  • ESP32 is 3.3V; Arduino uses 5V
  • Wrong GPIO pins used
  • Timing differences in OneWire
  • Power supply not clean
  • Breadboard corrosion or noise

Fix:

✔ Use GPIO4
✔ Add 100nF ceramic capacitor
✔ Use short wires
✔ Use updated libraries

Troubleshooting #13 — DS18B20 Works in Arduino IDE but Not in ESP-IDF / MicroPython

For ds18b20 esp32 micropython:

ds.convert_temp()
time.sleep_ms(750)

For esp32 ds18b20 esp idf, ensure:

  • CRC check passes
  • Scratchpad values decode correctly
  • Reset pulse is correct
  • Timing meets OneWire spec

Troubleshooting #14 — DS18B20 Not Working with Blynk

In esp32 ds18b20 blynk projects:

Issues:

  • Too many updates
  • WiFi delays block sensor timing
  • Virtual pin not configured

Fix:

✔ Use a timer
✔ Read temperature every 1 sec
✔ Send to Blynk every 2 sec

Troubleshooting #15 — DS18B20 Not Showing in Home Assistant

In esp32 ds18b20 home assistant:

Causes:

  • ESPHome YAML wrong
  • Wrong GPIO
  • Sensor not detected
  • No pull-up resistor

Fix YAML:

sensor:
  - platform: ds18b20
    pin: GPIO4

Troubleshooting #16 — Sensor Gets Hot or Burns Out

Reasons:

  • Wrong wiring
  • Short circuit
  • Powered from 5V (some cheap DS18B20 clones don’t support it)

Fix:

✔ Use only 3.3V
✔ Check wires carefully
✔ Replace sensor if burnt

Troubleshooting #17 — Fake DS18B20 Sensor

The market is full of fake DS18B20 sensors.

Signs of a fake:

  • Slow response
  • Wrong readings
  • 85°C forever
  • Fails CRC checks

Fix:

✔ Buy from trusted seller
✔ Use ROM search to verify address

Troubleshooting #18 — DS18B20 Temperature Incorrect by 1–2°C

Fix:

  • Add 100nF capacitor
  • Keep wires short
  • Use proper pull-up resistor
  • Use waterproof probe with stainless steel
  • Keep away from heat sources

Troubleshooting #19 — Using Multiple Sensors Gives Random Results

Fix:

✔ Label sensors with tape
✔ Scan each address
✔ Read by ROM address, not index
✔ Use strong pull-up resistor
✔ Use twisted pair wires

Troubleshooting #20 — Noise Interference from Nearby Devices

Causes:

  • Motors
  • Relays
  • WiFi interference
  • Switching power supplies

Fix:

✔ Shield DS18B20 cable
✔ Add ferrite bead
✔ Add decoupling capacitors
✔ Use CAT6 cable for long runs

Checklist (Fix 99% of Problems)

If your esp32 ds18b20 not working, check this:

  • 4.7k resistor added
  • Correct ESP32 GPIO pin
  • Wired properly
  • Powered with 3.3V
  • Short cable used
  • Correct DS18B20 library
  • Correct code
  • Device address correct
  • Good USB cable
  • No fake sensor
  • No noisy power supply
  • Avoid parasitic mode

If you follow this checklist, your DS18B20 will work.

Final Thoughts

Pairing an esp32 with ds18b20 gives you one of the most stable and accurate temperature-monitoring setups you can build as a beginner. Whether you’re using Arduino IDE, MicroPython, ESP-IDF, or adding it to Home Assistant or Blynk, the process stays simple and scalable.

You now know how to:

  • Wire the sensor
  • Write ESP32 DS18B20 code
  • Fix common issues
  • Read unique sensor addresses
  • Use multiple sensors
  • Integrate with IoT platforms

FAQ : ESP32 with DS18B20

1. How do I connect the DS18B20 temperature sensor with ESP32?

To connect the ds18b20 temperature sensor with esp32, use three wires: VCC → 3.3V, GND → GND, and DQ → a digital GPIO pin like GPIO4. Add a 4.7kΩ pull-up resistor between DQ and VCC for stable readings.

2. Why is my DS18B20 not working with ESP32?

A ds18b20 not working with esp32 issue usually happens due to missing pull-up resistor, wrong GPIO pin, bad wiring, long cables, or incorrect DS18B20 address. Also avoid input-only pins like GPIO34-GPIO39.

3. Which ESP32 pins are best for DS18B20 connection?

The safest pins for ds18b20 connection with esp32 are GPIO4, GPIO5, GPIO18, and GPIO19. Avoid boot-sensitive pins such as GPIO0, GPIO2, GPIO12, and GPIO15.

4. How do I interface the DS18B20 temperature sensor with ESP32 in Arduino IDE?

To do ds18b20 temperature sensor interfacing with esp32 in Arduino IDE, install the OneWire library and the DallasTemperature library. Then use sensors.begin(), requestTemperatures(), and getTempCByIndex(0) to read values.

5. Can I use multiple DS18B20 sensors with ESP32?

Yes. You can use esp32 with multiple ds18b20 temperature sensors on a single GPIO pin because the DS18B20 uses the OneWire protocol. Each sensor has a unique address, so label them physically and read temperatures by ROM address.

6. How do I find the DS18B20 address on ESP32?

Use the OneWire “Search Address” example to print the esp32 ds18b20 address to the Serial Monitor. This is required when using multiple sensors or ROM-specific readings.

7. Why am I getting -127°C or -196°C on ESP32?

A value of -127°C means the sensor is not detected. Check wiring, resistor, and GPIO. A value like -196°C usually means corrupted data or timing issues. Reconnect wires and restart the sketch.

8. Why does my DS18B20 show 85°C on ESP32?

85°C is the default power-on value when the DS18B20 has not finished converting temperature. Make sure you call requestTemperatures() and wait 750ms before reading.

9. How do I use DS18B20 with ESP32 in MicroPython?

For ds18b20 esp32 micropython, import the onewire and ds18x20 modules, scan for ROMs, call convert_temp(), wait 750ms, and then read read_temp(rom).

10. Is there an ESP-IDF driver for DS18B20 on ESP32?

Yes. You can read the sensor using the esp32 ds18b20 esp idf OneWire implementation. You’ll need to handle reset pulses, ROM matching, scratchpad reads, and CRC checks manually or via a OneWire component.

11. Why does DS18B20 work on Arduino but not on ESP32?

This usually happens because the DS18B20 expects 3.3V. Some Arduino modules run at 5V, so wiring must be adjusted. Also, ESP32 pins have different timing characteristics, so using proper libraries helps.

12. How do I send DS18B20 temperature data to Blynk using ESP32?

For esp32 ds18b20 blynk, read the temperature normally, then send values to a virtual pin (V1, V2, etc.) using Blynk.virtualWrite(). Use a timer, not delay(), to prevent blocking Wi-Fi updates.

13. Can I use DS18B20 with ESP32 over Bluetooth?

Yes. You can build an esp32 ds18b20 bluetooth thermometer by reading the temperature and sending it via BLE characteristics or Classic Bluetooth Serial. It’s useful for wireless temperature monitoring.

14. How do I add DS18B20 to Home Assistant using ESP32?

If you’re using esp32 ds18b20 home assistant, use ESPHome. The YAML config includes:

sensor:
  - platform: ds18b20
    pin: GPIO4

Home Assistant automatically detects it through ESPHome API.

15. Why does DS18B20 read inconsistently when using long wires with ESP32?

Long wires cause noise. To fix this:
• Use twisted pair or CAT6 cable
• Keep power at 3.3V
• Place pull-up resistor near ESP32
• Add a 100nF capacitor at the sensor

16. What is the simplest code to test ESP32 DS18B20 in Arduino IDE

You can test esp32 ds18b20 code with:

sensors.requestTemperatures();
Serial.println(sensors.getTempCByIndex(0));

If this prints values, your connection and libraries are correct.

17. What libraries should I install for DS18B20 on ESP32?

For esp32 ds18b20 arduino library, install:

  • OneWire
  • DallasTemperature

They handle ROM search, CRC checking, and scratchpad reading.

18. Why does my ESP32 DS18B20 project crash or freeze?

This can happen due to:

  • Weak USB power
  • WiFi + sensor reading blocking each other
  • Parasitic mode issues
  • Long wires without shielding

Use non-blocking timers and stable 5V power.

19. Can DS18B20 run in parasitic mode with ESP32?

Technically yes, but not recommended. ESP32 timing is sensitive, and many users report esp32 ds18b20 not working in parasitic mode. Use 3-wire mode for best reliability.

20. Where should I place the 4.7k resistor when interfacing DS18B20 with ESP32?

Place the resistor between DQ and 3.3V, ideally close to the ESP32 board. This makes the ds18b20 interface with esp32 more stable and prevents bus noise

Leave a Comment