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!
MATERIALSHARDWARE:
- TinyScreen+
- MicroSD TinyShield
- 150 mAh LiPo Battery -or- 500 mAh LiPo Battery (13 hr vs 45 hr approximate battery life)
- Wireling Adapter TinyShield
- LRA Motor Wireling
- Pulse Oximetry Wireling
- Microphone Wireling
- Accelerometer Wireling
- Wireling Cables (1 for each Wireling you plan to use)
- MicroUSB Cable
- WiFi TinyShield (optional, details at the end of the article)
SOFTWARE:
- Arduino IDE
- Fitness Tracker Code
- Google Sheets Uploader (optional, advanced)
- Blynk Fitness SuperChart Sketch (optional, advanced)
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 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 Wireling you choose!
- First, gather your Wirelings and Wireling cables.
- Plug your Wirelings into the Wireling TinyShield using the Wireling cables
- 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
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.
The good news is that our sketch is able to automatically detect which port the Accelerometer, LRA, and Pulse Oximetry Wirelings have been connected to.
If you want the ability to record audio using the MEMS Microphone Wireling, you would need to choose a specific port number and always connect the Microphone Wireling to the same port. Then, in your sketch, you would only need two lines to read data from the Wireling.
selectPort(1); // Correlates to port numbers labeled on Wireling 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.
Line Number57
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
52
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.
71-79
/* 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;
86-87
const int BEDTIME_HOUR = 23; // use 24 hour time only.
const int BEDTIME_MINUTE = 53;
- Next, you will need to install two libraries from the Arduino library manager, shown below:
- 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!
- 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.
#include "TinyCircuits_A1454.h" // For the sensor
Then, you will need to create a Wireling object.
TinyCircuits_A1454 hall = TinyCircuits_A1454();
Next, open communications with that object using the name you assigned it in step 2.
hall.begin();Finally, read from the sensor and store the value into a variable. long mag = hall.readMag();
- Before you can request a value, you must selectPort(x), where x is the port number (0-3) that the Wireling is connected to.
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:
- 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.
- WiFi uses about 3x the power (30ma vs 10ma), which means that you will likely need to use a significantly larger battery.
- 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.
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!
Comments
Please log in or sign up to comment.