How to turn an ordinary exercise bike into a virtual bike that lets you tour the world.
With a little ingenuity, coding and some help from older brother James, Miles interfaced his exercise bike with Google Street View to virtually tour the world as he pedalled. We caught up with Miles to find out more about his project.
Thank you for sharing your cool project with us Miles. Can you tell our readers more about yourself?
I am in Year 7 at the moment, I love open hardware and software. and I spend my life soldering, 3D printing and coding.
That’s awesome that you are into hardware and code at such a young age. What motivated you to make your virtual bike project?
The project was motivated by wanting to come home after school and wanting to explore more of the globe. Why ride my bike around my suburb, when I can ride it over the Golden Gate Bridge!
What a great way to see explore more of our wonderful planet without leaving the house. Did you build this from scratch or get design inspiration from another project?
The design was from a previous project that used the same components and measured speed and distance from the static bike. It was cool, but this is way cooler!
We like your thinking. Pedalling on a static bike, watching a speed and distance display would be boring. What parts does your project use and how do you navigate the streets as you pedal?
I used:
1 x Arduino Mega 2560 (A Uno would work fine too)
1 x Arduino USB Cable
1 x Arduino Reed Switch Module (Jaycar Part No. XC4476)
1 x Generic Magnet (I got mine in a 10 pack from Bunnings)
1 x Generic PC Mouse (Just to steer)
I put my wired computer mouse on a cutting board on the handles of the bike so I can turn, look around and see different things.
Using a mouse is a simple and no fuss idea to turn. How did you go about mounting the reed switch and magnets?
I mounted everything with Blu-Tak because it is what every maker wants things to be, easy to use and cheap. The magnets stick to the wheel magnetically and I used an exercise weight to get the reed switch into the best position.
Nice and easy, and saves getting the tools out or dealing with messy glue. What design challenges did you need to overcome and how?
It was fairly easy except for when the code went astray and spammed the “w” key on my laptop. We had to restart the computer to stop it spamming everything!
Another setback was that I was in no way familiar with Visual Studio. I had to learn the basics in a few days, but a finished project is worth the effort eight times over.
Visual Basic Code
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SerialPort1.Open()
End Sub
Private Sub Form1_MouseClick(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
While True
If SerialPort1.ReadChar() = "35" Then
SendKeys.SendWait("w")
End If
End While
End Sub
End Class
Arduino Code
#include "cool.h"
void setup() {
// put your setup code here, to run once:
pinMode(WheelClick,INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(WheelClick) == 1 && printed == 0) {
timeNow = millis();
n = n + 1;
timeChange = (timeNow - timeLast) / 1000;
wheelSpeed = 3.6 * circumference / timeChange;
wheelDistance = wheelDistance + circumference;
Serial.println(wheelSpeed);
/*Serial.print(" kph, ");
Serial.print(wheelDistance);
Serial.print(" m, ");
Serial.print(millis()/1000);
Serial.println(" s");
Serial.println("");*/
printed = 1;
timeLast = timeNow;
}
if (digitalRead(WheelClick) == 0) {
printed = 0;
}
}
Custom Library
#define WheelClick 5
int printed = 0;
float timeLast = 0;
float timeNow = 0;
float circumference = 1.444;
float wheelSpeed = 0;
float wheelDistance = 0;
float timeChange = 0;
int n = 0;
int inc = 5;
Congrats on learning to code with Visual Studio in such a short amount of time. If you were to start the design over again, would you change anything?
If I had to start again, I would probably watch over the code and implement a fail-safe for virtually pressing the keys. Everything else was pretty simple to do with my brother’s and my coding knowledge.
Sounds like your brother and yourself make a great coding team. Is there anything else you think our readers should know about the project that we haven’t covered yet?
It turns out that Visual Basic does everything way too simply. I thought I would have needed libraries and functions and mountains of code and lots of weird programs to virtually press keys. But it’s just SendKeys.Send(). That took way too much research during English class! I had to reach through piles of documentation for one line of code.
We hope you learned other things during the research. Are you working on any other projects?
I’m kind of into doing something for Christmas, like the fake-flame from Issue 23 on my tree for a twinkling tree. Maybe sharpening my Mechanical and Mechatronic Engineering skills. 3d printing in the meantime though.
We’d love to see a pic of the flickering flame on your Christmas tree. We look forward to seeing more exciting projects from you in the future. Happy making!