ArduinoGeneral

DSB18B20 Digital Temperature fails to deliver correct

userHead lehoang96 2020-08-31 13:40:55 38330 Views19 Replies
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.
Code: Select all
#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;

}
The result (Serial.print) can be seen in the attached file.

Any idea on the solution? Thanks.
icon Screenshot.png Download(0)
2021-04-25 18:40:54 Thank you for sharing your valuable information. Your website contains very informative information. 메이저놀이터 userHeadPic anan2384112
2021-04-25 18:40:54 Thank you for sharing your valuable information. Your website contains very informative information. 메이저놀이터 userHeadPic 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
userHeadPic lehoang96
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
userHeadPic lehoang96
2020-09-07 12:19:35
nana.wang wrote:
Fri Sep 04, 2020 7:48 am

2. Please measure whether the voltage at the two red boxes is around 5V.
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.
userHeadPic lehoang96
2020-09-07 12:19:35
nana.wang wrote:
Fri Sep 04, 2020 7:48 am

2. Please measure whether the voltage at the two red boxes is around 5V.
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.
userHeadPic lehoang96
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
userHeadPic lehoang96
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
userHeadPic lehoang96
2020-09-03 13:43:24
nana.wang wrote:
Wed Sep 02, 2020 5:36 am
Hi, could you please share the full product name or SKU No.?
So that we can check it ASAP.
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.
userHeadPic lehoang96
2020-09-03 13:43:24
nana.wang wrote:
Wed Sep 02, 2020 5:36 am
Hi, could you please share the full product name or SKU No.?
So that we can check it ASAP.
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.
userHeadPic lehoang96
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.
Code: Select all
#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;

}
The result (Serial.print) can be seen in the attached file.

Any idea on the solution? Thanks.
userHeadPic lehoang96