DS18b20 Troubleshooting

I am trying to get my Arduino Uno to read the DS18B20 sensor I bought on Amazon and it will return -127C on the serial monitor no matter what I do.

I have wired it exactly as instructed :

and downloaded the OneWire and Dallas Temperature libraries.

I am running the Single example from the Dallas Temperature Library and all I am getting is -127C

Any help is greatly appreciated.

Please.

In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.

Use the </> icon from the ‘posting menu’ to attach the copied sketch.

BTW, your schematic is wrong !

image

Sorry,
It is straight from the tutorial (Link: https://arduinogetstarted.com/tutorials/arduino-temperature-sensor)
Here is the code:

/*
 * Created by ArduinoGetStarted.com
 *
 * This example code is in the public domain
 *
 * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-temperature-sensor
 */

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

const int SENSOR_PIN = 13; // Arduino pin connected to DS18B20 sensor's DQ pin

OneWire oneWire(SENSOR_PIN);         // setup a oneWire instance
DallasTemperature tempSensor(&oneWire); // pass oneWire to DallasTemperature library

float tempCelsius;    // temperature in Celsius
float tempFahrenheit; // temperature in Fahrenheit

void setup()
{
  Serial.begin(9600); // initialize serial
  tempSensor.begin();    // initialize the sensor
}

void loop()
{
  tempSensor.requestTemperatures();             // send the command to get temperatures
  tempCelsius = tempSensor.getTempCByIndex(0);  // read temperature in Celsius
  tempFahrenheit = tempCelsius * 9 / 5 + 32; // convert Celsius to Fahrenheit

  Serial.print("Temperature: ");
  Serial.print(tempCelsius);    // print the temperature in Celsius
  Serial.print("°C");
  Serial.print("  ~  ");        // separator between Celsius and Fahrenheit
  Serial.print(tempFahrenheit); // print the temperature in Fahrenheit
  Serial.println("°F");

  delay(500);
}

Yes the schematic is wrong. Compare it with the drawing with the breadbord just
above it. Check the read and yellow wires
/ffur

You have the +5v going to Data.
There should be a 4.7k resistor going from +5v to the data.
Datasheet for DS18B20+T Analog Devices | Octopart
Good luck...........

I swear I caught that mistake on the diagram the first few times I tried the sensor but wiring it up this time it works perfectly so I must have repetitively overlooked it. Thanks for the help it is working now!

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