Introduction: Roving Inclinometer With IPhone Data Logging

I was doing repeated walks up a mountain trail and kept wondering what the actual incline was and how best to measure it. The iPhone provides a precise App that measures the incline as you tip it up on its side and it's fun to use on particularly treacherous sections of trails. Mapping programs give you slope data by dividing the height that you go up by the distance you travel but this is a summery of all the many small slope refinements that you encounter on a trail. You always tend to think that you're on a much tippier section than you actually measure. Inclinometers are an ancient instrument and currently the mechanical ones have been supplanted by electronic devices easily mated to microcontrollers. Base models are very cheap and require quite a bit of math to harvest angular data that makes any sense. In this case I have used a model that does most of the calculations on the chip and allows the small microprocessor to do some mild filtering and communication of data making the package quite small and adaptable to placement on your shoe. To measure incline the shoe provides a great measuring platform which you need to provide a length of perpendicularity to the slope that you walk on. A bicycle would provide this with the contact point of the two wheels or even greater length in a car. All measurements are dependent on finding an initializing zero point to set prior to setting out on your treck. The device is very light, rechargeable and communicates(Bluetooth) with an iPhone app to record your inclined angle and GPS position for processing either in Google earth or output as a CSV file. It may seem kind of obsessive in collecting this information but automated slope data collection might be useful for trail design where even mild deviations in slope make for easy or difficult for walking or biking.

Supplies

This is a small project that uses just one sensor, a battery and a microcontroller. The sensor I used from Adafruit does all the signal processing from the 9 DOF sensor to give the acceleration and the tilt in the direction that you're interested in. It would be difficult to substitute something cheaper. I am using the new ESP32 C3 microcontroller from SEEED Studio. It does Bluetooth with a little auxiliary antenna as well as battery charging and it's incredibly small! Very cheap too!


  1. Adafruit 9-DOF Absolute Orientation IMU Fusion Breakout- BNO055 $34
  2. Seeed Studio XIAO ESP32C3 - RISC-V tiny MCU board with Wi-Fi and Bluetooth5.0, battery charge $5
  3. Lipo Battery 300 mAh $3
  4. Generic momentary button Adafruit $1
  5. On/Off Switch waterproof Digikey $1

Step 1: Print It

The body of the Inclinometer is 3D printed in PLA. You can print it in something tougher but this thing has been through a lot of tramping: snow, mud and water and seems to do fine. The enclosure is designed to be relatively water resistant with the screw cap on the access port to the UBC hub. If you wanted you could put an O ring washer where it makes contact with the body assembly. Nothing required supports.

Step 2: Wire It

The wiring for this device is really simple so I've included the layout for the microcontroller above and I'll just list the connections. The BNO055 is a I2C connected device so it has four attachments: Power (3V), GND, SCL, SDA. The power and ground are supplied by the microcontroller and the D4 is for SDA and D5 is for SCL. The pushbutton for zeroing the unit is connected to D10 and to a ground. The Battery is connected to the two connectors on the back of the board with interruption by the on/off switch which is wired into the + line. The On/Off switch came with a built in LED but I did not wire it up to save energy.

Step 3: Build It

To build the unit place 4 M2 x 4 x 3.5 heat inserts into the supplied holes in the bottom section. The IMU unit is held in place with up to 4 M2 screws. The wires are tucked into the surrounding cutouts. The ESP32 unit is hot glued into its seat in the lower unit. The On/Off switch is superglued into its position in the lower unit. The button is superglued into its recess hole in the upper unit. The antenna has its glue backing removed and is taped to the roof of the unit. The unit is tested to make sure it is functioning well and the upper and lower units are glued together with superglue. The collar is secured to the case with superglue and the screw seal cap is tested to secure the opening.

Step 4: Program It

The programming for this is done in the Arduino IDE. The program takes periodic information from the BNO055 sensor and averages it and then periodically uploads it to the BLExAR App on your iPhone where it is graphed and collected in a CSV file for further analysis. The iPhone App also adds stamps for time and GPS location to your data.

