Exercise Machine controlled Video

In this video I show you how to rig up a cross trainer or other exercise machine to play or pause video depending on whether is it used or not. It uses Puck.js's Bluetooth LE HID capability.

The method of connecting to the trainer here could be used for all kinds of things - for instance you could easily log your usage of the trainer throughout a whole training session and then download it to your phone or PC afterwards.


I used an oscilloscope to look at the signal on the wire from the trainer. However if you don't have one, just use a volt meter and move the exercise machine very slowly.

The important thing is to get the polarity of the wiring correct. All you need to do is make sure that when the meter is across the wire, it reads a positive (not negative) voltage.

If the voltage across the wire is higher than 3v, ask on the forums - you may need some extra work to safely connect to Puck.js without damaging it.


The code used in the video is:

var controls = require("ble_hid_controls");
NRF.setServices(undefined, { hid : controls.report });

var rotations = 0;
var lastRotations = 0;
var wasPlaying = false;

var PLAYSPEED = 5;

setWatch(function(e) {
}, D1, { edge:"falling",repeat:true});

function setPlaying(play) {
  if (play!=wasPlaying) {
    wasPlaying = play;
    // flash a LED
    if (play) {
      // green = go
    } else {
      // red = stop
    // Call playpause to toggle beteen play and stop
    // Catch any exceptions thrown here in case HID
    // wasn't enabled
    try { controls.playpause(); } catch (e) { }

NRF.on('connect', function(addr) { 
  setInterval(function() {
    if (rotations >= PLAYSPEED && 
        lastRotations >= PLAYSPEED) {
      // if both the last time periods have been fast enough
      // start playing
    } else if (rotations < PLAYSPEED &&
               lastRotations < PLAYSPEED) {
      // else if both were too slow, stop playing
    lastRotations = rotations;
    rotations = 0;
  }, 2000);

NRF.on('disconnect', function() { 
  // Remove any intervals

This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.