# Standard Deviation and Moving Average

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.

Example code:

M.A._and_S.D.(pdf)- “storeValue(variable);” is how to enter data into the array, then call M.A. and S.D.

Not much of a circuit required! Arduino's regulator also powers Ping))). Servo has it's own 5v regulator... needs capacitors

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!

His door unlocker.

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.

Electrical Engineer who loves to bike!

### 6 Responses to Standard Deviation and Moving Average

1. i like your ping door locker!:D

2. aashishasanand says:

Well! It is pretty good actually. It can be upgraded as per requirements. Can you please give the schematics and components used in this circuit?
Nice work!!

3. Hello there! Do you know if they make any plugins to safeguard against
hackers? I’m kinda paranoid about losing everything
I’ve worked hard on. Any tips?

• Moser says:

Don’t put your micro controller or anything outside. Think of if there’s any way it could be taken over from what’s accessible outside.

Check your code and think about how the system would react if it got rebooted or powered off.

Other than that, just write good code. If you only have 3 digits in your password then there’s only 999 combinations (still more than a normal hacker would want to try…)

4. Cameron says: