Adjust values from the pressure sensor with Node?

Hello,

I use a digital pressure sensor in my irrigation system. Unfortunately, its measurement results are not linear. I have to adjust the values mathematically. I can't get any further with the "range node". Is there maybe another node that I could use.
The problem, the correction factors are not linear either. In the list you can see the comparison series of measurements.
The red values are at the input of the node. The green values should then be output at the output.

Many Thanks!
|
Drucksensor Messreihe .pdf (66.6 KB)

Hello Pinie_Pinie,

You can work with a normal function node and put in a switch case function, but this makes maybe only sense, if that are all values:

var value = msg.payload;
switch (value) {
    case (0):
       value = 0.6;
     break;
    case (0.6):
       value = 2.69;
     break;
    case (1):
       value = 2.83;
     break;
     …
    default:
       return null; // or errorhandling
     break;
}

If you do not want to work with a function node you can use a switch function to differentiate and change function to change the value, but this means more effort.

Hope this helps!

Cheers
Ranki

What interpolation accuracy do you need and what accuracy is the device specified at?
Also how often are you looking up the values?

Hello,
thank you very much first of all. A good approach.
I explained that badly. The correction should be made in one area. e.g. 0 - 2.3 = 0 or 2.4 - 2.7 = 0.6 etc.
My digital sensor is showing values that are too high.
If I have understood that correctly, an area should be defined in the function node. Is that possible and what about the syntax?
I wanted to set the accuracy in 0.4 steps. It doesn't have to be so accurate, as I only evaluate the pressure as a security. If the pressure falls below a certain value, the pump should be switched off.

Many Thanks!

pine_pinie

If it doesn't need to be extremely accurate what problem did you have with the Range node? This should do what you want

image

So an input of 2.3 or below will give you 0, an input of 6.18 or above will give 6.2, and it will be scaled linearly in between. That gives a max error of 0.17 in the output compared to the table.

Hi Pinie_Pinie,

Ranges are possible as well:

var value = msg.payload;
switch (true) {
    case ((value >= 0) && (value <= 2.3)):
       value = 0;
     break;
    case ((value > 2.3) && (value <= 2.7)):
       value = 0.6;
     break;
     …
    default:
       return null; // or errorhandling
     break;
}

Maybe this helps.

Cheers
Ranki

Hello,

I can't get this thing to work Sorry I'm missing something.
I have two Incjet.Nodes at the entrance with 1 and 2.5. The node is currently doing nothing. It comes out 1 or 2.5 at the end.
The fault is definitely mine.

Thank you for your patience

Why don't you like the range node technique, which will give you the correct value which you can then easily compare with your limit? Also it saves writing javascript, which is easy to get wrong.

I agree with Colin the range node should work fine here.

As to your code you are setting value but I see no setting of value to a msg property.

Hello,

you're right. I just tested the Rangenode with your settings and it works great. I don't understand the exact logic behind the node, but it doesn't matter. Absolutely sufficient for my purpose.
Thanks for your support!!!!

pine_pinie

It does matter, you should never use a node unless you basically understand what it does.
The settings I posted tell it to expect a message payload input between 2.3 and 6.18. It says if it is 2.3 then send 0 and if it is 6,18 then send 6.2 for values in between it does a simple linear interpolation, so for example if the input were half way between 2.3 and 6.18 then the output would be half way between 0 and 6.2

Hello,
brilliant so exactly what i was looking for.
With this node I can compensate the deviations of the digital pressure sensor. I am rounding the values through another node. Now the analog and digital pressure sensors show almost the same values.
Thanks anyway to Ranki. Here, too, I've learned something new.
Your explanation is super understandable.

Best wishes

pine_pinie

Hello Pinie_Pinie,

It‘s good to know that you are now fine with the change node. Nevertheless to complete the function node thing here:

Of course there is missing the assignment to the payload again like the following; my script was only to give you an example how it would work.

msg.payload = value;

Cheers
Ranki

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