My Dallas 18b20 isn't working

I've tried almost everything but the sensor is still showing -127 degrees. No matter which diagram or code i use it doesn't change anything at all. I downloaded the libraries and used diagrams with and without resistance. I also tried using 2 temperature sensors because my professor said so. I tried using analog pins as well as digital ones. Still nothing works.

Here's the code I'm currently using:

#include <OneWire.h>
#include <DallasTemperature.h>
float temp = 0.0;

int oneWireBus = 3;
OneWire oneWire(oneWireBus);
DallasTemperature sensors(&oneWire);

void setup() {
Serial.begin(9600);
Serial.println("Bas on Tech - 1-wire temperature sensor");
sensors.begin();
}

void loop() {

 sensors.requestTemperatures();
 temp = sensors.getTempCByIndex(0);

 Serial.print("Temperature is: ");
 Serial.println(temp);

 delay(1000);

}

Thank you so much in advance.

Welcome. You may have more luck posting in the Sensors section. I've flagged your post so it should get moved.

How have you wired up the sensor and which board do you have?

Hey, thank you so much.
I use the ESP8266 Board

@lovefordallas, your topic has been moved to a more suitable section on the forum; thanks @markd833 for picking it up.

There should be a resistor in there somewhere. Have a look at ESP8266 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) which should show you how it's done.

I used the diagram and code and it's still not working :frowning:

Your sketch with little modification is working fine with my ESP8266 based NodeMCU.

Output:

Temperature is: 25.56
Temperature is: 25.50
Temperature is: 25.56
Temperature is: 25.88
Temperature is: 25.63
Temperature is: 25.94

1. Connect Data-pin of sensor with D4-pin of the board.
2.
(1) Change this line: int oneWireBus = 3; to the following:
int oneWireBus = 2;
(2) Use direct one jumper for one connection.
(3) Use 2.2k to 4.7k resistor between Data-pin and Vcc (3.3V).
(4) Do not use TX (GPIO-1) and RX (GOPIO-3) pins of the ESP8266 as they are engaged with PC/IDE/SM.
(5) Pin diagram (Fig-1) of DS18B20 temperature sensor.
DS18B20Pic
Figure-1:

3. I am using this ESP8266 based NodeMCU (Fig-2).


Figure-2:

4. the sketch (your one)

#include <OneWire.h>
#include <DallasTemperature.h>
float temp = 0.0;

int oneWireBus = 2;
OneWire oneWire(oneWireBus);
DallasTemperature sensors(&oneWire);

void setup()
{
  Serial.begin(115200);
  Serial.println("Bas on Tech - 1-wire temperature sensor");
  sensors.begin();
}

void loop() 
{

  sensors.requestTemperatures();
  temp = sensors.getTempCByIndex(0);

  Serial.print("Temperature is: ");
  Serial.println(temp);

  delay(1000);
}

Your photo doesn't match the pinout that @GolamMostafa shows above. You've got the sensor comnected wrong.

I have connected sensor at D4-pin (GPIO2). I have suggested OP to do the same thing.

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