0

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).

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Jef
  • 791
  • 1
  • 18
  • 36
  • 1
    Have you tried taking the derivative? – Ignacio Vazquez-Abrams Nov 07 '13 at 21:02
  • I did not, not exactly sure how, but I will try. Thank you for your input. – Jef Nov 07 '13 at 21:14
  • 1
    When looking for a periodic signal, always consider an FFT. A wavelet transform is another option. – MSalters Nov 08 '13 at 00:14
  • I'm not sure what the code you share is trying to do -- because it's taking the absolute value, result will increase without limit. – bobwki Nov 08 '13 at 16:24
  • 1
    First, I confess I have no experience with accelerometers. And I'm not sure what the code you share is trying to do -- because it's taking the absolute value, result will increase without limit. You might try taking a running average -- create an array to store values (maybe 1 second's worth), do an initial read and fill the array with that value. Then for each read replace one value, incrementing as you go and rolling over at the end. Take the average each time. When you see your value drop significantly below the average (you'll have to test how much), you have a nod (I think). – bobwki Nov 08 '13 at 16:31
  • Thank you all for the great ideas, I will definitely look into them when I get back to my project. I will keep you updated! – Jef Nov 09 '13 at 22:21

1 Answers1

-1

You Spouse To Have A Threshold When The Sensor is ideling/Static State Or litle Naturle Head Movment Mmm you Can Try This Code I Think It Will Work For You:

void loop()
{
    int CurrentState = analogRead(AccPin);
     if(CurrentState > ThresHold || CurrentState < ThresHold)
     {boolean IsNoding = CheckForNoding();} 
     if(IsNoding)
     {
         //Do Whatever You Want
     }
     else
     delay(TimeInterVal); 
}

boolean CheckForNoding()
{ 
  Count = 0;
  boolean State = false;
  while(Count<MinToConsiderNode) // Your Case 100?!
  {
      int CurrentState = analogRead(AccPin);
      if(CurrentState > ThresHold || CurrentState < ThresHold)
      {
          int Count ++;
          delay(TimeInterval) // What you Think Should Be The Time Period Between each => Head Going Up or Down
          State = true;
      }
      else 
        {
            State = false;
            break;
        }
  }

    return State;
}
Dani Bresler
  • 109
  • 4