Need help with averaging analog readings

I have an analog sensor to measure moisture. To prevent triggers on random spike readings, I’d like to take and then average readings over a small period of time before deciding whether to turn on or remain dormant, and do so every minute or two, but I can’t figure out a way to keep this data for this cycle and discard it afterwards. Could someone help me, perhaps?


Thank you a lot, I’ll test it tomorrow.

unfortunately, the program did not find anything.
I pressed “add library” and passed “gweimer/utils/running-avg”, but nothing was found.

At this topic (Need help on averaging numbers for a project) man created a patch, but I was confused with adding “Port”, “N”, “pusce” and green cirle in the buttom. Where he fount them and the true names of thise nodes. I think it is very common qissue to find an average number. Please, help me.

You need to add the “gweimer/utils” library, then use the running-avg node from it.

Do you want to keep a running average, or do you just want to average some numbers? If you just want the average of a few numbers, it is just the sum of those numbers (add node) divided by the quantity of those numbers (divide node).

thanks for reply. I did that and add your library.
The primary aim is to find an average value from distance sensor and do it, for example every second. My sensor is not too accurate. I measure the distance and it shows me 20cm… 18…19…22…20…21… I know that it is approximately 20. However, I do not know how to take 20 measurements and divide on 20 to get more accurate value, because it non stop process.
I did a 5 timers (clock) in 100ms each. After I summ all and divide on 5 and got a result. But with this timers I run out of memory))) That’s why I’m looking for a bettes solution.

I have s restriction like new user (no mre than 3 replys…). So I edit this message/

I did like this and it works… but I need more timers and measurements. It’ll be cool to have 20 per 1 sec.

Yes I need to keep running average and renew it infinity time.

I have to add this image here, because another restriction did not let me add 2 img per message.

Your node. I did not get how to use it)))

I hope you will see upper message what I edited

Running-avg is probably what you want functionally. Not sure it will save you memory, though… Obviously, the more measurements you are averaging, the more memory you will need. More measurements will also take longer & tend to hide the fact that the distance is changing, so you may want fewer than 20 measurements.

1 Like