Issue while interfacing DS18B20 with ESP32

I’m trying to connect DS18B20 with ESP32 and i tried with Arduino Uno as well but in both micro-controllers I’m facing the sensor reading values it’s showing temp in serial monitor as -127°C and -196.6°F . The sensor is a new one i bought yesterday and I used a sensor which is a little older one but both of them are showing the same readings. what may be the problem?

#include <OneWire.h>
#include <DallasTemperature.h>
#include <WiFi.h>
#include <WiFiClient.h>

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

float Celsius = 0;
float Fahrenheit = 0;

void setup() {

void loop() {

  Celsius = sensors.getTempCByIndex(0);
  Fahrenheit = sensors.toFahrenheit(Celsius);

  Serial.println(" ");

-127 is the default value returned by the library when it can’t communicate with the sensor.

Pin 2 isn’t a great choice on the ESP32, as it’s a strapping oin and also has the inbuilt LED connected to it.

Does your sensor require a 4.7k pull-up resistor, or is it one of the ones that has this built in?

You don’t have any Blynk code in your sketch. I assume that you’re going to add thuis later? If you do then you can’t do this in your void loop…


oh … oh, I operated DS18B20 with ESP32 without connecting it with any resistor. Because I have no idea about these resistor connecting stuffs, will it cause damage to the sensor?
Yes I don’t have Blynk code in my sketch because for my project I’m just breaking down the larger stuffs into small chunks.

Probably not.

Sounds like you need to research your sensor, and also the best pins to use on the ESP32.