ESP32and DS18B20 for LCD I2C 20x4 is Temperture -127

#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>
#include <OneWire.h>
#include <DallasTemperature.h>

// Define the GPIO pin for DS18B20
#define ONE_WIRE_BUS 22

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);

// Set the LCD address to 0x27 or 0x3F for a 20 chars and 4 line display
LiquidCrystal_PCF8574 lcd(0x27);

void setup(void) {
// Start the serial communication
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library");

// Initialize the DS18B20 sensor
sensors.begin();

// Initialize the LCD
lcd.begin(20, 4);
lcd.setBacklight(255); // Turn on the backlight

// Print initial message to the LCD
lcd.setCursor(0, 0);
lcd.print("Temperature Monitor");
}

void loop(void) {
// Request temperature from sensor
Serial.println("Requesting temperatures...");
sensors.requestTemperatures();

// Get temperature in Celsius
float temperatureC = sensors.getTempCByIndex(0);

// Print the temperature to the serial monitor
Serial.print("Temperature is: ");
Serial.print(temperatureC);
Serial.println(" *C");

// Display temperature on the LCD
lcd.setCursor(0, 2);
lcd.print("Temp: ");
lcd.print(temperatureC);
lcd.print(" C");

// Wait 1 second before repeating the loop
delay(1000);
}

type or paste code here

And?

When it comes on the screen it will always be negative. But if you use this code #include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 22 //define the pin to connect the Sensor
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup(void) {
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library");
sensors.begin();
}

void loop(void) {
Serial.println("Requesting temperatures...");
sensors.requestTemperatures(); //Read data from library
Serial.print("Temperature is: ");
Serial.print(sensors.getTempCByIndex(0)); // Display temperature value
Serial.println(" *C");
delay(1000);
} When it doesn't appear, the screen will appear normally.

Is the temprature negative in the Serial.print too?

One check you can do is to see if you have selected the correct GPIO pin in the code to the real pin on the ESP32, they are not the same I believe on the ESP variants, but I could be wrong.

I chose the correct pin as I checked.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.