Introduction: Riding Through Walls: Google Street View Stationary Bike Interface

About: The Riding Through Walls: Google Street View Stationary Bike Interface allows you to cycle through Google Street View from the comfort of your living room. Using some simple electronics, an Arduino, a stationa…

The Riding Through Walls: Google Street View Stationary Bike Interface allows you to cycle through Google Street-View from the comfort of your living room. Using some simple electronics, an Arduino, a stationary bike, a computer, and projector or TV you can explore the world without leaving home. See http://ridingthroughwalls.megansmith.ca/ for more information.

Step 1: Materials

Parts List

Materials for Assembly

    • Wire cutters

    • Needle nose pliers

    • Soldering Iron (optional)

    • Flux Core Solder (optional)

    • Electrical Tape (optional)

    • Heat gun or lighter

Equipment Needed For Use Stationary bike

    • Computer with USB and monitor output

    • Projector or Monitor

Step 2: Prepare Your Space

This project is meant to allow you to explore the world by bike from the comfort of your living room. For best results use with a projector that covers the entire wall with the projected image. TVs and monitors will work as well, but the larger the image, the better the immersion. Place your stationary bike at a reasonable distance from the image, as close to centered as possible.

With an idea of where you want to place all your components you can now run the wires from the buttons and reed switch to the Arduino to get an estimate of how long your wires actually need to be.

Step 3: Circuit

The Riding Through Walls Google Street View Bike uses a relatively simple circuit consisting of two pushbuttons and one reed switch connected from the Arduino's inputs to ground. The internal pullup resistors are used avoiding the need to build the circuit with external resistors. The circuit shown has been tested with the Arduino Leonardo and should work for any Arduino.

  • Magnetic reed switch attached from pin 2 to ground
  • Right pushbutton attached from pin 3 to ground
  • Left pushbutton attached from pin 4 to ground
  • Internal pullup resistors used for all three pins

NOTE: As the circuit relies on the Arduino's internal resistors please take extra caution as setting the connections to OUTPUT HIGH could short 5V to ground and permanently damage the Arduino.

Step 4: Build Buttons

Run two lengths of wire from the Arduino to each of the handlebar pushbuttons. Cut the wire to length and crimp on the quick-disconnects to the end which will attach to the button. If you prefer the wire can be soldered to the buttons instead.

Step 5: Install Buttons for Turning

Depending on the size and shape of your handlebars there are a number of ways to attach your push buttons. You'll want them easily accessible and close to your hands.

Temporary or Flexible Solution: Using Tape or Velcro strips

  • Use Velcro strips or a strong but flexible tape such as electrical tape, hockey tape, or gaffer tape.
  • Hold the button in place perpendicular to the handlebar.
  • Wrap the velcro/tape around both the button and handlebar, making an X-shaped pattern to prevent the button from rotating.

Permanent Solution: Using standard handlebar

  • Drill a hole the same diameter as your button and thread the wires so that your button can be inserted into the handlebar at a comfortable distance for your thumbs to operate them while holding your handlebars.

Step 6: Attach Arduino to the Bike

To attach the Arduino Leonardo to the bike use the plastic mount provided with the Arudino.

  1. Run a Velcro strip through the vertical grating on the mount.
  2. Loop the Velcro around the bike where you would like to attach it.
  3. Insert the Arduino into the mount by pressing it into place.

If you do not have the plastic mount that comes with the Arduino there are other ways to make a case and locations to store the system safely.

Handlebar/saddle bag

You can simply place the Arduino in a handlebar or saddle bag to keep it secure and protected. The bag is designed to be easily attached to most bikes

Basket

If your bike has a basket you can place the Arduino in the basket and cover with a protective surface such as a plastic sheet or wooden board.

Reusable Plastic Container

You can also use a reusable plastic container. A small Ziploc or Tupperware container should also do the trick. Simply cut or drill holes in the base of the container to run zip ties through, and one hole to run the wires through. Zip tie the container to the bike and place the lid on when the Arduino is installed.

3D Printed Case

