Standard Deviation and Moving Average
October 1, 2011 5 Comments
Recently my neighbor paid me to build a key less entry system for his dorm room. I decided to go the economical route and use a button/potentiometer that sits outside the door and an Arduino on the inside that controls a servo connected to the lock. For my room, I thought it would be interesting to use a Ping))) ultrasonic distance sensor instead of the potentiometer and lose the button.
The Ping))) sensor kept taking readings while my hand was moving. In order to fix this I decided use a Moving Average filter, then calculate the Standard Deviation of the values currently included in the M.A. filter. When my hand is still, the Standard Deviation will become very small.
M.A._and_S.D.(pdf)- “storeValue(variable);” is how to enter data into the array, then call M.A. and S.D.
pingDoorLocker(pdf) – As you can see, this program blew up a little…
I tried to make the M.A. and S.D. code very easy to follow. Some things could have been combined in the S.D. and Variance method, but to the beginner what I wrote above is probably easier to understand since it follows the equations. As for the pingDoorLocker – I threw that code together very quickly.
Follow up notes: That was probably the worst way to do this project… I thought of a few ways how to write the program that would chop the code WAY down, but this is an example about using M.A. and S.D.! Pretty bad use of a M.A. filter if you ask me!
Since I did put a few hours into building my neighbor’s door opener, here’s an image of it! He didn’t want numbers on the potentiometer dial, so I made the LED flash the number that is currently being entered.
Code for his door opener (pdf) – leave a comment if you want schematics/code on rapid share since pdf loses tabs.