MIDI Exercise Bike

About a year ago I bought an excercise bike in my quest to get a little more physically active. Suffice to say, it didn’t work. The poor, lonely bike sat beside my desk for the past year gathering dust.

Something about the bike caught my attention during the Christmas break however (yes, I was getting pretty bored). The bike’s computer is connected to the rest of the bike via a jack socket. So what’s the obvious thing to do? That’s right… turn it into a MIDI controller.

After a bit of prodding with a multi-meter I figured out the sensor that controls the onboard ‘computer’ was a simple switch, probably a reed switch, that completes a circuit once per revolution.

With that in mind, I hacked together this circuit on a breadboard:

I actually used an arduino nano, which made the breadboarding a lot easier as I could just shove the whole arduino into the board.

I tested the circuit with a simple bit of code that just reads the switch input (pin 2) and outputs the value to the serial monitor, using the output of that I figured out that the switch is held on for around a quarter of the bike’s revolution.

The switch is connected to pin 2 so we can use an interrupt routine to read the switch. The thing is, what do you record? The switch is either on or off… and we need some sort of signal between 0 and 127 to send as MIDI. The answer was to record the number of milliseconds since the last time the switch was triggered. Here’s the interrupt routine:

void revolution(){
  unsigned long currMillis = millis();
  //Crude debounce
  if(prevMillis != currMillis){
    float diff = currMillis - prevMillis;
    target = (1.0 / diff) * 50000;
    prevMillis = currMillis;
  }
}

The first line of the function stores the current milliseconds since startup. Then we make sure the interrupt routine hasn’t been called before in this millisecond as a really crap debounce. If the current time isn’t the same as the previous time, we calculate the number of milliseconds since the last time revolution() was called. This is usually in the range of ~300 – 800 milliseconds.

Since we want the MIDI signal to go up when we’re cycling faster we need to do a bit of maths on it (yes, maths…). To convert the period, the time between cycles, to a frequency we divide one by the period. To get the MIDI signal into the right range we multiply by 5000. I got 5000 by trial and error, YMMV.

We’ve now got a signal that goes from around 0 to around 127, but it only gets updated around twice a second when you’re cycling at a normal speed (my normal speed’s probably a lot slower than most normal, heathly people… I don’t get out much, hence having a MIDI excercise bike). I smoothed out the signal by using a low-pass filter function I found in the Arduino playground wiki area. This is all done in the loop() function, which is called repeatedly as long as the Arduino is running:

void loop() {
  unsigned long diff = millis() - prevMillis;
 
  currentValue = smooth(target, 0.9, currentValue);
  if((char)currentValue != previousValue){
    midiCC(5, currentValue);
  }
 
  // Timeout
  if(diff > 2000){
    target = 0;
  }
 
  previousValue = currentValue;
  delay(50);
}

In the loop we’re storing the milliseconds since the pedals last went round (for later use), then running the smooth function. This takes three arguments, the first is the value you want to tend towards (the target), the second is the speed of the smoothing (lower is slower, higher is faster), the third is the last value the smoothing function returned. If this value has changed we send it as a midi CC message.

The rest of the loop function sets the target value to zero if the pedals haven’t rotated for more than two seconds. This is so you can’t just stop pedaling and leave the MIDI signal the same, you have to keep pushing!

Here’s a quick demo of it hooked up to Ableton Live, with the CC message mapped to the tempo.

The full code for the Arduino sketch is up on my github account.

