Have Arduino decimate sensor data before uploading it to the cloud?

Hello Everyone,

I have a soil moisture sensor pushing data to Thingspeak. The code currently sends a GET request to the cloud every 10 seconds.

The problem is that the sensor data is very noisy, and my code is currently just taking a snapshot every 10 seconds and using that to push to the cloud.

Is there a way that I can average the data gathered over those 10 seconds and upload that instead?

Currently I'm declaring a variable that's the reading from the sensor and that's what I'm using to upload.

Thanks in advance

Of course.
A rolling average needs a buffer of 'n' samples, so you subtract from a running total the value of the oldest sample, and add in the value of the newest, before dividing the running total by 'n'.