Introduction: Simple, Easy and Cheap DIY Pedometer With Arduino
I borrowed an accelerometer 4 months back from a friend but I realized it's never been put into it's best use.So why not make something good out of it. I already have https://play.google.com/store/apps/details?id=com.noom.walk installed in my phone , but the problem with these apps is they consume too much battery and doesn't work when put into sleep (Almost all mobiles have these issues). So I decided to make my own pedometer.
Please click on vote (in upper right corner) . An other version with MATLAB is coming soon.
Step 1: Who Moved Moved My Accelerometer ?
Well as the title says it is an inexpensive project and doesn't require much Hardware. All you need is this :
Hardware
- Arduino ( UNO or it's clone or an pre-boot loaded ATMega328 )
I had a freeduino so I used that
- ADXL 335 Triple Axis Accelerometer.
Software Packages:
- Arduino IDE (Any version should work)
Step 2: How Accelerometers Work ?
Before we get started onto making our own Pedometer , it is fascinating to know how such a technology works.
ADXL 335 (or let's say any other version) is based on MEMS technology , an acronym for Microelectromechanical Systems. The 3 triple axis sensor consist of a micro-machined structure of a silicon wafer. The structure is suspended just like a spring (made up of polysilicon , ugh Organic Chemistry :/ ) . With subject to acceleration , the spring deflects and deflection of spring causes change in capacitance which is converted to an output voltage proportional to acceleration.The video explains how MEMS based accelerometer are used in Mobile phones. This video also got featured on Hack-a-day , couple of years back.
So for a layman , it can be assumed that accelerometer measures acceleration or the change in velocity
Accelerometer types and why use ADXL 335 ?
The commonly used low power board-compatible (plug-n-play) accelerometers are :
- ADXL 335
- ADXL326
- ADXL 377
ADXL 335 can measure up to 3G in X, Y and Z axis , ergo , it is sensitive enough to use it as a pedometer.
Google up the data sheets for each three of these for more details.
Step 3: Getting Started With Accerelometer
Let's us start by simply reading the accelerometer data and then by calibrating it so as to feel what does it look like .
ADXL 335 is a simple plug and play device . Plug the accelerometer on the analog pins of Arduino such that the pins are connected in following fashion :
analog 0: accelerometer self test
analog 1: z-axis
analog 2: y-axis
analog 3: x-axis
analog 4: ground
analog 5: vcc
Note : Some of the Accelerometers works only with 3.3V , so it better t avoid 5V and use 3.3V instead.Please refer to data sheet of your Accelerometer.
After inserting the Accelerometer , upload this simple code to read Accelerometer data.
Step 4: Pedometer-Walkthrough
So that was enough to get started with Accelerometer. Let me give you a quick walkthrough (a psuedo-code and the suggested algorithm) for the pedometer.
On powering up the switch , calibrate() Continuously read the data analogRead(Xaxis); <p>analogRead(Yaxis);</p><p>analogRead(Zaxis);</p> from accelerometer for three X, Y and Z axis. //Calculate the total acceleration vector with respect to starting point i.e. where the calibration was called Acceleration vector = squareroot(x^2+y^2+z^2)// w.r.t to to xbar ybar zbar Analyze the data for setting up a threshold (we'll have further discussion on how to set a threshold and count steps in next coming steps) If acc vector crosses threshold count++ display steps
Step 5: Analyzing the Data and Detecting a Threshold (Almost There!)
Select the right COM port and board in Arduino's IDE , upload the following code.
Notice that this is infact the actual code but with the output suppressed, so it doesn't display steps.This is the penultimate step for our Pedometer.
Open the serial monitor and have a look on what accelerometer data looks like. Move some steps to see how the data changes.
Brace yourself :
Obviously the data will vary from person to person and should be adjusted accordingly. That's why complex systems such as those in Myo band uses an IMU which offers 9 degrees of freedom.
Detecting the threshold crossing :
if (totave[i]>threshhold && flag==0)
{ steps=steps+1; flag=1; } // if it crosses threshold increment step by one and raise the flag
else if (totave[i] > threshhold && flag==1) // if flag is raised and threshold is crossed , do nothing
{ //do nothing }
if (
totave[i] < threshhold && flag==1) // if flag is raised and threshold is not crossed , put that flag down.{flag=0;}
Note for Grammar Nazis : I know I have misspelt at times in code such as using threshhold instead of threshold and many others, but please bare with me.
Step 6: Step Up
Time for counting , here we go upload the attached code
You Might wanna put that accelerometer in your pocket or just wrap it around your leg near ankle (this again may require some calibration )