 # measure analog values between a zero interval

Hello there!

I am not really experienced in C-programming so I would need some help in how to programm something like this:

I am reading analog values from 8 FSR sensors (two force measuring plates) and calculating a floating average of the already to digital converted values. So far so good.

Further on I would like to calculate the average of the values which lay between an interval of zeros.
In the end all this is about to compare actual bodyweight of a person to how much of the body weight is actually brought up on the plates and not relieved over the handrails of the treadmill.
The interval of zeros (or very low values) shows the time between the two steps and i want to leave this out of the calculation. After the zeros there is the next step and i want the average, so the force, or weight, which occures in one step cycle (values before and after zeros). All this then should continue till the measurement is ended manually.

I hope i described it in a way someone can understand. I think the coding doesnt take that much effort but i just cant wrap my head around it.

Thank you!

Marvin

I hope i described it in a way someone can understand. I think the coding doesnt take that much effort but i just cant wrap my head around it.

I'm amazed at the number of people that can not figure out how to do something, and yet conclude that it should be easy.

It really does, though, seem like it should be easy. To calculate an average, you add up a bunch of values, and divide by the number of values.

Now, the problem is that some (many?) of the values are zero (or less than some threshold). So, while adding nothing, or almost nothing, does little to affect the total, the average is reduced because the number of values remains the same.

So, what to do?

Lets say that you get 10 readings, like
0, 4, 10, 100, 150, 150, 100, 10, 4, 0

You add them up, and get 528. Divide by 10, and you get 52.8.

Well, suppose that you were to decide whether to add the value to the total only if it was greater than the threshold. Lets say the threshold is 5. The two 0s and the 2 4s are less than the threshold, so we don't add them to the total. Now, the total is 10 + 100 + 150 + 150 + 10, which is 520. Divide by 10, and the average is 52.0. Hmmm, that's going the wrong way.

Well, suppose you only count the values that are above the threshold. There were 6 of them. The total is still 520, but the average is 520/6, which is 83.3. That's more like it.

Implementing that in code really is easy.

Hello Paul.

I understand what you suggest and I also understand the mathematical background.

But thats not my problem. I do not know how to implement that in my code. I do not know how to tell the arduino to leave the zeros out of my calculations but use them as an reference to know which values have to be added up to an average and which dont. I dont want an average over an exact number of value.
I want it always to be the values before the zeros and after the zeros till the next bunch of zeros which are considered.

Thank you

OK. I'll be REAL specific. POST YOUR CODE!

Thats all I have for now. Didnt come up with anything close to what i want.

int total = 0;
int average = 0;

int sensormean = (A0+A1+A2+A3+A4+A5+A6+A7)/8;

void setup() {

Serial.begin(9600);

}
}

void loop() {

}

Serial.println(average);
delay(1);
}

``````int sensormean = (A0+A1+A2+A3+A4+A5+A6+A7)/8;
``````

Calculating the average of a bunch of pin numbers doesn't make sense.

``````  readings[readIndex] = analogRead(sensormean);
``````

That doesn't make sense, either.

Lets start with something REALLY simple. How many sensors do you have connected to the Arduino? Where?

I have connected 8 fsr sensors on the analog inputs of an arduino nano beginning with A0 to A7

Marv_Goodman:
I have connected 8 fsr sensors on the analog inputs of an arduino nano beginning with A0 to A7

Do you want to average the readings from all 8 sensors together, or do you want to average the reading from each sensor? Or do you want to average the readings from only some sensors?

I want to average the readings from all 8 sensors together, so no matter where on the plates you step you get the same values.

Hi, Marv.
These sensors are simple to set up and great for sensing pressure, but they aren’t incredibly accurate. Use them to sense if it’s being squeezed, but you may not want to use it as a scale.".

Moreover, with no pressure, they are a high value resistance, not low or zero. You will need to calibrate each sensor to see what it's no pressure resistance actually is. Then with the same weight placed on each sensor, you will not get identical values, as indicated in the above statement.

At best, you can tell when someone is pressing on a sensor or not.

Paul

Hi Paul_KD7HB

The sensors signal is already amplified in a way they can be very accurate. I know that because parallel to my measurement there is already an measurment going on. I am just trying to add something new.

But could you maybe tell me what PaulS meant when telling me that this doesnt make sense. I want to average all of my 8 sensors constantly while measuring so i get the same value no matter where on the plates i step.

``````int sensormean = (A0+A1+A2+A3+A4+A5+A6+A7)/8;
``````

I already managed to divide the steps btw. but because of this averaging issue i dont know if the values I am getting are "good" or not.

try this, it compiles but you need to tweak some numbers I guess

``````//
//    FILE: average.ino
//  AUTHOR: rob tillaart
//    DATE: 2018-03-16
// VERSION: 0.1.0
// PURPOSE: demo
// HISTORY: 0.1.0 initial version
//

const int THRESHOLD = 50;

int   ports = { A0, A1, A2, A3, A4, A5, A6, A7 };

float total     = 0;
float average   = 0;

void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);

for (int i = 0; i < numReadings; i++)
{
}
}

void loop()
{

// take the average of 8 analog samples that are above THRESHOLD
float sum = 0;
int  count = 0;
for (int i = 0; i< 8; i++)
{
if (t > THRESHOLD)
{
count++;
sum += t;
}
}

// put them in the array
if (count > 0)
{
}
else
{
Thank you robtillaart. It works fine after tweaking some numbers 