Introduction: DIY Bike Speedometer W/ Reed Switch & Wifi Kit 8

I have always been curious about my bike riding trends — how fast I ride usually, what routes I take, what my usual cadence is, etc. Well, making this Bike Speedometer was the first step to learning these things. I wanted to make something that would be useful and would also test my circuitry skills, so this bike speedometer (which is relatively simple, but a step up for me in terms of skills such as soldering) was the perfect choice! I was able to use a relatively antiquated but simple sensor technology (a magnet) and use it in tandem with the Arduino-based Heltec Wifi Kit 8 to calculate the speed of the front wheel; this is basically how the speedometer works. Enjoy!

Supplies

Supplies/Materials

  • Bicycle
  • Heltec Wifi Kit 8 board
  • Cardboard
  • 3V battery holder
  • Batteries
  • 22awg spools of red & black wire
  • Reed Switch (Get one that looks like a resistor)
  • Electrical Tape
  • MicroUSB cable
  • Strong magnet
  • Computer with Arduino IDE capability

Tools

  • Soldering iron & filament

Step 1: Install Arduino

First, code should be uploaded to the Heltec; we are going to create a holder for the chip (which has an integrated LCD screen) on the bike in a way that renders the MicroUSB port inaccessible.

Access the Arduino IDE. If you have not installed the IDE yet, go to the link to install here and follow the directions: Software | Arduino

Upon launch and depending on the system theme, the window should look similar to the above.

Step 2: Install Heltec's Board Firmware

The Wifi Kit 8 uses the chip firmware, ESP8266.

  • Click on "File" near the top of the screen. Then click on "Preferences." (left)
  • In the window, copy and paste "http://arduino.esp8266.com/stable/package_esp8266com_index.json" in the "Additional boards manager URLs" field as shown. (top right)
  • Click on "Tools" near the top of the screen. Then click on "Board > Boards Manager." A window similar to the one pictured above will show up. (middle right)
  • Type "esp8266" in the search bar. Click "INSTALL" for the package titled "esp8266". (bottom right)
  • Go again to "Tools" and click "Manage Libraries." A window similar to the Boards Manager window will show up; this one is for libraries instead. Type in "u8g2" and install the library "U8g2" (not pictured, as the process is similar to installing the esp8266 firmware.)

You're ready to put in your code!

Step 3: Input Code

  • Obtain a USB cable such as the one pictured above. (left) Plug this in to the MicroUSB port at the side of the board.
  • Multiply the radius of your bicycle wheel by 357 to obtain a number we'll call the "Speed Constant." For example, my bike diameter is 28 inches, so my speed constant would be (14)(357) = 4998.
  • Copy and paste in the following code. Your screen should look similar to the picture above after this is finished. (right)

#include <U8g2lib.h> // includes library

U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ 16, /* clock=*/ 5, /* data=*/ 4); // establishes u8g display


int reedPin = 10;

int speedTime = 0;

double velocity = 0;


void setup() {

 // put your setup code here, to run once:

 pinMode(reedPin,INPUT_PULLUP);

 Serial.begin(9600);

 u8g2.begin();

}


void u8g2Print(int s) {

 u8g2.setFont(u8g2_font_logisoso32_tf);

 u8g2.print(s,0);

 u8g2.drawStr(18,32,"mph");

 u8g2.setCursor(0,32);

}


void loop() {

 // put your main code here, to run repeatedly:

 if (digitalRead(reedPin) == 0)

 {

  speedTime = 0;

  while(1)

  {

   delay(50);

   speedTime += 50; 

   if (digitalRead(reedPin) == 0)

   {

    break;

   }

  }


  velocity = (int) ([YOUR SPEED CONSTANT]/((double) speedTime));


  if (speedTime != 50)

  {

   u8g2Print(velocity);

  } 

 }

 delay(50);

}

Step 4: Upload

  • Go again to "Tools," then to "Board > esp8266 > Wifi Kit 8." Click on it as shown; this ensures the code will upload to the correct type of board. (left)
  • Click on the arrow button in the top left of the screen. This uploads the code to the board. (right)

Step 5: Prop Up the Wifi Kit & Attach to the Handlebars

After uploading the code, you may disconnect the board.

  • Place the board on a piece of cardboard similar to the diagram shown, taking special care to make sure that the pinholes have adequate space underneath them. Place the board and the cardboard carefully on the handlebars. (left)
  • Use electrical tape to attach the board onto the handlebars by wrapping tape around the sides of the board, leaving all of the LED screen visible. Your chip/monitor should be secured to the handlebars. (right)

Step 6: Solder the Reed Switch

  • Take the reed switch and a spool of red and black wire. Remove a strip of wire from each sufficiently long to extend from the handlebars (where the chip is) to the middle of the front wheel. Strip off the insulation from the ends of the wires; this can be done using a wire stripper (recommended) or using scissors.
  • At a soldering station, use clips (on the left of the above picture) to lay the red wire's metal part on the metal part of the reed switch. Solder the two wires together by holding the heated soldering iron below the point where the two touch for about five seconds and bringing the filament close to the soldering iron. The soldering iron will melt the filament, connecting the bond. Repeat for the black wire. The finished product should look like the picture above.

Step 7: Tape the Reed Switch to the Bicycle Frame

  • With a small piece of electrical tape, adhere the tape onto the reed switch, then place it onto the bicycle frame at the location where a wheel spoke is closest to the frame. Place a magnet on the spoke near the reed switch and tape it to the spoke with electrical tape. The finished product should look something like the above.

Step 8: Solder the Reed Switch to the Board

  • Solder the other ends of the red and black wires to the board. The red wire should connect to the hole that says "D6" next to it. The black wire should connect to one of the "GND" holes. The reed switch will now comprise part of a complete circuit that uses magnetic attraction to detect when the revolution of one wheel has been completed.

Step 9: Solder the Battery Pack to the Board

  • Take the battery holder and solder the red wire to "3.3V" and the black wire to "GND." This will power the circuit.

Step 10: Place Batteries in the Battery Pack

  • Place two 1.5V batteries in the battery pack. Your Wifi Kit should power on and print out "0 MPH." Ride around on your bike and enjoy your new speedometer!