Introduction: Arduino Pedometer

About: Lazy Old Geek

Problem: So my nutritionist (doesn’t everyone have a nutritionist) suggested I should increase my exercise which primarily consists of walking my dog. She even gave me a chart of activities and calories burned. Here’s an example.
http://www.nutristrategy.com/caloriesburned.htm
Well, being a LAZY OLD GEEK, I decided to monitor my walking electronically.

Solution: It was a “long and winding road” but here’s the finished product. It’s not very elegant but it does the job. The Arduino attaches to the pedometer which counts my steps and records steps plus temperature and humidity and time to the SD card.

Parts List:
USB Freeduino kit
(Arduino-clone) $22.50
HSM-20G Temp-RH $9 (Closeout)
AdaFruit Datalogger $19.50
Adafruit 6 AA
Battery holder $5.00
Pedometer $1 (Dollar Store)
SD Card $6

Prices US dollars December 2010

The total is about $63. Yes, it’s costly but the Arduino stuff can be used for other projects.

Tools:
Soldering tools
DMM Recommended

Step 1: Selecting Parts

I recently built an Arduino with LCD to measure temperature and humidity while taking our walks.
https://www.instructables.com/id/Arduino-Nokia-LCD-Sensors/

Problem: I decided to extend this concept. The problem with using the LCD is that it’s not easy to use or see, especially when wrestling with my big dog, Marcus.

Solution: Recently I received an Adafruit datalogger kit for my birthday.
http://www.adafruit.com/index.php?main_page=product_info&cPath=17_21&products_id=243
See picture. This Adafruit kit is well designed and uses quality parts. As with all Adafruit products, the assembly instructions are excellent. For a LAZY OLD GEEK I really appreciate the quality of the PCB which makes soldering and unsoldering easy. Another nice feature is the real time clock with battery. Highly recommended.

I used an Adafruit 6 AA Battery holder because it will work with rechargeable batteries. It is a lot bigger and heavier than a 9Volt holder, however.
http://www.adafruit.com/index.php?main_page=product_info&cPath=38&products_id=248

For logging data, you need an SD card. Adafruit recommends 2gB or less and not SDHC.

The Arduino-clone, Freeduino and the temperature-humidity sensor are the same ones used in the previous Instructable.

Problem: How to monitor walking. My first idea was to use the GPS, I have.
https://www.instructables.com/id/GPS-for-Lazy-Old-Geeks/
Well this GPS has a USB output. I tried various methods/schemes to interface this with my Arduino but had no success. Also my experience with my GPS is that it is not that accurate for short distances. It would probably work if our walks were long straight distances but walking with Marcus is very convoluted. He follows his nose and we encounter a lot of rabbit and field mice smells. And he is big, so I mostly follow.

Solution: I decided a pedometer was a better solution. It’s pretty easy to interface and keeps track of steps. My pedometer was a gift but our dollar store sells pedometers that will probably work as well as the one I used.

I connected the sensors with telephone wire.

Step 2: Pedometer Wiring

The pedometer I used is an Accusplit x 120. It is available from Amazon.com. See picture.

Most pedometers use the same basic design. A little weighted arm is held up by a tiny spring. When the user walks, the hip movement and gravity lets the arm drop down closing an electrical contact.
See first green pedometer picture.
Warning: When opening up the pedometer, be very careful as there usually is a tiny spring that can come off and get lost. That’s what happened to this one. On this one, the spring went from the bottom metal plate to the metal arm. The spring was part of the electrical circuit that connected the bottom plate to the arm.

When the user steps, gravity forces the metal arm down so that it touches the upper metal plate and electrically shorts the two metal plates together.

Procedure:
Take the cover off the pedometer. It may use screws or mine opened with a twist of a coin.
Carefully turn on the pedometer.
Take your DMM, set it to VDC.
Place the black-negative lead on the bottom metal plate, place the red-postive lead on the upper metal plate.
Measure the voltage, it will probably read about 1.2 VDC
If it measures -1.2VDC then switch the two leads.

If you want and are dexterous, while holding the probes on the pedometer, move the arm down so that it touching the top plate. The voltage should read about 0 VDC.

Black pedometer:
For the pedometer I used, the design is a little different. See picture. The arm is plastic and has a little magnet in it. You should be able to see the little curved spring holding the arm up. On the right is a little glass tube with two leads in it. This is called a reed switch. When the magnet comes close to it, the two leads inside are shorted together so the results are the same as the green pedometer.
For the electronically inclined, the little black cylinder under and to the right of the reed switch is a capacitor. This (I assume) is a hardware debounce component.

