Introduction: IDC2018IOT Leg Running Tracker

We came out with this idea as part of the "Internet Of Things" course at IDC Herzliya.

The project's goal is to enhance physical activities that involve running or walking using NodeMCU, a few sensors and a could server. The result of this project is a very useful IOT device that can be turned in the future to a real production product that will be used everywhere! Please let us know what you think :)

Before you start, make sure you have:

* NodeMCU device.

* 1 Piezoelectric sensor.

* MPU6050 sensor.

* One big matrix.

* Elastic rope.

* Firebase account.


* Multiple Piezoelectric sensor

* multiplexer

Step 1: Setting Up and Calibrating the MPU6050

The first sensor we want to use is MPU6050.

MPU6050 can be used as both Gyro and Accelerometer. We would like to track the movement of the foot, so we are only going to use the accelerometer feature. Also note that we only need to use one of the 3 provided axes since the foot generally moves only in one coordinate.

The sensor is designed to use analog pins, but using the following repository, the sensor can be used with 2 digital pins using I2C protocol.

Note that we use filter for smoothing the data. The smoothing function is f(n) = (value * 0.2) + (f(n-1) * 0.8)

Upload the following sketch with the following connections:

* VCC --> 3v3

* GND --> ground

* SCL --> D1

* SDA --> D2

* Int --> 3v3

The sketch is attached.

  • Connect the sensor to the device.
  • Load the attached sketch.
  • Connect the device and the sensor to one foot using an elastic rope.
  • Look at the "serial plotter" to see the data graph.
  • Watch the video attached to this step.

Step 2: Setting Up the Piezo


  • Connect the piezo with 1M resistor (see attached picture).
  • Upload the attached sketch.
  • Connect the device to one foot using the elastic rope.
  • Open "serial plotter".
  • Watch the video that is attached to this step.

Step 3: Integrating the Sensors to the Arduino

We saw how to calibrate the sensors, now we are going to integrate both of the sensors to the NodeMCU!

  • Connect both sensors to the device, use the same pins as in steps 1+2.
  • Load the attached sketch.
  • Connect the device with the 2 sensors to one foot.
  • Open "serial plotter".
  • Watch the attached video.

Step 4: Sending Data to the Cloud!

In this step we will connect our device to the cloud and send data to see some amazing charts!

We will use the MQTT protocol and send data to a free server called "Adafruit".

NOTE: Adafruit does not support sending data a few times every second, it works in slower paces, therefore we will send an averaging of our data points, and not the data points themselves. We will transform the data from our 2 sensors to averaged data using the following transformations:

* Step detection time will be transformed to steps per minute. Each step duration can be found by (millis() - step_timestamp), and the averaging can be done using a filter, as we saw before: val = val * 0.7 + new_val * 0.3.

* Step power will be transformed to average step power. We will use the same methodology of using "max" for each step, but we will use a filter to do an averaging using the filter average = average * 0.6 + new_val * 0.4.


  • Enter the website of Adafruit at the address and make sure you have an account.
  • Create a new dashboard, you can name it "My steps detector".
  • Inside the dashboard, press on the + button and select "line chart", and create a feed named "steps_per_min".
  • Inside the dashboard, press on the + button and select "line chart", and create a feed named "average_step_power".
  • You should now see 2 empty charts for each of the fields.
  • Use the attached sketch and set the following configuration:

USERNAME = your Adafruit username.

KEY = your Adafruit key



mpuStepThreshold = Threshold from step 2

Then you can connect the device to one foot and the sketch will send steps data to the server!

Step 5: Using 2 Devices at the Same Time

On this step, we will simulate 2 people that walk with the device on the same time!

We will use 2 different devices - with the same data points as explained in step 4.

So this is really easy, there are 3 simple tasks :

1) create extra feeds for the data from the 2nd device, we suggest giving a post-fix of "_2"

2) change the blocks in the dashboard to present data from both feeds.

3) change the name of the feeds in the sketch of the second device.

4) See the results!


Adafruit resist data that comes too fast, it might be needed to adjust the frequency in which data is sent to the server. do that by finding the following in the sketch:

// Send every 5 seconds not not exceed Adafruit's limit for free users.
// If you use premium or your own server feel free to change. // Every time send an alternating data point. if(millis() - lastTimeDataSent > 5000){


Step 6: Enhancements, Notes and Future Plans!

The main challenge:

The main challenge in the project was testing the NodeMCU in a physical activity. The usb cable disconnects often, and when trying to move fast there can be a problems of detaching pins. Many times we were debugging a piece of code that actually worked, and the problem was in the physical realm.

We overcame this challenge by carrying the laptop close to the runner, and writing each piece of code at a time.

Another challenge was to make the different components interact smoothly:

  • The piezo with the acceleromter: Soved that as described in step 3, by a creative idea we had.
  • The sensors with the server: as described in step 4, we transformed the values into other values that can be sent to a server in a slower pace.

The limitations of the system:

  • Needs calibration before used.
  • Need to be turned into a more rigid product, that does not break easily in a physical activity.
  • The piezoelectric sensor is not very accurate.
  • Needs some wifi connection. (Easily solved using cell phone hotspot)

Future plans!

Now, that we have a fully working leg monitoring device there are further enhancements that can be done!

Multiple pizeos!

  • Connect piezos to different areas in the foot.
  • Use multiplexer since NodeMCU only supports one analog pin.
  • Can show a heat map of the foot to describe impact areas.
  • Can use this data to create alerts on wrong posture and body balance.

Many devices!

  • We showed you how to connect 2 devices on the same time, but you can connect 22 piezos to 22 soccer players!
  • The data can be exposed during the game to show some interesting metrics about the players!

Advanced sensors

We used piezo and accelerometer, but you can add other devices that will enrich the output and give more data:

  • Accurate lazers to detect footsteps.
  • Measure distance between the foot and the ground.
  • Measure distance between different players (In case of multiple devices)