There are a number of 3D printed cases that you can be download and printed from sites such as Thingiverse including this one for Arduino Uno and Leonardo. You may want to modify the case before printing to suit your mounting solution, for example making holes to run zip ties through the case. Simply 3D print the case, assemble it, and zip tie or tape it to the bike.

Step 7: Install Reed Switch and Magnet

First, the reed switch and corresponding magnet need to be installed on the wheel and frame. Depending on the type of drive system your stationary bike uses you will need to take a slightly different approach, but in each case the magnet goes on the moving part and the reed switch goes on the frame. They should be mounted in a location where they won't interfere with any other parts such as brakes or drivetrain components. If the wires attached to the reed switch aren't long enough you'll need to solder more wire to extend them.

Alternative 1 - Bike Wheel With Tire

If you're using a regular bike on a bike trainer, or one of many older stationary bikes that use a standard bike wheel and tire then these steps are for you.

  1. Try placing the magnet directly on the wheel. If the wheel is steel then the magnet will hold itself in place.
  2. If the magnet does not stay in place it can be attached to the wheel using double sided mounting tape, hot glue or super glue.
  3. Alternately a second magnet can be placed inside the rim to hold the magnet to the wheel. To accomplish this follow these steps:
    • Remove the wheel from the bike as this will make the following steps easier.
    • Deflate the tire by removing the dust cap and pressing the valve in with a screwdriver, pen or other small tool.
    • Pull the tire back from the rim where you'd like to install the magnet.
    • Place one magnet inside the rim, offset towards one side of the wheel. Place the other magnet on the outside of the rim in the same location. The magnets should hold each other in place.
    • Re-inflate the tire using a bike pump or air compressor, be sure not to exceed the recommended pressure printed on the side of the tire.
    • Re-install the wheel on the bike.
  4. Install the Reed Switch on the frame within 12 mm (0.5") of the magnet while keeping it clear of any moving parts. Make sure that the larger side of the reed switch is facing the magnet. Use zip-ties, velcro strips, tape, or hot glue to secure it in place.

Alternative 2 - Exercise Bike with Flywheel

Most modern exercise bikes use a compact flywheel of some kind in place of the wheel. In this case you will have to use double sided mounting tape or glue as there is no way to secure the magnet with a second magnet.

  1. Find a mounting location for the magnet which won't interfere with any brake, frame or drive train components.
  2. Attach the magnet to the flywheel using double-sided tape, hot glue, or super glue.
  3. Install the Reed Switch on the frame within 12 mm (0.5") of the magnet while keeping it clear of any moving parts. Use zip-ties, velcro strips, tape, or hot glue to secure it in place.

Alternative 3 - Exercise Bike with Fan

Some stationary bikes use a fan for resistance, in this case you can attach the magnet to the end of a fan blade.

  1. Remove fan housing from bike.
  2. Attach magnet on fan blade using a second magnet on the other side of the fan blade, double-sided tape or hot glue.
  3. Mount as close to fan housing as possible.
  4. Re-install fan housing.If using a fan style stationary bike you can likely place the reed switch directly on the fan housing.
  5. Install the Reed Switch on the frame or housing within 12 mm (0.5") of the magnet while keeping it clear of any moving parts. Use zip-ties, velcro strips, tape, or hot glue to secure it in place.

Alternative 4 - Crank Mount

If none of the previous methods will work for you, or if you're concerned about disassembling your bike then this method will work as a last resort. Note that your speed will be fixed regardless of what gear or resistance you are using.

  • Install the magnet onto the inside of the crank arm using double-sided tape or hot glue. Be sure to avoid installing on the pedal pivot or too close to the crankshaft.
  • Install the Reed Switch on the frame within 12 mm (0.5") of the magnet while keeping it clear of any moving parts. Use zip-ties, velcro strips, tape, or hot glue to secure it in place.

Step 8: Test Reed Switch

  • Be sure to verify that nothing hits either part, and that they do not interfere with the normal operation of the bike!
  • Once the magnet and reed switch are installed you can verify operation using a circuit tester or multimeter. The switch should be normally open, closing briefly when the magnet passes by the reed switch.
    • If using a multimeter the resistance between the switches should be "infinite" except when the magnet is near the reed switch, in which case it should be as close to 0 as possible.

    Step 9: Program Arduino

    Before you connect your Arduino to the system it is important to install the RTW-bike code. This will ensure old code doesn't run and cause a short from 5V to ground when you first plug it in.

    1. Download the or copy the code below. Alternately you can find it on GitHub at https://github.com/riding-through-walls/RTW-bike.
    2. Open in Arduino IDE or similar and connect your Arduino via USB.
    3. Change #define CRANK_RATIO to the correct number for your setup:
      • On most setups you'll want to simulate a road bike with a 700c tire. Set CRANK_RATIO to 5
      • If you want to calculate the CRANK_RATIO based on your wheel size use the following equation (where d is the diameter:
        • Using a diameter in millimeters: CRANK_RATIO = 11000 / (π*d)
        • Using a diameter in inches: CRANK_RATIO = 433 / (π*d)
        • Round to the nearest whole number.
    4. Compile and upload the code to your Arduino.

    RTW_v01p.ino

    <p>/* <br>Exercise Bike Interface to Google Maps Street View
    Based on Keyboard.Message Example Program.
     Sends a text string when a button is pressed.
     Adapted to include more manipulation for 'Riding Trough Walls': a X-Canada Bike ride througuh Google Streetview, performed by Megan Smith.
     
     The circuit:
     * Magnetic reed switch attached from pin 2 to ground
     * Right pushbutton attached from pin 3 to ground
     * Left pushbutton attached from pin 4 to ground
     * Internal pullup resistors used for all three pins
     
     created 24 Oct 2011
     modified 27 Mar 2012
     by Tom Igoe
     modified 24 June 2012
     by Jeff Adkins
     modified 13 May 2015
     by Megan Smith
     modified 15 October 2015
     by John Campbell
     
    This example code is in the public domain.</p><p><a href="http://www.arduino.cc/en/Tutorial/KeyboardButton">http://www.arduino.cc/en/Tutorial/KeyboardButton</a></p><p> */
     //initialization of constants
    #define NUMBER_OF_BUTTONS  3
     
    #define BUTTON_FORWARD 2
    #define BUTTON_LEFT 4
    #define BUTTON_RIGHT 3</p><p>// number of pedals that invokes a single "up arrow"
    #define CRANK_RATIO 5</p><p>#define KEYPRESS_DELAY_ON  100
    #define KEYPRESS_DELAY_OFF 100</p><p>int buttonPin[NUMBER_OF_BUTTONS] = {BUTTON_FORWARD, BUTTON_LEFT, BUTTON_RIGHT};          // input pin for pushbutton
    int previousButtonState[NUMBER_OF_BUTTONS] = {HIGH,HIGH,HIGH};   // for checking the state of a pushButton
    int counter = 0;                  // button push counter
    int debounceFlag1[NUMBER_OF_BUTTONS] = {0,0,0};            // debounce flag 
    int debounceFlag2[NUMBER_OF_BUTTONS] = {0,0,0};            // debounce flag
    // The debounce flags are two separate magnetic field inputs taken one after the other.
    // if they match, then the switch is assumed to have actually triggered.</p><p>void setup() {
      // make the pushButton pin an input:
      for(int i=0;i<number_of_buttons;i++) {=""  ="" pinmode(buttonpin[i],="" input_pullup);="" }="" initialize="" control="" over="" the="" keyboard:="" keyboard.begin();="" }<="" p=""></number_of_buttons;i++)></p><p>// Main Loop
    void loop() {
      int buttonState[NUMBER_OF_BUTTONS]={HIGH,HIGH,HIGH};
      for (int i=0; i<number_of_buttons; i++)="" {=""  ="" buttonstate[i]="digitalRead(buttonPin[i]);" switch(buttonpin[i])="" case="" button_forward:="" if="" (="" (buttonstate[i]="" !="previousButtonState[i])" &&="" low))="" debounceflag1[i]="buttonState[i];" delay="" (3);="" debounceflag2[i]="digitalRead(buttonPin[i]);" (debounceflag1[i]="=" debounceflag2[i])="" counter++;="" (counter="">=CRANK_RATIO){
                      counter = 0;
                      Keyboard.press(218);
                      delay(KEYPRESS_DELAY_ON);
                      Keyboard.releaseAll();
                      delay(KEYPRESS_DELAY_OFF);
                    }
                  }
                  debounceFlag1[i] = 0;
                  debounceFlag2[i] = 0;
              }
              break;
            case BUTTON_LEFT:
              if(buttonState[i] == LOW) { Keyboard.press(216); }
              else { Keyboard.release(216); }
              break;
            case BUTTON_RIGHT:
              if(buttonState[i] == LOW) {Keyboard.press(215); }
              else { Keyboard.release(215); }
              break;
            default:
              break;
        }
        // save the current button state for comparison next time:
        previousButtonState[i] = buttonState[i]; 
      }
    }
    /*
            if ((buttonState[i]!= previousButtonState[i]) && (buttonState[i] == LOW)) {
              debounceFlag1[i] = buttonState[i];
              delay (2);
              debounceFlag2[i] = digitalRead(buttonPin[i]);
              if (debounceFlag1[i] == debounceFlag2[i]) {
                counter++;
                if (counter>=CRANK_RATIO){
                  counter = 0;
                  Keyboard.press(218);
                  delay(KEYPRESS_DELAY_ON);
                  Keyboard.release(218);
                }
              }
              debounceFlag1[i] = 0;
              debounceFlag2[i] = 0;
    </number_of_buttons;></p> */

    Step 10: Completing Setup

    Run the USB cable from your laptop to the bike and up the frame to the Arduino. Tape the cable to the floor with gaffer or duct tape as necessary and zip tie or tape it to the bike frame. With the wiring complete, connect the USB plug to your computer. If it's not already connected, run the HDMI or similar monitor cable from the computer to the projector or TV.

    Step 11: Ride Through Walls!

    Now that the electronics are installed and the equipment is set up you're ready to go for your first ride!

    1. On your computer, open Google Maps and navigate to wherever you'd like to go for a ride!
    2. Select a location to start either by:
      • Dragging the Street View "Pegman" from the bottom right of the screen to a highlighted road.
      • Clicking on the road, then clicking on the image that appears at the bottom of the screen.
    3. Click "Hide Imagery" in the bottom-right corner of the screen.
    4. To make Street View fullscreen:
      • On PC: Press F11
      • On Mac: Press ctrl+cmd+f or click the green fullscreen button at the top left of the window.
      • You can exit fullscreen mode by pressing the same key(s).
    5. Click on the screen and rotate the view in-line with the road.
    6. Hop on your bike and start pedaling!
    7. To turn, press the left or right buttons mounted to the handlebars.

    Step 12: Troubleshooting

    • Bike stuck or not moving forward
      • Try turning to the left or right to see if you can proceed that way
      • The window may have lost focus, in which case you simply have to go to the computer and click once on the center of the Street View window.
      • Sometimes there are gaps in Street View that prevent you from continuing. In this case you will have to go to your computer and move to a new location to continue.
      • Check to ensure USB is connected and Arduino is powered (green light should be on).
      • Check reed switch wires are properly connected and not severed.
      • Check that the magnet is still in place on the wheel and that the gap between the reed switch has not become too large.
      • Try shorting the contacts on the reed switch to test for a defective switch.
    • Left and Right buttons not rotating view
      • Try pedaling, if the view does not progress follow the steps for troubleshooting a stuck bike above.
      • If the bike moves forward, but the left and right switches don't rotate the view it is likely a problem with the switches or connection.
      • Check button wiring is properly connected and not severed.
      • Try shorting the contacts on the button to test for a defective button
    • Wheel or pedals jamming
      • Check clearance on reed switch to make sure it is not contacting any moving parts
      • Check wire routing to ensure wiring isn't tangled