Temperature Sensor always giving -127.00 C and 196.60 F as output

I am using a ESP32 board, and a DS18B20 temperature sensor.
i am connecting the VCC pin of the sensor to 3V3, GND pin to GND, and DQ pin to D4.
But, each time, I run the code, the output is always -127.00 C and -196.60 F, no matter whatever connections I use. I have also tried with a 4.7k Ohm resistor.

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

// GPIO where the DS18B20 is connected to
const int oneWireBus = 4;     

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

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

void setup() {
  // Start the Serial Monitor
  Serial.begin(115200);
  // Start the DS18B20 sensor
  sensors.begin();
}

void loop() {
  sensors.requestTemperatures(); 
  float temperatureC = sensors.getTempCByIndex(0);
  float temperatureF = sensors.getTempFByIndex(0);
  Serial.print(temperatureC);
  Serial.println("ºC");
  Serial.print(temperatureF);
  Serial.println("ºF");
  delay(5000);
}

This is the code I am using.

Can anyone please help me out ?

How was the resistor connected? The pullup resistor is required for proper operation.

Post a hand drawn schematic showing your wiring, please. Post photos of your wiring.

Thanks for posting code properly. Most new users do not and have go be asked to read the guidelines.

I am new to Arduino programming. This is how I have connected the resistor.

do you think somebody can understand from your image how the elements are actually connected? :slight_smile:

I get that the board in the background could be your ESP32, but I can't figure the board in the foreground. The DS18B20 is a simple device that needs a 4.7K pull up resistor. The board in the photo looks like it may be some sort of IR sender/receiver if that's an IR LED at the top of the board.

Please post more photos. You can always hand draw a block diagram showing the connections (and pin numbers) and then take a photo of it to upload here.

Try a search engine. -127 apparently means that the library can't see any sensors. Likely a wiring error or perhaps your DS18B20 is kaput.

Hi,
see in this link the correct way to connect a 18B20 to an ESP32.

Hi, @mainak_chandra
Welcome to the forum.

Can you please post a circuit diagram of your project, including power supplies, use a pen(cil) and paper and show an image of it would be fine.

Can you please post an image of your sensor module?
Can you please post a link to where you purchased the sensor.

I don't remember seeing a module like that with a trim pot on the board.

Thanks.. Tom.... :smiley: :+1: :coffee: :australia:

Tom, i've not seen one like that either. @mainak_chandra are you sure that the board we see in your photo has a DS18B20 temperature sensor on it? Can you upload a photo of the front of the board?

It's possible that the board in the photo carries out another function, but also has a DS18B20 temperature sensor on it. I have a TINY-RTC board that has a 24C32 and a DS1307 on it, but it also has space to add a DS18B20 as well.

I am guessing that:
A. The module in the photo is not a DS18B20 temperature sensor
B. The resistor is not placed correctly.

But those are guesses because the photo does not show much of anything of relevance. In the photos, we need to see every component so that we can identify it and we need to see where every wire goes.

1 Like

Great! a puzzle!
This is the temperature module: https://www.elecbee.com/en-26166-30pcs-Thermal-Sensor-Module-Temperature-Switch-Thermistor-Sensor-Board.
It is a NTC with a resistor and a useless amplifier for a useless digital output.

1 Like

Wow, $14.99 for that? Should, at least, buy me dinner first.

A new variation on GIGO.

The board you have does not use the one wire comm system. It just provides a digital output (1 or 0)
and an anlog output you can measure with one of your analog inputs.
So: your description is wrong;
your expectations are wrong; and
your code is wrong.

1 Like

Sorry! I am new to Arduino programming. So I messed everything up.
I am using an NTC Thermistor, and not DS18B20.

I am trying to use this design.

The design is of DS18B20, but I am using it for NTC.
My sensor is connected. But, the readings are always the extreme -127.00 C.

Can someone please point out the mistake I am making ?

Why? You've just said that the sensor you have isn't a DS18B20. The DS18B20 library won't work with the sensor you have.

Then what library should I use for NTC? I know very less about hardware programming?

Hi,

What part number has your module got?
It is an analog output device.

Uses:
Temperature detection, temperature control sensors , ambient temperature detection
Features

  1. Using the NTC thermistor sensor, good sensitivity
  2. The comparator output signal is clean, good waveform, driving ability, more than 15mA.
  3. Adjust the temperature distribution position detection threshold
  4. The working voltage 3.3V-5V
  5. The output format: digital switching outputs ( 0 and 1 )
  6. Fixed bolt holes for easy installation
  7. Small PCB board size: 3.2cm x 1.4cm
  8. Using a wide voltage LM393 comparator
    Module for use:
  9. The thermal resistance of the module is very sensitive to the ambient temperature, typically for detecting the temperature of the surrounding environment ;
  10. Through the potentiometer adjustment, you can change the temperature detection threshold ( ie, control temperature ), such as the need to control the ambient temperature is 50 degrees, the module in the corresponding ambient temperature to its green light , DO high power output when flat, set the temperature below this value, the output is high , the green light does not shine ;
  11. DO output can be directly connected to the microcontroller through the microcontroller to detect high and low, thereby detecting temperature changes in the environment ;
  12. DO output of the relay module can directly drive the shop, which can be composed of a thermostat to control the temperature of work-related equipment can also be connected to the cooling fan, etc. ;
  13. The temperature detection range of the modules 20 to 80 ° C ;
  14. The module can be replaced with a line of temperature sensors used to control the water temperature, water and the like.

Tom... :smiley: :+1: :coffee: :australia:

thermistor-temperature-sensor-module-india-400x400 (1)

I do not know the part number . This is my device.

Here is what a search for "thermistor module tutorial arduino" turns up.

Or:

It looks like that module has variable sensitivity. Presumably you would need to calibrate it in order to extract any useful temperature measurement from it.