The procedure is the same but you measure the voltage across the reed switch. In this case when I had the black lead on the bottom, it read -1.2Vdc. See picture, so I had to switch the leads with the black on top.

Procedure continued:
Cut a length of two wire cable, I made mine about three feet long. I used an old phone cord. This one had two wires, most have four. Solder the ground wire, usually black or in my case, green to where the negative lead of the DMM was. In my case, it was the top of the reed switch. Connect the other wire (red) to where the red DMM lead was, in this case the bottom of the reed switch.

Step 3: Datalogger Wiring

Procedure:
Assemble the datalogger per instructions.
Load the software from Adafruit website.
Set up the real time clock per instructions.
Test the SD card (sdfat) software per instructions

Wiring procedure:
The first picture shows the 5VDC and ground wiring on the datalogger. The green wire is from the pedometer ‘ground’. The small black wire is the ground wire from other telephone wire going to the HSM-20G. The little red wire is the 5VDC connecting to the HSM-20G temperature-humidity sensor.

The second picture shows the red (5VDC) and black (ground) wires going to the prototype area shown in the first picture. The yellow and green wires are the two sensor outputs for the HSM-20G, Humidity to Analog 1 and temperature to 2 of the datalogger and Arduino. The red wire from the pedometer is going to Analog 3.

Warning: If you leave the pedometer connected to the Arduino unpowered, the Arduino will try to draw power from the pedometer and drain the battery faster. When finished, disconnect the datalogger from the Arduino. I didn’t have the instructions for my pedometer but it apparently does not have an on-off switch.
A more permanent solution would be to put a connector on the telephone cord so I could unplug it or put in a switch but I’m LAZY.

Step 4: Pedometer Theory and Software Design

Software is in MTSTempRHStep.zip file

Theory of Operation:

The voltage from the pedometer going to the Arduino Analog 3 is about 1.2VDC. When the user steps, the voltage drops to close to zero. The Arduino software will detect this and count this as a step.

Software Design:

The software has to read the data from the temperature and humidity probe and the pedometer, then log it to the SD card. The software will determine how often to log data to the SD card. This software is set for 10 second samples. This can be changed by changing the value of LOG_INTERVAL (10,000 means 10,000 milliseconds which is 10 seconds).

Reading temperature and humidity can be done once for every log entry.

Problem: The pedometer has to be monitored pretty continuously as a step can occur at any time. (This is called an asynchronous event).

Solution: I had to rewrite the sample program so that the pedometer is sampled constantly and data is collected until the LOG_INTERVAL (10 seconds) is reached, then the temperature and humidity sensors are sampled and all of the data plus the time is written to the SD card.

Here is the significant portions of the software loop.


