DSB18B20 Digital Temperature fails to deliver correct

For a project on water quality monitoring system, multiple sensors are deployed to gather the data. Among them is the DS18B20 sensor. During testing period (ie: individual testing each sensor), the temperature fails to show a "meaningful" answer.
Instead of returning something in the range of 25 to 30 degree C (I'm in an air-conditioned room with windows opened, and my area is tropical), the data returned in "-1000.00". The sensor is working, but for some reasons, it does not return the correct value. And with the temperature being read wrong, all associated data (pH and electrical conductivity) will also be wrong.
The code is pretty much a copy-paste from DFRobot wiki. Note: This is just the temperature segment.
Any idea on the solution? Thanks.
Instead of returning something in the range of 25 to 30 degree C (I'm in an air-conditioned room with windows opened, and my area is tropical), the data returned in "-1000.00". The sensor is working, but for some reasons, it does not return the correct value. And with the temperature being read wrong, all associated data (pH and electrical conductivity) will also be wrong.
The code is pretty much a copy-paste from DFRobot wiki. Note: This is just the temperature segment.
Code: Select all
The result (Serial.print) can be seen in the attached file.#include <OneWire.h>
int DS18S20_Pin = 48; //DS18S20 Signal pin on digital 48
//Temperature chip i/o
OneWire ds(DS18S20_Pin); // on digital pin 48
void setup(void) {
Serial.begin(9600);
}
void loop(void) {
delay(1000);
float temperature = getTemp();
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print("C deg");
Serial.println("");
delay(100); //just here to slow down the output so it is easier to read
}
float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -1000;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return -1000;
}
if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print("Device is not recognized");
return -1000;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for (int i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}
ds.reset_search();
byte MSB = data[1];
byte LSB = data[0];
float tempRead = ((MSB << 8) | LSB); //using two's compliment
float TemperatureSum = tempRead / 16;
return TemperatureSum;
}
Any idea on the solution? Thanks.

2021-04-25 18:40:54 Thank you for sharing your valuable information. Your website contains very informative information. 메이저놀이터
anan2384112

2021-04-25 18:40:54 Thank you for sharing your valuable information. Your website contains very informative information. 메이저놀이터
anan2384112

2020-09-07 14:10:53 Actually, nevermind. I find the issue. It is because of the connection wires.
Yes, some wires are too crap that the electricity and power cannot be supplied and transferred correctly. It is giving more meaningful numbers now, 25C for plain water, and 8~9C for iced water
lehoang96
Yes, some wires are too crap that the electricity and power cannot be supplied and transferred correctly. It is giving more meaningful numbers now, 25C for plain water, and 8~9C for iced water

2020-09-07 14:10:53 Actually, nevermind. I find the issue. It is because of the connection wires.
Yes, some wires are too crap that the electricity and power cannot be supplied and transferred correctly. It is giving more meaningful numbers now, 25C for plain water, and 8~9C for iced water
lehoang96
Yes, some wires are too crap that the electricity and power cannot be supplied and transferred correctly. It is giving more meaningful numbers now, 25C for plain water, and 8~9C for iced water

2020-09-07 12:19:35
I'd say the problem is with the board, not the sensor (probably). I think I will ask the seller (I buy this via a middle man) to see if they have any warranty policy.
lehoang96
This is where the problem is, I suppose. I measure the voltage between the 2 red boxes, and I only have 0.2V. I double check the Arduino board (Mega 2560, also from DFRobot), and I see that between the 5V and the GND, there is only ~0.2V.
I'd say the problem is with the board, not the sensor (probably). I think I will ask the seller (I buy this via a middle man) to see if they have any warranty policy.

2020-09-07 12:19:35
I'd say the problem is with the board, not the sensor (probably). I think I will ask the seller (I buy this via a middle man) to see if they have any warranty policy.
lehoang96
This is where the problem is, I suppose. I measure the voltage between the 2 red boxes, and I only have 0.2V. I double check the Arduino board (Mega 2560, also from DFRobot), and I see that between the 5V and the GND, there is only ~0.2V.
I'd say the problem is with the board, not the sensor (probably). I think I will ask the seller (I buy this via a middle man) to see if they have any warranty policy.

2020-09-04 12:24:07 Attached is my hardware connection, can you check if I have done it correctly?
And yes, the digital wire (the white one) is in Pin Digital 48, it is slightly hard to see at this angle. Both the power and the ground (red and black) are connected to the 5V and GND on the digital side. I've checked with both the Power and the Digital series of pin (Red and Black on the Arduino Mega 2560 from DFRobot), but nothing changes. The value returned is still -1000.
Something is wrong about the hardware, but I'm not sure which one it is
lehoang96
And yes, the digital wire (the white one) is in Pin Digital 48, it is slightly hard to see at this angle. Both the power and the ground (red and black) are connected to the 5V and GND on the digital side. I've checked with both the Power and the Digital series of pin (Red and Black on the Arduino Mega 2560 from DFRobot), but nothing changes. The value returned is still -1000.
Something is wrong about the hardware, but I'm not sure which one it is

