Using the Pedometer in MIT App Inventor

The pedometer uses the phones motion sensors (accelerometers) to identify when the phone (or tablet) is being carried by someone that is walking – and uses this to measure the number of steps you take as you walk. When calibrated to the length of your stride, the pedometer provides a way to estimate the distance you have traveled.

The pedometer is so simple to use, I put this example together while eating lunch today.

User Interface

This is a simple program!

To use this app, enter your stride length in meters. For illustration, I set the stride length to 1/2 meter or 0.5, as seen in this screen shot:

Screenshot_20161206-153814

Press the Start measuring steps button to activate the pedometer and then start walking with your phone. You will soon see the Elapsed distance value increase as you move around.

Designer View

Using the Designer, set a Horizontal layout at top, and add a Label and set its text to Set stride length:, then add a Textbox to its right.

Add another Horizontal layout and add two buttons. Set one for the Start measuring button and the other for the Stop measuring button.

The next line is optional – a label has been added which is used to display the WalkingStep event status.

Then add another Horizontal layout with two labels – one to say “Elapsed distance:” and the second to display the distance traveled.

Voila_Capture 2016-12-06_03-29-39_PM

Don’t forget to add the Pedometer component! The Pedometer is located in the Sensors section of the Palette, and when dropped on the Designer View, appears as a non-visible component below the screen area.

Components

The components are labeled as shown here:

Components

The NumbersOnly property checkbox of txtStrideLength is checked to limit the input to numeric values.

Properties

Blocks View

Setting up the Designer View is harder than writing the app!

The Pedometer is started by – surprise – calling its .Start method.

The Pedometer is stopped by calling its .Stop method.

The .Reset method resets the distance counters to zero.

Blocks1

As you walk, the Pedometer component generates two events – either SingleStep or WalkStep. The distance parameter holds the estimated distance traveled and is the same as the Pedometer.Distance property.

Blocks2

Source Download

Access the source file at the MIT App Inventory Gallery.

E-Books

In addition to hundreds of posts and examples on this blog, I have several e-books available from Google Books, Amazon and other outlets. The books cover topics that are far too large to cover in blog posts, especially for Volume 3 – Databases and Files and Volume 4 – Graphics, Animation and Charts. Volumes 1 and 2 are intended for those just starting out with App Inventor.

Visit the books page for details on each book, sample chapters, where to buy – all are very inexpensive.

Also, use the Search box in the left column of this web site to look for other examples to help you with your App Inventor programming!

AppInventor-Vol1-RevisedCover

AppInventor-Vol2-CoverRevised

AI2Volume3Cover

CoverOnly2

Advertisements

2 thoughts on “Using the Pedometer in MIT App Inventor

  1. Hi dear Edward,

    I replicated this tutorial to learn about pedometer.

    A very interesting development would be to record in Firebase the steps and the distances walked, by hour, triggered by a clock, then draw some charts with the daily distances / steps during a month, an year, etc… also a daily alert to appear to urge the phone owner to walk more to fulfill his / her daily plan…

    Thus the average hourly speed is measured.

    Researches showed that if speeds over 5 km / hour for people over 70 yo, death couldn’t reach them.
    The condition for a healthy aging is to walk over 6000 strides / day with an average speed of over 3 km / hour.

    Take a look here
    https://batrani.afacereamea.ro/alimentatie/cat-de-repede-merge-omul-cu-coasa-1187/

    Regards,

    Mihai

    Like

    • Mihai

      That is a very good idea for an App Inventor app – this can certainly be done using the pedometer and Firebase (or TinyWebDB) to store the data in a database to be used for drawing a chart of speed.

      I do a lot of running – but do not carry my phone with me while I run 🙂

      Ed

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s