Custom Fitness Tracker

Custom Fitness Tracker

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 Wirelings 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 wirelings

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

    In addition, we created 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 the code to match with any wireling you choose!

    With each Wireling Adapter TinyShield, you can connect up to 4 additional wirelings to the rest of the TinyCircuits ecosystem for a limit of 8 Wireling Adapter TinyShields for 32 wirelings


        Step 2: Assembly

        • First, gather your wirelings and wireling cables.
        • Plug your Wirelings into the Wireling TinyShield using the Wireling cables
          • port 0 - Microphone Wireling (not used in this tutorial)
          • port 1 - Pulse Oximetry Sensor Wireling
          • port 2 - LRA Motor Wireling 
          • port 3 - Accelerometer Sensor Wireling
        • Connect the larger boards using the 32-pin tan connector (TinyScreen+, MicroSD Card TinyShield, Wireling 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 wireling measures the beats per minute (BPM) and saturated oxygen level. The small knot 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 Wireling Adapter TinyShield, it is important to understand port selection. You must indicate in your sketch which port each Wireling is using. Note that the port numbers are printed on the reverse side of the TinyShield. The 4 ports are numbered 0-3. 

                You can use a Wireling in any of the 4 ports you choose, but you would need to modify the program to match what ports you choose. The above assembly instructions note which Wirelings are initially programmed for which port in the program included in this tutorial.

                 

                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 wireling 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 some Arduino Libraries including the Wireling, RTCZero, SdFat library from the Arduino Library Manager:
                sdfat arduino library manager screenshot

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

                To install the MAX30101 library, download the zip file under the above Software section and check out our Library Installation Page

                • 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 wireling sensors! See the optional tips below for how to incorporate any wireling into your own sketches. If you need any help, feel free to email us at info@tinycircuits.com!


                Wireling Tips (optional)*

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

                  1. #include "TinyCircuits_A1454.h" // For the sensor
                  2. Then, you will need to create a wireling 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 wireling 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 wireling 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!!