Go Down

### Topic: Detecting specific motions using accelerometer (Read 3733 times)previous topic - next topic

#### aboyne

##### Jul 23, 2010, 08:27 pmLast Edit: Jul 23, 2010, 08:27 pm by aboyne Reason: 1
Hey all,

I am going to soon begin trying to recreate one of these: http://www.thewandcompany.com/ using an arduino. This is my first project with arduino, so I will be starting slow by first just creating a setup that can learn and reproduce IR signals. I feel like I can handle this part, but the accelerometer has been making me a little more nervous.

I want to have at least 5 basic motions, flip up (volume up), flip down (volume down), right flick (channel up), left flick (channel down), and flick up & down (power). Has anyone worked with detecting these motions? I do not have my arduino or components yet, but I am just thinking ahead of time.

Thanks.

#### aboyne

#1
##### Jul 26, 2010, 07:22 pm
I don't know if I posted this in the wrong place, please let me know if I did. I have been thinking about this problem, and have a bit of an idea of what I want to do.

First step would be to detect the direction of a voluntary motion. To do this I was thinking of the following (in sudo code).
Code: [Select]
`threshold = # (how much the force needs to change before it is considered voluntary)vals = readSensorinit_x = vals[xforce]init_y = vals[yforce]init_z = valz[zforce]vals = readSensorx = vals[xforce]y = vals[yforce]z = valz[zforce]diff_x = x-init_xdiff_y = y-init_ydiff_z = z-init_zif(diff_x>threshold): #Moved rightif(dir_x<threshold*-1): #Moved  leftif(dir_y>threshold): dir = #Moved upif(dir_y<threshold*-1): #Moved downif(dir_z>threshold): #Moved forwardif(dir_z<threshold*-1): #Moved back`

That is my basic idea for determining that there was a voluntary motion in a certain direction. From there, I would give an amount of time to wait for the next motion (milliseconds probably). Record the sequence of motions, and look to see if that sequence matched a pre-defined sequence. If it does, then fire a specific IR code.

I have never worked with accelerometers before, so I am sure I am missing something here. I realized the fact that the accelerometer sensor will detect gravity, but this should account for that. I might code this up for my phone soon to test it out.

I am interested in hearing opinions if anyone has them.

Thanks.

#### Andrew

#2
##### Jul 27, 2010, 12:16 pm
I've never done it myself (though it sounds a fun project) but there is some pseudo-code here http://www.codeshogun.com/blog/2009/04/17/how-to-detect-shake-motion-in-android-part-i/ and actual code here http://www.clingmarks.com/?p=25 that might help you.

Andrew

#### aboyne

#3
##### Jul 27, 2010, 07:22 pm
I tried something fairly similar to that code, but gravity is kind of messing me up. I have some rotation when I am doing the motions, and that means that gravity starts to act on different axis in the middle of a motion. Back to the drawing board.

Go Up