Ultrasonic Sensor and node-red-node-pisrf

Hi !

Built a project with ultrasonic sensor to check water level. Works fine.
pisrf gives distance to water level in cm. Is there a way to change it to mm, or give the cm value a decimal?

Thanks for any advice.

Hi, you could e.g. use node-red-contrib-unit-converter

The problem, that the pisrf node gives a round centimeter value, without decimals.
1,2,3,4,5,6 cm and so on. If I convert it to mm, I will get 10, 20, 30, 40.
So the accuracy stays the same. I would like to get at least one decimal.

I took a quick look at the underlining code and it looks like it is converting the results to an integer.

If I get a chance (be warned, this might take some time since I'm helping home school two grandsons and entertaining their 4 year old sisterl and their 7 month old sister and 'my time' quickly becomes 'their time')

I'll fix up a circuit to test and then see if the code could be changed to return a decimal place.

What sensor are you using?

After doing some reasearch and reading about the different sensors I don't think the time to add a decimal point is worth it. You will never get mm accuracy. After all, the srf04 sensors has a precision of ~3mm (a 6mm spread) and the srf05 has ~2mm (a 4mm spread). Add to that the fact that the speed of sound changes with the amount of moisture in the air and you will never have an exact measurement.

1 Like

Hi !

Home-School, tell me about it! I am with you there. About accuracy, you are probably right, those sensors will never be mm accurate. Haven't thought of the air humidity - sound traveling speed issue, but that adds to the accuracy problme as well.
My goal was more, to "smoothen out" my graph, not to have a "sawblade".


Having a decimal in the result could have done that.

Thank you for your time and effort,
wishing you and your family good health
and happy schooling!

Maybe I have to make a different approach. Gather 10-20 measurements, calculate their average and post this value into the graph...hmmm...

Look at the smooth node

1 Like

That was exactly what I needed, thanks for the tip ! :+1:

Or you could use a change node and context storage to smooth the value

[{"id":"7080fa23.99b904","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$ceil($random()*3)+20","payloadType":"jsonata","x":180,"y":4580,"wires":[["b3663021.bfbe9"]]},{"id":"b3663021.bfbe9","type":"change","z":"5a245aa1.510164","name":"","rules":[{"t":"set","p":"smooth","pt":"flow","to":"$append([payload],$flowContext(\"smooth\"))[[0..19]]","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"$round($average($flowContext(\"smooth\")),1)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":4580,"wires":[["4d764ad4.3d8544"]]},{"id":"4d764ad4.3d8544","type":"debug","z":"5a245aa1.510164","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":4580,"wires":[]}]

this will hold last 20 values and average the output.

yeah - why did I bother write the smooth node...

4 Likes

Probably as a help for people who have difficulty with code. But for others who want to learn a bite of code, my example may help.

The Smooth node is pretty awesome, thanks for writing it.

I'm using it consistently on different graphs that represent chemical tank levels and battery charge levels, to both smooth out the results and reduce the update frequency (I need to display 1-3 days of results on variables that are read every 20-30 seconds), and the smooth node solves it perfectly.

@E1cid: Your code example is fine as reference, but if someone really wants to spend some time coding, I'd recommend to spend that time and energy somewhere else, since this issue is already solved impeccably by the Smooth node.

I am sure I said learning to code, which my example helps with, but cheers for your opinion.

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