I am working on an application where I need to detect the movement of someones head, especially when someone is nodding. To do this we've placed an Arduino on a cap with an accelerometer (MPU-6050). The accelerometer returns values between 0 and 10 from horizontal to looking a bit up and 0 and -10 for looking a bit down.
I need to recognize a pattern in values which represent a simple nod, like this. I've been told I had to use something like:
for(int x = 0; x < 100; x++){
result += abs(oldvalue) + abs(newvalue) / 2;
}
This will get the average value over 100 loops (like 0.5 second), but it's impossible to determine wheter a person is nodding or not based on the result
.
I myself thought about checking for some kind of wave form, which nodding actually is. The old value will be lower or higher than the other value for a while, but not sure how to do this, since I can not pause my code because it's checking the output from other sensors also (microphone and compass).