# Ds18b20 wrong value if temperature is below 0 degrees

**URL:** <https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812>\
**Category:** General\
**Created:** [11 February 2021 11:11 UTC](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812 "2021-02-11T11:11:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Speedy](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@Speedy](https://discourse.nodered.org/u/Speedy)\
**Post date:** [11 February 2021 11:11 UTC](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812/1 "2021-02-11T11:11:12Z")

</div>

Hi,  
i use the ds18b20 sensor with raspberry. Since update to node-red 1.2.9. the values of temperatures below 0 degrees are showing wrong. There is p.e.4093.9. What can i do?

Thanks

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 February 2021 11:31 UTC](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812/2 "2021-02-11T11:31:37Z")

</div>

Welcome to the forum @Speedy.

Please feed the output of the sensor node into a Debug node and screenshot what you see in the debug pane. You can paste an image here directly. Also tell us which node you are using, there are several DS18b20 nodes. It is probably node-red-contrib-something. If you are not sure look in Manage Palette to find out,

Also stop node red then start it again in a terminal using node-red-start and copy/paste here what you get. Copy/paste for this please not a screenshot. When pasting logs or flows here use the `</>` button at the top of the forum entry window and paste it in. The startup log will tell us a lot about your system.

---

<div class="post-metadata">

**Author:** ![Speedy](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@Speedy](https://discourse.nodered.org/u/Speedy)\
**Post date:** [11 February 2021 11:33 UTC](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812/3 "2021-02-11T11:33:23Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/c/8c5a1f0d140c4429bb380c7378c369949feb8c18.png)

Node: node-red-contrib-sensor-ds18b20

It's work before the update fine. All other sensors \> 0 degrees are ok.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 February 2021 11:51 UTC](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812/4 "2021-02-11T11:51:46Z")

</div>

If you warm it up is it ok again?

Don't forget the log.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 February 2021 11:53 UTC](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812/5 "2021-02-11T11:53:43Z")

</div>

> [@Speedy](#):
>
> node-red-contrib-sensor-ds18b20

Is this you or somebody else? [Fails to read negative temperatures!! (Any more!!) · Issue #6 · charlielito/node-red-contrib-sensor-ds18b20 · GitHub](https://github.com/charlielito/node-red-contrib-sensor-ds18b20/issues/6)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [11 February 2021 12:01 UTC](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812/6 "2021-02-11T12:01:17Z")

</div>

What version of Raspibian are you using?

Doing a search I found a [thread](https://www.robo-tank.ca/forum/Thread-DS18B20-probe-negative-temperature?pid=6073#pid6073) that had a similar issue and doing a `apt full-upgade` fixed it. Worth a try

---

<div class="post-metadata">

**Author:** ![Speedy](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@Speedy](https://discourse.nodered.org/u/Speedy)\
**Post date:** [11 February 2021 12:04 UTC](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812/7 "2021-02-11T12:04:25Z")

</div>

Yes. Positive temperature is show correct.

---

<div class="post-metadata">

**Author:** ![Speedy](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@Speedy](https://discourse.nodered.org/u/Speedy)\
**Post date:** [11 February 2021 12:06 UTC](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812/8 "2021-02-11T12:06:56Z")

</div>

Hi, i've the up to date version. Full-upgrade show that no updates available. The problem is since the note-red update.

---

<div class="post-metadata">

**Author:** ![Speedy](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@Speedy](https://discourse.nodered.org/u/Speedy)\
**Post date:** [11 February 2021 12:07 UTC](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812/9 "2021-02-11T12:07:31Z")

</div>

Yes! That's my problem, too.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 February 2021 12:09 UTC](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812/11 "2021-02-11T12:09:51Z")

</div>

OK, show us the startup log then please.

---

<div class="post-metadata">

**Author:** ![Speedy](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@Speedy](https://discourse.nodered.org/u/Speedy)\
**Post date:** [11 February 2021 12:11 UTC](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812/12 "2021-02-11T12:11:47Z")

</div>

```auto
11 Feb 13:11:10 - [info]
Willkommen bei Node-RED!
===================
11 Feb 13:11:10 - [info] Node-RED Version: v1.2.9
11 Feb 13:11:10 - [info] Node.js Version: v12.20.1
11 Feb 13:11:10 - [info] Linux 5.10.11-v7+ arm LE
11 Feb 13:11:11 - [info] Paletten-Nodes werden geladen
11 Feb 13:11:13 - [info] Einstellungsdatei: /root/.node-red/settings.js
11 Feb 13:11:13 - [info] Kontextspeicher: 'default' [module=memory]
11 Feb 13:11:13 - [info] Benutzerverzeichnis: /root/.node-red
11 Feb 13:11:13 - [warn] Projekte inaktiviert: editorTheme.projects.enabled=false
11 Feb 13:11:13 - [info] Flow-Datei: /root/.node-red/flows_raspberrypi.json
11 Feb 13:11:13 - [warn]
---------------------------------------------------------------------
Die Datei mit den Datenflowberechtigungsnachweisen wird mit einem vom System generierten Schlüssel verschlüsselt.
Wenn der vom System generierte Schlüssel aus irgendeinem Grund verloren geht, werden Ihre Berechtigungsnachweise
Die Datei kann nicht wiederhergestellt werden. Sie müssen sie löschen und erneut eingeben.
Ihre Berechtigungsnachweise.
Sie sollten Ihren eigenen Schlüssel mit Hilfe der Option 'credentialSecret' in
Ihre Einstellungsdatei. Node-RED wird dann Ihre Berechtigungsnachweise erneut verschlüsseln.
Datei mit dem ausgewählten Schlüssel beim nächsten Deployen einer Änderung verwenden.
---------------------------------------------------------------------
11 Feb 13:11:13 - [info] Flows starten
11 Feb 13:11:13 - [info] Flows gestartet
11 Feb 13:11:13 - [info] Server wird jetzt auf http://127.0.0.1:1880/ ausgeführt.

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 February 2021 12:15 UTC](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812/13 "2021-02-11T12:15:17Z")

</div>

It appears you didn't use the [recommended script](https://nodered.org/docs/getting-started/raspberrypi) to install node red, so somehow you are running as root. Which is a bad idea.

---

<div class="post-metadata">

**Author:** ![Speedy](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@Speedy](https://discourse.nodered.org/u/Speedy)\
**Post date:** [11 February 2021 12:19 UTC](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812/14 "2021-02-11T12:19:06Z")

</div>

I've use this script. Is the root-install the problem?

Edit: I've (re)install node-red after normal apt upgrade, because the nagative problem.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 February 2021 12:23 UTC](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812/15 "2021-02-11T12:23:51Z")

</div>

I don't know whether that is the problem. How are you running as root? Did you run teh script using sudo or logged on as root or something like that?

This tutorial shows you how you can look at the system pseudo files for the sensor to check that the system side of it is working. [Raspberry Pi Tutorial Series: 1-Wire DS18B20 Sensor - Waveshare Wiki](https://www.waveshare.com/wiki/Raspberry_Pi_Tutorial_Series:_1-Wire_DS18B20_Sensor)

---

<div class="post-metadata">

**Author:** ![Speedy](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@Speedy](https://discourse.nodered.org/u/Speedy)\
**Post date:** [11 February 2021 12:26 UTC](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812/16 "2021-02-11T12:26:08Z")

</div>

I was logged on as root ☹  
The sensor is ok. If the temperature positive then the correct value is shown.

I've 13 ds18b20 sensors, but the only with negative temperature don't work.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [11 February 2021 13:23 UTC](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812/17 "2021-02-11T13:23:56Z")

</div>

Have you tried any of the other ds18b20 nodes?

---

<div class="post-metadata">

**Author:** ![Speedy](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@Speedy](https://discourse.nodered.org/u/Speedy)\
**Post date:** [11 February 2021 13:39 UTC](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812/18 "2021-02-11T13:39:41Z")

</div>

I've tried one other node. There i must add a Topic and can not choose a SensorID. I don't no how this work. The values shouldt stored in the influxdb.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 February 2021 13:48 UTC](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812/19 "2021-02-11T13:48:55Z")

</div>

Did you check the /sys files as I suggested?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 February 2021 13:55 UTC](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812/20 "2021-02-11T13:55:28Z")

</div>

> [@Speedy](#):
>
> I was logged on as root

You should not even have the root user enabled. There is never any need for that.

---

<div class="post-metadata">

**Author:** ![RadioFlyer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/radioflyer/32/21310_2.png) [@RadioFlyer](https://discourse.nodered.org/u/RadioFlyer)\
**Post date:** [11 February 2021 14:25 UTC](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812/21 "2021-02-11T14:25:35Z")

</div>

I can't help you directly but I ran into a similar problem with a sketch running on a ESP8266 and found the following which fixed my code. Apparently Arduinos do the math differently and don't have the issue. I rather suspect that the following lies at the heart of your issue.

" 'byte' is unsigned. When you put MSB and LSB together on UNO or NANO, it seems that (MSB \<\< 8)|LSB results in the correct signed number. But on the ESP8266 it looks like it results in an unsigned number. This will turn all negative numbers into large positive ones. For example, 0xFFF8 is -0.5 degrees, but as a positive number it is 65528 and dividing by 16 gives you 4095.5.  
Throwing (int16\_t) on the front forces the compiler to treat the result as a signed 16-bit integer which then gives the correct result."

[Next page](https://discourse.nodered.org/t/ds18b20-wrong-value-if-temperature-is-below-0-degrees/40812.md?page=2)