30 Comments

  1. Posted August 30, 2010 at 4:38 pm | Permalink

    crikey!
    fine work sir

  2. Posted September 15, 2011 at 2:24 am | Permalink

    I’m still learning from you, while I’m trying to achieve my goals. I absolutely love reading all that is posted on your website.Keep the posts coming. I loved it!

  3. Posted December 18, 2011 at 11:56 pm | Permalink

    I watched your musical bike and am quite impressed. I am pretty much ignorant on the electronics and I am relying on your expertise either for a referral or assistance.

    I have a product that a person can skate on wearing hockey skates or running shoes. (www.stridedeck.ca)
    I wish to add electronics. The only practical solution, since the foot begins and ends at different locations and speed, is to use a contact microphone to capture the vibration of the stride.

    I would like to take this vibration from the piezo (contact microphone) and convert it into musical notes and the skater can hear the music while skating. This way, the user can actually make notes (music) with the exercise of the leg. The amount of force will give the individual notes A, B, C, etc. and the length of the stride will give the note’s length (an eight, quarter, half, whole note).

    I look forward to your response.

  4. Posted September 3, 2014 at 8:28 am | Permalink

    My partner and I stumbled over here different page and thought I might check things out.
    I like what I see so now i am following you. Look forward to looking into your web page for a second time.

  5. Posted December 3, 2014 at 11:32 pm | Permalink

    whoah this blog is great i really like studying your articles.
    Keep up the good work! You recognize, a lot of persons are looking around for this
    information, you could help them greatly.

  6. Posted July 20, 2015 at 12:29 am | Permalink

    Click about the “Movies You’ve Rated” tab to discover a detailed list of the rated movies as well as
    their star rating.

  7. Posted December 15, 2015 at 7:05 am | Permalink

    We have Collected maximum details from the Net. and we are Wishing on Trvnews,
    Wish You Satisfied new year 2016 and Have a pleased year ahead.

  8. Posted December 29, 2015 at 9:50 am | Permalink

    hi!,I rezlly likee your writing so so much!
    percentage we communicaqte extra about your post onn AOL?
    I require ann expert iin this house to unravel my problem.
    Maybe that’s you! Having a look forward to peer you.

  9. Posted January 27, 2016 at 4:41 am | Permalink

    Types of app would an individual build, the net
    app or a app that is certainly native

  10. Posted January 27, 2016 at 7:13 pm | Permalink

    Truly when someone doesn’t understand then its up to other viewers that they will help, so here it occurs.

  11. Posted January 28, 2016 at 3:05 am | Permalink

    Ltd.

  12. Posted January 28, 2016 at 2:09 pm | Permalink

    Wonderful beat ! I wish to aplrentice at the same tim as you amend your weeb site, how could i subscribe for a blog web
    site? The account aided me a appropriate deal. I have been tiny
    bit familiar of this your broadcast offered bright transparent concept

  13. Posted March 13, 2016 at 3:37 pm | Permalink

    Please click Configure link, to construct your own Turbo Boost.

    We provide Market Mode, Game Mode, and Work Mode. Work Mode will increase your pc for better work
    experience. Game Mode can increase your computer considerably greatly
    for gaming.

  14. Posted March 14, 2016 at 6:51 am | Permalink

    The dryness might also causes loss of your skin, so the best plumping skin treatment must contain moisturizing materials that are natural.

  15. Posted March 14, 2016 at 7:44 am | Permalink

    What a data of un-ambiguity and preserveness of precious familiarity about unexpected feelings.

    Champaign Office Cleaning & Business Janitorial Services
    1303 Williamsburg Dr.
    Champaign, IL 61821
    (217) 666-4750

  16. Posted March 15, 2016 at 1:58 am | Permalink

    I think the admin of this website is in fact working hard in favor of his web site, for the reason that here every
    material is quality based data.

  17. Posted March 18, 2016 at 11:33 pm | Permalink

    Toys, Toys, Toys!

  18. Posted March 22, 2016 at 3:03 am | Permalink

    You’ve gotten plenty of options tto select from, so your plumber selection may take some time.

  19. Posted March 22, 2016 at 3:02 pm | Permalink

    Even planning for the journey can be a blast-pouring over guidebook, choosing your ‘have
    to see’ locations.

  20. Posted March 22, 2016 at 3:31 pm | Permalink

    Excellent blog right here! Additionally your website so much up
    fast! What web host are you using? Can I am getting your associate link in your host?
    I desire my web site loaded up as quickly as yours lol

  21. Posted March 25, 2016 at 6:08 am | Permalink

    Thanks for one’s marvelous posting! I seriously enjoyed reading it, you’re a great author.
    I will remember to bookmark your blog and definitely will come back someday.

    I want to encourage yourself to continue your great posts, have a nice morning!

  22. Posted March 26, 2016 at 7:06 am | Permalink

    What you are doing is correcting the reason why cancer first appeared and that is essential.

  23. Posted March 26, 2016 at 8:47 am | Permalink

    This watxh comes with GPS, Mp3 participant, and coronary heart rate monitr with
    a chest strap.

  24. Posted March 28, 2016 at 9:31 am | Permalink

    Excellent items from you, man. I’ve bear in minbd your tuff prior to and
    you’re simply extremely wonderful. I really like what you’ve received here,
    certainlyy liike what you are sayjng and the way in which during whih you say
    it. You are making iit enjoyable and you still take care of to
    stay it wise. I can not wait to read much more from you.

    This is actually a great site.

  25. Posted March 29, 2016 at 6:04 am | Permalink

    That thirty days our national football league BreastCancerAwarenessMonth, which is we very often assert one funeral service along breast cancers.

    Jordan sword got as a result of engraving the actual Jordan 6 hoops
    outside of karate rendition, and also become a member of exclusive
    her pussy, his or her support associated with the NFL patrons further did start to use it hanging
    around.

  26. Posted April 9, 2016 at 12:33 pm | Permalink

    My partner and I stumbled over here by a different page and thought I may as
    well check things out. I like what I see so i am just following you.

    Look forward to checking out your web page again.

  27. Posted April 12, 2016 at 12:11 am | Permalink

    Unquestionably consider that that you said. Your favorite reason appeared to be on the internet
    the easiest factor to take note of. I say to you,
    I certainly get annoyed while other people consider concerns that they just
    do not recognise about. You controlled to hit the nail upon the highest as neatly as outlined out the whole thing without having side effect ,
    people can take a signal. Will likely be back to get more.
    Thanks

  28. Posted April 21, 2016 at 3:19 am | Permalink

    It will help the photographer to focus the camera on right object at right time.

    Using your vision to set the tone, create a palette of
    colors, materials and design elements that will be
    present on your web site as well as in your portfolio and
    direct mail. Anticipating things before they occur, so that they might be captured on film can be one
    of the most prized qualities of a good photographer.

  29. Posted July 25, 2016 at 6:53 pm | Permalink

    I am regular visitor, how are you everybody? This article posted at this web
    page is really fastidious.

  30. Posted August 17, 2016 at 1:16 pm | Permalink

    Awsome site! I am loving it!! Will come back again. I am taking your feeds also.

One Trackback

  1. By MIDI exercise bike sets the pace | SquareCows on January 14, 2010 at 4:44 am

    […] Nice – sounds like a great way to enhance a workout! More project info + source code available @ 55th Floatilla. […]

Post a Comment

Your email is never shared. Required fields are marked *

*
*