StartTime=millis();
}
void loop(void)
{

// MTS Pedometer reads about 1.2V open = 245 counts
if (analogRead(PedoPin) < 50) // About .245V
{
  StepCnt +=1;
  TotalCnt +=1;
  delay(300); //Delay .3 sec
}

if ((millis()-StartTime)>long(LOG_INTERVAL))
{

  Code that writes to log file

  StepCnt =0;
  StartTime = millis();
}

Theory: Before the loop is started, StartTime reads in millis() which is the number of milliseconds since the Arduino was powered up or reset.
The pedometer is read, if it’s close to zero, then StepCnt and TotalCnt are incremented.
This is repeated until millis() is 10 seconds or greater than StartTime.

When the 10 seconds has passed, the real time, temperature, humidity, StepCnt and TotalCnt are written to the log file.
The StepCnt is set to zero (so that only counts between samples are recorded)
StartTime is set to millis() so the next 10 second interval can be measured.
The whole process is repeated.

The file created on the SD card is labeled loggerxx.csv where xx is a number starting with 00, e.g., the first will be logger00.csv.
.csv means the file is written as comma separated values and can be read directly into Excel software. It can also be read by Google docs (free) and Open Office (free).

Step 5: Calibration

Problem: Circuits like a pedometer have a problem called debounce. Whenever you have a mechanical switch like the pedometer mechanical arm or reed switch, you might think the switch is open or closed but that is not the case. When the switch contacts get close to each other, there is a varying resistance between the two contacts.
This is indicated in the next picture. For many readers, this won’t mean anything. It is an oscilloscope trace of a switch turning off. But to simplify, it is apparent that it is not a smooth transition from on to off. Since the Arduino chip is fast, it could actually read several ‘steps’ when there should only be one.

Solution: Now this problem can be ‘debounced’ in hardware or software. Since I don’t have any control over the hardware of any pedometer you may be using, I am using a software ‘debounce.’

Here is the pedometer code:

// MTS Pedometer reads about 1.2V open = 245 counts
if (analogRead(PedoPin) < 50) // About .245V
{
  StepCnt +=1;
  TotalCnt +=1;
  delay(300); //Delay .3 sec
}

There are two values that may need to be adjusted. The first is the 50. Remember when I said you could measure the closed value for the pedometer? Did you do it? Well, this is the voltage that will be sent out when the user is stepping. The number 50 is in counts where each count is about 0.0049VDC so 50 counts is about 0.245VDC.
This code value needs to be set a little bit above the measured value. The reason is that the actual closed voltage will vary and it will also be different because of the resistance of the wire. I didn’t actually measure the closed value but 50 should work in most cases. The ‘<’ symbol just means that it has to be less than 50. You don’t care how much less.

The other value is the delay(300). This is the software debounce. Not what this means is that if the Arduino sees a step, it will do nothing for .3 second (300 milliseconds) before it will look for another step. If my calculations are right, you would have to be walking/running at over 4.5 MPH for this not to work. I am OLD so I don’t think that will be a problem. If you are younger, you can probably put in a shorter delay value.

Calibration procedure:
Load the Arduino software
Turn on the pedometer
Reset the Arduino
Go for your walk
Record the step count from your pedometer
Wait 10 seconds, disconnect the power to the Arduino
Take the SD card out and stick it in your computer.
Open the last loggerxx.csv file.
Go to the bottom and get that last total count number.
It should be close to the count on your pedometer.
Mine was within 2 counts over a couple of samples over a couple hours each.
If not, tweak the values above and repeat.

I searched the internet on accuracy of pedometers. Most weren’t that accurate, often about 10% so that’s about all the accuracy you can get anyway.

Step 6: Using Arduino Pedometer

Many internet articles on pedometers suggest a good goal for most people is 10,000 steps a day.
You may also be interested in mileage or feet. You can ‘calibrate’ your pedometer by counting how many steps you take for a known distance. I’ve tried this about three times and got three different answers from about 1.8 to 2.1 feet per step.

What my nutritionist is interested in is miles per hour.

Here’s how I use my Arduino pedometer.

The two pictures show the assembly ready for action.

 I restart the Arduino and the pedometer when I start our walk and stop it when I get back.
I open the last loggerxx.csv file with Excel. All I really need is the first record and the last.

date                time       tempF     RH% steps totalsteps
12/23/2010    7:6:54       81        38         4          4
12/23/2010    9:13:18    58        82          0         8552

To calculate the time for the walk, just take the last time and subtract the first time. Excel has a way to do this using something like this
=TIMEVALUE(B753)-TIMEVALUE(B2) {{B753 and B2 are cell numbers}}
This gives a value in days of 0.087778.
Multiply by 24 to get hours = 2.106667

I use a step value of 2 feet per step so multiply totalsteps 8552 * 2 = 17104 feet
Divide by 5280 to get miles = 3.239394
Divide miles by hours to get MPH 3.239394/2.10667 = 1.5 MPH

So according to the chart, with my weight, that means I burned about 280 calories on this walk.

Yes, I know. It’s a lot of algebra but it’s not too hard with Excel.
I’ve includes a sample file Dec23.csv and Dec23.xls with the calculations at the bottom

By the way, this two hour logging only took up 30K on my 64mByte SD card.

Conclusion: My Arduino pedometer seems to work pretty good. Logging to an SD card has the disadvantage of not having on going data but I can get steps by looking at the pedometer.

The log file has other ‘interesting’ information. On a cold December early morning in the high desert, it took about 15 minutes for the temperature to drop from inside house temp of 76F to outside 31F. Humidity stayed pretty constant until it started to warm up. Temperature went for 31F to about 66F which seems a high to me. I should investigate but then I am LAZY.

On some really cold days, I noticed the Arduino pedometer count was higher than the pedometer count but it was still within about 10% so I'm ignoring the differences. I also noticed that the temperature never went below 0 F but am ignoring this also. I shouldn't be walking my dog when it's this cold anyway.