Waterproof DS18B20 only showing -127 degrees celsius

This is my code. My goal is for the sensor to read the temperature of the water and then print whether it is a good temperature for a plant (hydroponics). I changed the wiring and code several times (using the same materials) but kept getting the same results. Please help me!

//libraries
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS (pin number)

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

float Celsius = 0;
float Fahrenheit = 0;

//RGB pins
const int redPin = 9;
const int greenPin = 8;
const int bluePin = 7;
int redValue;
int greenValue;
int blueValue;

#include <LiquidCrystal.h> //the liquid crystal library contains commands for printing to the display
  LiquidCrystal lcd(12, 11, 6, 5, 4, 3);
  const int backlight = 13;

void setup() {
sensors.begin;
Serial.begin(9600);

  pinMode(backlight, OUTPUT);
    digitalWrite(backlight, HIGH);
    lcd.begin(16,2); // the the lcd display we are using a display that is 16 characters wide and 2 characted high
    lcd.setCursor (0,0); //set the cursor to the (0,0) position (top left corner -  first row and column
} //end of setup

 void setColor(int redValue, int greenValue, int blueValue)
  {
    analogWrite(redPin, redValue);
    analogWrite(greenPin, greenValue);
    analogWrite(bluePin, blueValue);
} //end of setColor

void loop() {
sensors.requestTemperatures();
Celsius = sensors.getTempCByIndex;
Fahrenheit = sensors.toFahrenheit(Celsius);
Serial.print(Celsius);
Serial.print(“ C “);
Serial.print(Fahrenheit);
Serial.print(“ F “);
delay(1000);

if (Fahrenheit < 60) {
setColor(0, 0, 255);
lcd.print(“Temp : cold”);
lcd.display();
} //end of if

if ((Fahrenheit > 60) && (Fahrenheit < 70)) {
setColor(255, 255, 0);
lcd.print(“Temp: good”);
lcd.display();
} //end of if

if (Fahrenheit > 70) {
setColor(255, 165, 0);
lcd.print(“Temp: hot”);
lcd.display();
} //end of if
} //end of loop

That is the standard error code for the DS18B20. Doesn't identify the error, though. Show us how you have the device wired, please!

1 Like

Have you tried a simple sketch to set up and read the device?
I mean something like what is described in this article.

Once that is working, I would slowly add the other code.

1 Like

You are getting the address of the member function. You want to actually execute it.

Celsius = sensors.getTempCByIndex();
1 Like
  • Do you have pull-up on the sensor ?
1 Like

Thank u guys but I realized that the sensor itself was a problem. But thx so much for the quick responses!!

1 Like

Yes it does. It means " not connected "

2 Likes

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