How to send negative temperature value efficiently

I am measuring temperature and some of my values are negative, The easiest way is to use strings but I would like to know how I can send the data in the most optimal way, any help would be appreciated, I am using an arduino uno and Lmic library

2ā€™s complement???

1 Like

Strings are not appreciated in LoRaWAN :slight_smile: and the sign at the end is just a bit.
Integer or decimal? range? you can always add a number and then subtract it.

How about send the temp in Kelvin. That way there is never a negative. Convert it to F or C if you need to display it later on a less constrained system.

2 Likes

It also depends on range and precision needed/available. With kelvin degrees you are almost obliged to send 2 bytes, but if temperature comes from a DHT11, one byte is sufficient (adding 128 ).

1 Like

Adding 128 to it assumes a fixed range. ( in theory -127 to 127 C ). But as you alude, not enough information to give a ā€˜realā€™ answer.

Yes, more info is needed, but you always have a fixed range, which is limited at first by the sensor, then by your needs and where you put it.
DHT11 measures 0-50Ā°C with 2C accuracy, so even +128 is not needed (actually I supposed to have edited the post, but likely the operation did not succeed). And also 8 bit is overkill.
DHT22 measures -40C - +80C with 0.5C accuracy, so 8 bit are needed, and you may store every value with a step of 0.5C, with 0C equal to 80. Although thinking at Shannon-Nyquist I could not bother much about decimals, and just store the integer part + 40.

The second limit is where you use it and how much difference you need to recognize. In a common room you may safely assume that temperature will not fall under zero and not grow overā€¦ 40-50.

1 Like

Iā€™d assume that a 0.5 accuracy means that a reading of, e.g., 20.3 indicates that the actual value is somewhere between 19.8 and 20.8. So, Iā€™d not send 20.3 as 20.5, as then one cannot distinguish that from 20.4, 20.5, 20.6 and 20.7.

Indeed. And then also reserve a specific value for ā€œout of rangeā€, if only to detect faulty sensors.

1 Like

Again, it depends from the need (and precision, but in case of DHT22 is indeed 0.1C). If you need to detect a temperature change I agree with you, but if you are interested in the real temperature, it does not do much difference due to the possible error.

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