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() {
sensors.begin();
Serial.begin(9600);
}
void loop() {
sensors.requestTemperatures();
Celsius = sensors.getTempCByIndex(0);
Fahrenheit = sensors.toFahrenheit(Celsius);
Serial.print(Celsius);
Serial.print("°C");
Serial.println(" ");
Serial.print(Fahrenheit);
Serial.println("°F");
delay(5000);
}