# How to convert my modbus data to Fahrenheit

**URL:** <https://discourse.nodered.org/t/how-to-convert-my-modbus-data-to-fahrenheit/40398>\
**Category:** General\
**Created:** [4 February 2021 19:39 UTC](https://discourse.nodered.org/t/how-to-convert-my-modbus-data-to-fahrenheit/40398 "2021-02-04T19:39:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjw](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@jjw](https://discourse.nodered.org/u/jjw)\
**Post date:** [4 February 2021 19:39 UTC](https://discourse.nodered.org/t/how-to-convert-my-modbus-data-to-fahrenheit/40398/1 "2021-02-04T19:39:45Z")

</div>

I have a ADAMS 6015 RTD module which i wanna use with node red. Can only communication  
with it via Modbus read. I have gotten as far as getting decimal and hexadecimal temperature values back to node red via Modbus read. Is there any way to get actual Celsius values back to node red, Since the module already converts rtd to Celsius? Also not quite sure on how the modbus address works.  
Below is screenshot of what rtd is displaying now, and of the modbus address in utility, and of modbus from user manual. also screenshot of values in node red.

 ![adams1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/4/548670b250aa442d79b3509e0b437be97df5b29a.png) ![adams2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/3/833168643aca4d18b046741384d6ad607472e16d.png) ![adams3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/0/10f837a722934e501be0fc568c53d56757807652.png) ![adams4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/5/35eb9cad0178788f7e786dd947d939bcd409716f.png)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [4 February 2021 20:20 UTC](https://discourse.nodered.org/t/how-to-convert-my-modbus-data-to-fahrenheit/40398/2 "2021-02-04T20:20:15Z")

</div>

I'm confused.

One of these ~~devices~~ nodes gives you a _reading_ which is the temperature, and as it **gives** you the reading, that node would have an output.

Going on what you have shown with your screen shot, that is the one called `rtd`, and it has 2 outputs.

If you connect those outputs to a `debug` node and set it to show the entire message: what happens?

Oh, and what is the temperature at the time of taking the reading?

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [4 February 2021 21:29 UTC](https://discourse.nodered.org/t/how-to-convert-my-modbus-data-to-fahrenheit/40398/3 "2021-02-04T21:29:25Z")

</div>

Hi,

In order to get the Modbus decimal to Eng units you need to use this formula according to the docs.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/f/0f12a4fa27185e6347acf190a8c0ccac33680152.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/6/766c6d1fcd9b9284d8e8c272c6522319b3318c41.png)

**Example Flow:**

```auto
[{"id":"e408ef72.58812","type":"inject","z":"94ab22aa.035ba","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"22048","payloadType":"num","x":210,"y":1040,"wires":[["dda5ae4b.3055b"]]},{"id":"dda5ae4b.3055b","type":"function","z":"94ab22aa.035ba","name":"","func":"// pt100 range -50 ~ +150\n\n\nlet decimal = msg.payload\nlet celsius = ( decimal / 65535) * 200 - 50 \n\nmsg.celsius = celsius\n\nlet fahrenheit = (celsius * 9/5) + 32\n\nmsg.fahrenheit = fahrenheit\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":450,"y":1040,"wires":[["a7beba74.31897"]]},{"id":"a7beba74.31897","type":"debug","z":"94ab22aa.035ba","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":670,"y":1040,"wires":[]},{"id":"1443a3c7.aabf1c","type":"comment","z":"94ab22aa.035ba","name":"modbus decimal","info":"","x":210,"y":1000,"wires":[]}]

```

**Code in Function :**

```javascript
// pt100 range -50 ~ +150

let decimal = msg.payload // msg.payload[0] when linked to modbus node
let celsius = ( decimal / 65535) * 200 - 50 
let fahrenheit = (celsius * 9/5) + 32

msg.celsius = celsius
msg.fahrenheit = fahrenheit

return msg;

```

**Result :**

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/5/6520b76e34654e23f23406c7ce2c3cea4840bb3b.png)

**[EDIT]**

By the way .. what modbus addresses did you read in your screenshot above ? 40001 ?  
Did you try reading 31 and 32 also ? Your device could be sending the engineering units in those directly which makes the above code unnecessary 😉

---

<div class="post-metadata">

**Author:** ![jjw](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@jjw](https://discourse.nodered.org/u/jjw)\
**Post date:** [5 February 2021 03:01 UTC](https://discourse.nodered.org/t/how-to-convert-my-modbus-data-to-fahrenheit/40398/4 "2021-02-05T03:01:13Z")

</div>

The one called rtd is a modbus read node, I just named it rtd.  
So i can actually get my temp from decimal or hexadecimal, Not having to worry About getting a floating point number?  
my sensor range in the specs is -50 - 200 celsius. Actual temp in room was around 64 fahrenheit, always changing a few degrees.  
So i attached 2 debug nodes. screenshot below.  
debug data is expanded on bottom two

![adams5.PNG](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/9/59e6a9fdbc04b93495c7f19e30a7f2807e5d08cd.png)

 ![adams6.PNG](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/c/0c7ab2e16d656106cae1284fdc3308d2e264e572.png)

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [5 February 2021 11:58 UTC](https://discourse.nodered.org/t/how-to-convert-my-modbus-data-to-fahrenheit/40398/5 "2021-02-05T11:58:13Z")

</div>

> [@jjw](#):
>
> So i can actually get my temp from decimal or hexadecimal, Not having to worry About getting a floating point number?

Ofcourse .. as i have demostrated with the above example flow.  
Wire a **Function node** to the top output of your **Modbus read node** with the code :

```auto
// pt100 range -50 ~ +150

let decimal = msg.payload[0]
let celsius = ( decimal / 65535) * 200 - 50 
let fahrenheit = (celsius * 9/5) + 32

msg.celsius = celsius
msg.fahrenheit = fahrenheit

return msg;

```

Then wire a complete msg Debug node after the function node and thats it .. you get your fahrenheit temperature in `msg.fahrenheit`

> [@jjw](#):
>
> my sensor range in the specs is -50 - 200 celsius

I dont know about that .. i made my calculation based on the settings you had in the screeshot above  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/2/a2abce378fd9d8be508ec13be3d428eb4fd80ca8.png)

IF the range is -50 ~ 200 C and the reading temp is off, then you should correct the range in the Adam Utility and adjust the calculations in the function. `let celsius = ( decimal / 65535) * 250 - 50 `

---

<div class="post-metadata">

**Author:** ![jjw](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@jjw](https://discourse.nodered.org/u/jjw)\
**Post date:** [5 February 2021 14:23 UTC](https://discourse.nodered.org/t/how-to-convert-my-modbus-data-to-fahrenheit/40398/6 "2021-02-05T14:23:57Z")

</div>

OK thank you very much. It seems like the sensor specs don't affect the reading temp.  
Cause its very accurate using -50 to 150c. If not ill adjust the calculations accordingly.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [6 April 2021 14:24 UTC](https://discourse.nodered.org/t/how-to-convert-my-modbus-data-to-fahrenheit/40398/7 "2021-04-06T14:24:04Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
