# Exercise Buddy: Motion aware BLE media controller

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/108/956/medium800/sensors_DSC_0624.jpg?1644711308)

Watching a riveting show while on a stationary bike is a good way to motivate yourself to exercise more regularly. There was even a scientific study done about it, which coined the term [“temptation bundling”](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4381662/ "“temptation bundling”"). But sometimes, the show might get way too interesting and you might not even notice that you've stopped cycling!

This project creates a device that can detect simple movement, and when it detects that you've stopped moving, it will pause any videos or music playing on your Apple mobile device (iPad, iPhones, etc.). It's an exercise buddy that will remind you to keep moving so you can keep watching!

## Parts
Featured
### Adafruit LED Glasses Driver - nRF52840 Sensor Board

[Adafruit LED Glasses Driver - nRF52840 Sensor Board](https://www.adafruit.com/product/5217)
This board is designed to be a thin, Bluetooth®-enabled driver board for our [Adafruit LED Glasses](https://www.adafruit.com/product/5210) RGB LED matrix. That said, it's a perfectly good stand-alone development board for the Nordic nRF52840 chipset, with a very slim design,...

In Stock
[Buy Now](https://www.adafruit.com/product/5217)
[Related Guides to the Product](https://learn.adafruit.com/products/5217/guides)
![Angled shot of thin, rectangular Bluetooth LED driver board.](https://cdn-shop.adafruit.com/640x480/5217-07.jpg)

Featured
### Lithium Ion Polymer Battery Ideal For Feathers - 3.7V 400mAh

[Lithium Ion Polymer Battery Ideal For Feathers - 3.7V 400mAh](https://www.adafruit.com/product/3898)
Lithium-ion polymer (also known as 'lipo' or 'lipoly') batteries are thin, light, and powerful. The output ranges from 4.2V when completely charged to 3.7V. This battery has a capacity of **400mAh** for a total of about 1.9 Wh. If you need a larger (or smaller!)...

In Stock
[Buy Now](https://www.adafruit.com/product/3898)
[Related Guides to the Product](https://learn.adafruit.com/products/3898/guides)
![Slim Lithium Ion Polymer Battery 3.7v 400mAh with JST 2-PH connector and short cable](https://cdn-shop.adafruit.com/640x480/3898-05.jpg)

### Part: Velcro strap
quantity: 1
Any velcro strip with a hook side and a loop side will do.
[Velcro strap](https://amzn.to/3rIstP2)

### Part: 3D printing filament
quantity: 1
Pick your favorite PLA filament! This is the one I used for this project
[3D printing filament](https://amzn.to/3oMf8Dg)

![](https://cdn-learn.adafruit.com/assets/assets/000/108/953/medium800/sensors_DSC_0591-2.jpg?1644706281)

# Exercise Buddy: Motion aware BLE media controller

## 3D printing and assembly

Download the files for this case using the buttons below. If downloading from the zip file, note that the models inside the `STL_files` folder and `3MF_files` folder are the same. There is also a `.f3z` file included in case you wanted to modify or adjust parameters on the model itself.

[Download from PrusaPrinters](https://www.prusaprinters.org/prints/133966-led-glasses-driver-ble-sensor-board-case)
[3D_files.zip](https://cdn-learn.adafruit.com/assets/assets/000/108/962/original/3D_files.zip?1644795639)
The case is made up of 3 pieces:

- **case**
- **cover** - snap fits onto the case.
- **switch extender** - fits on top of the onboard switch so it can be reachable from outside the case.

Print out all three, using 0.2mm layers and no supports. Choose your favorite color PLA filament.

The case has a "shelf" that the board sits on so that it doesn't crush the battery. It also has a pair of slots that you can thread some velcro through to secure it to an armband or a bike pedal arm.

![sensors_DSC_0618.jpg](https://cdn-learn.adafruit.com/assets/assets/000/108/951/medium640/sensors_DSC_0618.jpg?1644694491)

![sensors_DSC_0625.jpg](https://cdn-learn.adafruit.com/assets/assets/000/108/954/medium640/sensors_DSC_0625.jpg?1644710293)

Cut about 17cm length of velcro, and reduce the strip width to around 11mm. Thread it through the slots before placing the board inside as shown below.

Depending on where you will mount it, you can also opt to add a rubber or silicone piece under the case, to add a bit more stability. The clear silicone piece shown here was from a local dollar store, but a couple of the more common small circular rubber feet might just do the trick as well.

![sensors_DSC_0626.jpg](https://cdn-learn.adafruit.com/assets/assets/000/108/955/medium640/sensors_DSC_0626.jpg?1644710393)

![](https://cdn-learn.adafruit.com/assets/assets/000/108/952/medium800thumb/sensors_assembly.jpg?1644694730)

Attach the battery to the BLE sensor board, and align the USB-C port to the biggest hole on the case. Push the board down so that it is sitting on the shelf. The battery wire will stick out a little. Then, place the switch extender on top of the board switch, you should feel the switch slot into the hole.&nbsp;

Finally, align the switch extender to the switch port on the cover, and snap fit into place. Voila! You should still have access to the right-angle button and the STEMMA QT connector.

# Exercise Buddy: Motion aware BLE media controller

## CircuitPython

[CircuitPython](https://github.com/adafruit/circuitpython) is a derivative of [MicroPython](https://micropython.org) designed to simplify experimentation and education on low-cost microcontrollers. It makes it easier than ever to get prototyping by requiring no upfront desktop software downloads. Simply copy and edit files on the **CIRCUITPY** drive to iterate.

## CircuitPython Quickstart

Follow this step-by-step to quickly get CircuitPython running on your board.

[Download the latest version of CircuitPython for this board via circuitpython.org](https://circuitpython.org/board/adafruit_led_glasses_nrf52840/)
 **Click the link above to download the latest CircuitPython UF2 file.**

Save it wherever is convenient for you.

![install_circuitpython_on_most_boards_CircuitPython_downloaded.jpg](https://cdn-learn.adafruit.com/assets/assets/000/102/129/medium640/install_circuitpython_on_most_boards_CircuitPython_downloaded.jpg?1620922559)

![](https://cdn-learn.adafruit.com/assets/assets/000/105/173/medium800/adafruit_products_EyeLightsD_Reset_NeoPixel.jpg?1633470769)

Plug your board into your computer, using a known-good data-sync cable, directly, or via an adapter if needed.

Double-click the **reset** button (highlighted in red above), and you will see the **RGB status LED(s)** turn green (highlighted in green above). If you see red, try another port, or if you're using an adapter or hub, try without the hub, or different adapter or hub.

If double-clicking doesn't work the first time, try again. Sometimes it can take a few tries to get the rhythm right!

A lot of people end up using charge-only USB cables and it is very frustrating! **Make sure you have a USB cable you know is good for data sync.**

You will see a new disk drive appear called **GLASSESBOOT**.

&nbsp;

Drag the **adafruit\_circuitpython\_etc.uf2** file to **GLASSESBOOT**.

![adafruit_products_EyeLights_UF2_downloaded_GLASSESBOOT.png](https://cdn-learn.adafruit.com/assets/assets/000/105/174/medium640/adafruit_products_EyeLights_UF2_downloaded_GLASSESBOOT.png?1633471162)

![adafruit_products_EyeLights_drag_UF2.png](https://cdn-learn.adafruit.com/assets/assets/000/105/175/medium640/adafruit_products_EyeLights_drag_UF2.png?1633471170)

The **BOOT** drive will disappear and a new disk drive called **CIRCUITPY** will appear.

That's it!

![install_circuitpython_on_most_boards_CIRCUITPY.jpg](https://cdn-learn.adafruit.com/assets/assets/000/102/130/medium640/install_circuitpython_on_most_boards_CIRCUITPY.jpg?1620923145)

# Exercise Buddy: Motion aware BLE media controller

## CircuitPython libraries and code

Plug your [Adafruit LED Glasses Driver - nRF52840 Sensor Board](https://www.adafruit.com/product/5217) into the computer's USB port with a known good power+data USB cable. You should see a new flash drive appear in the computer's File Explorer or Finder (depending on your operating system) called&nbsp; **CIRCUITPY**.

Click the "Download Project Bundle" button under the Code section below.&nbsp;

Unzip the folder and copy the following items to the **CIRCUITPY** &nbsp;drive:

- **lib** &nbsp;folder
- **code.py**

The project uses the **lib** folder libraries to access the accelerometer and to be able to send play and pause commands to an Apple mobile device.&nbsp;

- adafruit\_ble
- adafruit\_ble\_apple\_media
- adafruit\_lis3dh
- neopixel

Your **CIRCUITPY** drive should contain the files listed below:

![](https://cdn-learn.adafruit.com/assets/assets/000/109/020/medium800/sensors_Untitled4.png?1644877113)

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Motion_Buddy/code.py

# Code

This board has a built-in accelerometer to detect and calculate movement. To get a rundown of the basics of how accelerometers work, check out the excellent Adafruit guide [Make It Shake, Rattle, and Roll: Accelerometer Use](https://learn.adafruit.com/make-it-shake-rattle-and-roll "Make It Shake, Rattle, and Roll: Accelerometer Use").

The idea behind the code is simple: remember the last x, y and z position, and check to see if there has been enough movement in each axis. If there has&nbsp;_not_ been enough movement since the last saved position, send a pause command to the Apple mobile device (and keep sending the pause command so that the video stays paused even if you press "play" on the device itself). Devious, but necessary.

Also the onboard NeoPixel is used as a status indicator, so that you can get a clue about what the device is up to, even when it's not connected to a computer.&nbsp;

Pair your Apple device to your project and take it for a spin! If you are not moving, the audio should be paused.

Literally, attach it to your stationary bike pedal and get ready to be motivated to keep pace. You might also consider attaching it to your body if you're doing some other form of physical exercise, but you may have to fiddle around with the `WIGGLE_ROOM` value depending on what kind of movement is involved.

Good luck and have a good workout!

![](https://cdn-learn.adafruit.com/assets/assets/000/108/963/medium800thumb/sensors_bike-header-short.jpg?1644798731)


## Guide Products

### Adafruit LED Glasses Driver - nRF52840 Sensor Board

[Adafruit LED Glasses Driver - nRF52840 Sensor Board](https://www.adafruit.com/product/5217)
This board is designed to be a thin, Bluetooth®-enabled driver board for our [Adafruit LED Glasses](https://www.adafruit.com/product/5210) RGB LED matrix. That said, it's a perfectly good stand-alone development board for the Nordic nRF52840 chipset, with a very slim design,...

In Stock
[Buy Now](https://www.adafruit.com/product/5217)
[Related Guides to the Product](https://learn.adafruit.com/products/5217/guides)
### Lithium Ion Polymer Battery Ideal For Feathers - 3.7V 400mAh

[Lithium Ion Polymer Battery Ideal For Feathers - 3.7V 400mAh](https://www.adafruit.com/product/3898)
Lithium-ion polymer (also known as 'lipo' or 'lipoly') batteries are thin, light, and powerful. The output ranges from 4.2V when completely charged to 3.7V. This battery has a capacity of **400mAh** for a total of about 1.9 Wh. If you need a larger (or smaller!)...

In Stock
[Buy Now](https://www.adafruit.com/product/3898)
[Related Guides to the Product](https://learn.adafruit.com/products/3898/guides)

## Related Guides

- [Adafruit EyeLights LED Glasses and Driver](https://learn.adafruit.com/adafruit-eyelights-led-glasses-and-driver.md)
- [Sailor Moon Star Locket](https://learn.adafruit.com/sailor-moon-star-locket.md)
- [3D Printed Frame for Adafruit IS31FL3741 LED Glasses](https://learn.adafruit.com/3d-printed-frame-for-led-glasses-is31fl3741.md)
- [Wireless LED Juggling Balls with ESP-NOW](https://learn.adafruit.com/wireless-juggling-balls-esp-now.md)
- [PyBadge Conference Badge With Unicode Fonts](https://learn.adafruit.com/pybadge-conference-badge-multi-language-unicode-fonts.md)
- [Watchmen's Sister Night NeoPixel Goggles](https://learn.adafruit.com/watchmen-sister-night-circuitpython-neopixel-goggles.md)
- [Archimedes' Boat](https://learn.adafruit.com/archimedes-boat.md)
- [Personal and Portable ESP32-S2 Web Server](https://learn.adafruit.com/wordle-personal-esp32-s2-web-server.md)
- [Rezz-Inspired NeoPixel Glasses](https://learn.adafruit.com/rezz-inspired-neopixel-glasses.md)
- [Clue Shot Timer](https://learn.adafruit.com/clue-shot-timer.md)
- [NeoPixel Badge Lanyard with Bluetooth LE](https://learn.adafruit.com/bluetooth-neopixel-badge-lanyard.md)
- [Trash-Built Robotic Fish](https://learn.adafruit.com/trash-robo-fish.md)
- [Drama Piñata](https://learn.adafruit.com/customizable-reusable-pinata.md)
- [Disconnected CO2 Data Logger](https://learn.adafruit.com/disconnected-co2-data-logger.md)
- [MakeCode Arcade Pixel Animation](https://learn.adafruit.com/makecode-arcade-pixel-animation.md)
- [Pulse Oximeter Wireless Data Logger](https://learn.adafruit.com/pulse-oximeter-wireless-data-logger.md)