The initial section of the program adds libraries for the sensor as well as for connecting via Bluetooth. The sample rate delay allows you to change how often the sensor is queried. In the setup function the Bluetooth service is started and the advertising for your named device can be changed...I used elevation as you can see from the list in the BleX app listing. GetZero() function sets whatever level the shoe is resting on during "boot" up to be the zero angle. This function waits for 10 seconds while setting this level. In the void loop() function a timer checks initially if it's time to send data out via bluetooth --this is currently set to every 5 seconds. It then checks to see if the zero button is being pushed. If it is the getZero() function is again called. Next the IMU is given initial values for Accel and Angle in the Z axis: this is the important axis in regard to acceleration in the up/down direction and the angle of tilt of the IMU unit. It can be thought of one of three movement states Pitch, Roll and Yaw. The z axis defines the Pitch of the IMU and the acceleration in the same axis defines the movement. When walking you have to develop an algorithm that defines the angle of the shoe at a particular moment--that moment when your step is finally taken and the shoe is resting parallel to the surface of the ground without any acceleration. (Except for gravity which is taken out of the acceleration values.) The way this algorithm works is the loop keeps checking acceleration in the z direction until it is less than 0.2 and then waits to see if it rests there for 100 ms--if it does the values of the angle (Pitch) are sent through a Kalman filter and when the acceleration starts up again this value is sent through a moving average function smooth(). The Bluetooth periodically broadcasts the smooth() result every 5 seconds to the BLExAR app for location pining and timing.

Step 5: Testing It

I 3D printed several angle structures to confirm the rated output from the device was exactly what was being measured. In all cases it came out within 1 degree. Walking up and down my 1/3 mile long driveway multiple times to collect data from the BLExAR revealed a mild variability in the data of +/- 1 degree which I think is pretty good considering the way the data was being handled and the inherent irreproducibility of angular planting of your foot and the deviations in GPS postions. The actual angles measures agreed quite well with the iPhone angle measurements. (+/- 1 degree).

Step 6: Using It

In practice the Inclinometer is very easy to use. You charge it up in an hour and zip tie it to the front of your shoe. It doesn't matter which direction the On/Off switch faces. (Either toward you or toward the shoe tip). The device is very light and you do not feel it at all while walking. Initially when turned on it will set a zero point in the first ten seconds but this is the initial setting and you can subsequently re-zero it at anytime by pushing the zero button. Download the wonderful BLExAR App for your iPhone and run the scan profile to look for the name of your device in the list of Bluetooth devices. It will pull up the next screen and you choose the Graph option to begin to see the data. The IMU device has an initial period when the sensors have not internally zeroed out and it is best if you tilt and turn the shoe multiple times in the first couple minutes so it gets its "bearings". After this initial breaking-in it's best to push the re-zero button and put the shoe on a flat surface to give you a zero baseline. The data can be seen on the graph about once every five seconds and you can either clear the graph with the buttons on the screen or tap collect data to start collection of a CSV file to be emailed to you for further processing. It is very easy to import the CSV file into Google Earth and project the data onto the 3D maps and develop video walk throughs with your elevation data superimposed. The data elements can be grouped and color coded to indicate different height values on your trip. If you are a Strava fan you can also upload your data by using the Heart Rate Bluetooth encoding to spoof the Strava app into collecting your elevation numbers instead of your beats per minute. Just look up how it was done in this Instructable: https://www.instructables.com/Accurate-VO2-Max-for-Zwift-and-Strava/ The battery will last a least 4 hours and it records declines in minus and inclines in plus. Since the algorithm depends on the shoe staying still for a bit to grab the angle it is best to have a slow steady pace for the measurements -- woking on a new program for trail running. Print it in the same color as your shoe to be more discreet, but weirdly enough only one person asked me about it...