How can I calculate an average of a MPU6050 measurement?

I'm am making a vibration testing code with a MPU6050 but I want to calculate the average of the vibrations and I don't now how to do it, I want it to be good when the average is within a set value and bad when its not whitin the average

Describe how would you average the following

123456.54321
234567.87654
755533.11111
533249.98765

I would like to just add those number to each other and the divide it by the number of numbers to get a average so 123456.54321 + 234567.87654 + 755533.11111 + 533249.98765 / 4 to get a average and next I want if the average that came from the calculation is for example 20 +/- 5 to be good so a green light would light up and if it is bad a red light to light up but I am just a beginner at coding so idk how to do such a thing in a code.

Well how would you go about storing the summed value of 10 readings?

int summedvalueof10readings;
summedvalueof10reading +=1;
summedvalueof10reading +=1;
summedvalueof10reading +=1;
summedvalueof10reading +=1;
summedvalueof10reading +=1;
summedvalueof10reading +=1;
summedvalueof10reading +=1;
summedvalueof10reading +=1;
summedvalueof10reading +=1;
summedvalueof10reading +=1;

like that you think?

then you could divide those 10 values by the number of stored samples?

int bullyfrogdrinkswine= summedvalueof10reading/10;

right?

And before you write that you don't know how to code those things. Let me ask, what happened when you tried?

That's not beginner code. So, I know you know how to code.

1 Like

Post the code, using code tags, and we can suggest how to average some values.

For posting suggestions, see the "How to get the best out of this forum" post.

Are you saying that you want to calculate the mean and some measure of deviation from that mean?

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