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);
}
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.
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.
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.
Uses:
Temperature detection, temperature control sensors , ambient temperature detection
Features
Using the NTC thermistor sensor, good sensitivity
The comparator output signal is clean, good waveform, driving ability, more than 15mA.
Adjust the temperature distribution position detection threshold
The working voltage 3.3V-5V
The output format: digital switching outputs ( 0 and 1 )
Fixed bolt holes for easy installation
Small PCB board size: 3.2cm x 1.4cm
Using a wide voltage LM393 comparator Module for use:
The thermal resistance of the module is very sensitive to the ambient temperature, typically for detecting the temperature of the surrounding environment ;
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 ;
DO output can be directly connected to the microcontroller through the microcontroller to detect high and low, thereby detecting temperature changes in the environment ;
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. ;
The temperature detection range of the modules 20 to 80 ° C ;
The module can be replaced with a line of temperature sensors used to control the water temperature, water and the like.
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.