2020-09-04 12:24:07 Attached is my hardware connection, can you check if I have done it correctly?
And yes, the digital wire (the white one) is in Pin Digital 48, it is slightly hard to see at this angle. Both the power and the ground (red and black) are connected to the 5V and GND on the digital side. I've checked with both the Power and the Digital series of pin (Red and Black on the Arduino Mega 2560 from DFRobot), but nothing changes. The value returned is still -1000.
Something is wrong about the hardware, but I'm not sure which one it is
lehoang96
And yes, the digital wire (the white one) is in Pin Digital 48, it is slightly hard to see at this angle. Both the power and the ground (red and black) are connected to the 5V and GND on the digital side. I've checked with both the Power and the Digital series of pin (Red and Black on the Arduino Mega 2560 from DFRobot), but nothing changes. The value returned is still -1000.
Something is wrong about the hardware, but I'm not sure which one it is

2020-09-03 13:43:24
I've also checked on other websites, and I have also tried directly plug in the sensor into the board with a 4k7 pull-up resistor (between the 5V and the data pin). The code is consulted from Arduino CC, and the result returns also say that the device is not connected.
I've also buys the sensor (same sensor) from another shop. Nothing changes.
lehoang96
It's SKU DFR0024. The Wiki link is [urlhttps://wiki.dfrobot.com/Gravity__DS18B20_Temperature_Sensor__Arduino_Compatible__V2_SKU__DFR0024]here[/url].
I've also checked on other websites, and I have also tried directly plug in the sensor into the board with a 4k7 pull-up resistor (between the 5V and the data pin). The code is consulted from Arduino CC, and the result returns also say that the device is not connected.
I've also buys the sensor (same sensor) from another shop. Nothing changes.

2020-09-03 13:43:24
I've also checked on other websites, and I have also tried directly plug in the sensor into the board with a 4k7 pull-up resistor (between the 5V and the data pin). The code is consulted from Arduino CC, and the result returns also say that the device is not connected.
I've also buys the sensor (same sensor) from another shop. Nothing changes.
lehoang96
It's SKU DFR0024. The Wiki link is [urlhttps://wiki.dfrobot.com/Gravity__DS18B20_Temperature_Sensor__Arduino_Compatible__V2_SKU__DFR0024]here[/url].
I've also checked on other websites, and I have also tried directly plug in the sensor into the board with a 4k7 pull-up resistor (between the 5V and the data pin). The code is consulted from Arduino CC, and the result returns also say that the device is not connected.
I've also buys the sensor (same sensor) from another shop. Nothing changes.

2020-08-31 13:40:55 For a project on water quality monitoring system, multiple sensors are deployed to gather the data. Among them is the DS18B20 sensor. During testing period (ie: individual testing each sensor), the temperature fails to show a "meaningful" answer.
Instead of returning something in the range of 25 to 30 degree C (I'm in an air-conditioned room with windows opened, and my area is tropical), the data returned in "-1000.00". The sensor is working, but for some reasons, it does not return the correct value. And with the temperature being read wrong, all associated data (pH and electrical conductivity) will also be wrong.
The code is pretty much a copy-paste from DFRobot wiki. Note: This is just the temperature segment.
Any idea on the solution? Thanks.
lehoang96
Instead of returning something in the range of 25 to 30 degree C (I'm in an air-conditioned room with windows opened, and my area is tropical), the data returned in "-1000.00". The sensor is working, but for some reasons, it does not return the correct value. And with the temperature being read wrong, all associated data (pH and electrical conductivity) will also be wrong.
The code is pretty much a copy-paste from DFRobot wiki. Note: This is just the temperature segment.
Code: Select all
The result (Serial.print) can be seen in the attached file.#include <OneWire.h>
int DS18S20_Pin = 48; //DS18S20 Signal pin on digital 48
//Temperature chip i/o
OneWire ds(DS18S20_Pin); // on digital pin 48
void setup(void) {
Serial.begin(9600);
}
void loop(void) {
delay(1000);
float temperature = getTemp();
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print("C deg");
Serial.println("");
delay(100); //just here to slow down the output so it is easier to read
}
float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -1000;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return -1000;
}
if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print("Device is not recognized");
return -1000;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for (int i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}
ds.reset_search();
byte MSB = data[1];
byte LSB = data[0];
float tempRead = ((MSB << 8) | LSB); //using two's compliment
float TemperatureSum = tempRead / 16;
return TemperatureSum;
}
Any idea on the solution? Thanks.
