Custom Fitness Tracker

by Zachary Lee September 23, 2019

Custom Fitness Tracker

Get your hands on Whiskers by backing the Whisker Kickstarter Today!!

There are many fitness trackers on the market today, but most of them do not give users the ability to easily add custom software or hardware. In this tutorial, you will learn how to do both! TinyCircuits Whiskers allow you to choose between 30 unique sensors for your projects! This is a new step forward in the Quantified Self movement!


MATERIALS

HARDWARE: 

SOFTWARE:


    Step 1: Choosing the right whiskers

    For our custom fitness tracker, we chose to use the accelerometer, pulse oximetry, and LRA (tiny vibrating motor) whiskers. Our goal was to track our steps using the accelerometer and issue notifications using the LRA. Then, using the pulse oximetry whisker we would be able to measure your heart rate and blood oxygen level.

    In addition, we created a sleep tracker functionality! By observing the nightly movement of the user and their heart rate, we were able to measure sleep quality and duration. Based on this study, we know that heart rates alone provide a significant clue as to which sleep stage you are in. 

    Of course, there are many other interesting combinations. Using the general tips provided in this article, you will be able to easily modify our code to match with any whisker you choose!

    With each Whisker Adapter TinyShield, you can connect up to 4 additional whiskers to the rest of the TinyCircuits ecosystem 


        Step 2: Assembly

        • First, gather your whiskers and whisker cables.
        • Plug your Whiskers into the Whisker TinyShield using the Whisker cables
        • Connect the larger boards using the 32-pin tan connector (TinyScreen+, MicroSD Card TinyShield, Whisker Adapter TinyShield)
        • Insert the microSD card to the MicroSD Card TinyShield
        • Plug in the battery to the TinyScreen+ 
        • Connect all of this with a micro USB cable to your computer to be ready for uploading the program

          Here, the pulse whisker measures the rhythmic flow of blood into and out of your finger. The small noose keeps a light, steady pressure to ensure the most accurate readings.


                Step 3: Uploading the code to your processor

                If this is your first time using TinyCircuits products, please refer to the TinyScreen+ Setup Tutorial to configure the Arduino IDE correctly.

                • Then, download the zip archive provided in the Software section above.
                • Open the FitnessTracker.ino file with the Arduino IDE or text editor of choice. 

                When using the Whisker Adapter TinyShield, it is important to understand port selection. You must indicate in your sketch which port each Whisker is using. Note that the port numbers are printed on the reverse side of the TinyShield. The 4 ports are numbered 0-3. 

                The good news is that our sketch is able to automatically detect which port the Accelerometer, LRA, and Pulse Oximetry Whiskers have been connected to.

                If you want the ability to record audio using the MEMS Microphone Whisker, you would need to choose a specific port number and always connect the Microphone Whisker to the same port. Then, in your sketch, you would only need two lines to read data from the Whisker. 

                  selectPort(1); // Correlates to port numbers labeled on Whisker device
                  analogRead(A1); // Same number as port number

                There are a few parameters that you can set at this stage to personalize your fitness tracker. In order to set them, navigate to the line shown in the table and modify the value to the right of the equals sign.

                 Parameter Line Number
                const int AGE = 25; // age has a significant impact on sleep composition, so inputting your age will increase the accuracy of your sleep quality calculation
                
                57
                const int STEP_TRIGGER = 250; // The LRA whisker will notify you of inactivity if you complete less than half of this number of steps each hour. Step % is based on this * 16 waking hours.
                
                52
                /* Change these values to set the current time when you upload the sketch. */
                const byte seconds = 10;
                const byte minutes = 52;
                const byte hours = 23;
                
                /* Change these values to set the current initial date */
                const byte day = 16;
                const byte month = 8;
                const byte year = 19;
                
                71-79
                const int BEDTIME_HOUR = 23; // use 24 hour time only.
                const int BEDTIME_MINUTE = 53;
                
                86-87

                 

                • Next, you will need to install two libraries from the Arduino library manager, shown below:

                The library manager can be found by going to Tools-> Manage Libraries in the Arduino IDE

                • You did it! Now let's upload the code.
                • Make sure that you have the correct port selected. The correct port number will vary, but your processor should appear to the right:

                • Then, upload the code!

                Red circle around Arduino upload button

                • After uploading the code, wait a few seconds and try tapping any of the buttons on your TinyScreen+. You should see the fitness display appear. 

                At this point, the tracker will begin monitoring the time, step count for the current day, percentage of your step goal, pulse, oxygen saturation, and remaining battery percentage. Also, once the tracker has detected that you have fallen asleep it will measure your sleep quality and determine your current sleep stage. All data is recorded to tracker.txt in a CSV format every 30 seconds by default.

                Another text file called quartiles.txt will store quartile data of your heart rate at night. It is intended to be read by the sleep quality algorithm. Since everyone's heart rate varies, it is much more accurate to base calculations off of your past heart rate than preprogrammed values. Avoid editing the format of this file or it will not be read properly by the sketch.

                Finally, a third file called sleephistory.txt is created. This file contains two columns in a CSV format, the date and the sleep quality for that date. It is updated every morning when you wake up and contains more accurate information after your sleep chronology was analyzed. Sleep chronology contrasts your sleep stage transitions against the optimal configuration of lighter sleep at the beginning and end of the night and deeper sleep in the middle.

                This is just the beginning of what you can accomplish using whisker sensors! See the optional tips below for how to incorporate any whisker into your own sketches. If you need any help, feel free to email us at info@tinycircuits.com!


                Whisker Tips (optional)*

                             Depending on the whisker, you may need to #include a library. 

                  1. #include "TinyCircuits_A1454.h" // For the sensor
                  2. Then, you will need to create a whisker object.
                    TinyCircuits_A1454 hall = TinyCircuits_A1454();
                  3. Before you can request a value, you must selectPort(x), where x is the port number (0-3) that the whisker is connected to. 
                  4. Next, open communications with that object using the name you assigned it in step 2.
                      hall.begin();
                    
                  5. Finally, read from the sensor and store the value into a variable.
                      long mag = hall.readMag();
                There! Now you have the power to add any whisker to your fitness tracker.

                  Wireless setup tips (advanced, optional)*

                  • To forewarn you, there are some shortcomings to WiFi in this application, which is why we recommend using a MicroSD card:
                    1. WiFi uses about 3x the power (30ma vs 10ma), which means that you will likely need to use a significantly larger battery. 
                    2. During any period of time in which you lose connection to WiFi, data will be lost. There are workarounds that are compatible with some IoT apps, but not others. For example, we have written a solution that starts storing data in the TinyScreen's RAM when you lose WiFi connection and then attempts to upload it to Google Sheets once a connection is regained. However, if you remain disconnected for several days, you will run out of RAM. This is recommended for advanced users only as you will need to merge the solution into this sketch.
                    3. The WiFi module is longer than the rest of the stack by about 0.5''.
                  I see you're still undeterred! Wireless setup is quite possible with this project and we have created some example code and pointers to help you on your journey.
                    • In order to interface with Google Sheets, please follow step 2c of the weather station tutorial. We have also included some example code in the software section that was working perfectly with an earlier version of this project. It is up to you to see if you can adapt it to fit your needs.
                    • If you wish to interface with Blynk, we recommend you use the SuperChart widget, as explained in The Internet of Things: Getting Started with Blynk tutorial. We also have included some example code for this route in the software section.

                    CONTACT US

                    As always, if you have any questions or feedback, feel free to email us at info@tinycircuits.com. We would love to hear any ideas for improvement or new IoT projects you were inspired to work on! 

                    Show us what you make by tagging @TinyCircuits on Instagram, Twitter, or Facebook so we can feature it!

                    Thanks for making with us!!

                     



                    Zachary Lee
                    Zachary Lee

                    Author



                    Also in Projects

                    TinyLily Halloween: Harry Potter Luna Lovegood Spectrespecs
                    TinyLily Halloween: Harry Potter Luna Lovegood Spectrespecs

                    by Laverena Wienclaw October 15, 2019

                    Light up your world with Spectrespecs to see all the wrackspurts out there making minds fuzzy! Using TinyLily RGB LEDs, you can...

                    View full article →

                    Tiny Weather Station Tutorial
                    Tiny Weather Station Tutorial

                    by Zachary Lee October 03, 2019

                    In this simple tutorial, we will show you how to build a very low power weather station that measures wind...

                    View full article →

                    RGB LED Scooter
                    RGB LED Scooter

                    by Hunter Hykes October 01, 2019

                    Jazz up your scooter with RGB LED Underglow sensitive to the scooter's speed. This project uses the Digital Hall Sensor Whisker...

                    View full article →