Arduino Bike Speedometer

by amandaghassaei in Circuits > Arduino

433765 Views, 383 Favorites, 0 Comments

Arduino Bike Speedometer

main.jpg
IMG_9279 copy.jpg
Monitor your road speed using the Arduino. This project uses a magnetic switch (also called a reed switch) to measure the speed of one of the bike's wheels.  The Arduino calculates the mph, and send this information out to the LCD screen on the handlebars as you ride.  It is compatible with any kind of bike/wheel, simply enter the radius of the wheel in the firmware to calibrate the device for your setup.



Parts List:

(1x) Arduino Uno REV 3 Radioshack 276-128
(1x) Switch-Magnetic Reed Radioshack 55050593
(1x) 10K Ohm 1/4-Watt Carbon Film Resistor Radioshack #271-1335
(1x) 9V Alkaline Battery Radioshack #23-866
(1x) Heavy-Duty 9V Snap Connectors Radioshack #270-324
(1x) PC Board with Copper Radioshack #276-147
(1x) Parallax 27977-RT Serial Backlit LCD Radioshack 276-120
(x2) SPST PC-Mountable Submini Toggle Switch Radioshack #275-645
(2x) Male Header Pins Jameco 103393
(1x) Female Pin Sockets Jameco 308567

Additional Materials:
22 Gauge Wire Radioshack #278-1224
Solder Radioshack #64-013
sand paper
plywood
wood glue
hot glue
screws
zip ties
sugru

Download Arduino IDE

Schematic

schematic.jpg
The schematic for this project is shown above.

It consists of three switches:
-one to connect to a 9V power supply
-one to switch the backlight of the LCD on and off
-a magnetic switch (called a reed switch) which closes each time the wheel completes one full rotation.

The Parallex LCD is designed to connect to the arduino using only three pins (ignore the labels and the other pins int his schematic).  One to 5V, one to ground, and a third to serial out (TX)- on the arduino, serial out is digital pin 1.

10kOhm resistors are connected to the reed and backlight switches to prevent excess current between 5V and ground (you should never directly connect 5V and ground on the arduino!)

Protoboard

IMG_5509 copy.jpg
IMG_5508 copy.jpg
Solder three rows of header pins on the protoboard so that the arduino will snap to it as shown in the images above.

Reed Switch

IMG_9337 copy.jpg
IMG_9082 copy.jpg
IMG_9083 copy.jpg
IMG_9084 copy.jpg
IMG_9086 copy.jpg
IMG_9087 copy.jpg
IMG_9088 copy.jpg
IMG_9085 copy.jpg
The reed switch is comprised of two pieces, a switch and a magnet. The switch has two wires extending out from it, when a magnet comes near the switch it causes a small mechanical piece to move and close the switch momentarily.

Solder a 10kOhm (current limiting) resistor between A0 and ground on the protoboard. Connect long pieces of stranded wire to A0 and 5V- these wires will wrap around the bike and attach to the reed switch.

Mount Reed Switch on Wheel

IMG_9344 copy.jpg
IMG_9343 copy.jpg
IMG_9341 copy.jpg
IMG_9337 copy.jpg
F6NCGE1H3JXA2QT copy.jpg
Secure both the magnet and reed switch to your bike wheel with electrical tape (either wheel is fine).  As shown in the images above, the magnet connects to one of the tire spokes and the reed switch connects to the frame of the bike.  This way, each time the bike wheel turns the magnet moves past the switch. Connect the leads form the reed switch to the long wires from your protoboard (orientation does not matter here- it's just a switch)

Use the code below to test your reed switch. When the magnet on the wheel moves past the switch, the arduino should print ~1023, otherwise it will print ~0. Open the serial monitor (Tools>>Serial Monitor) in Arduino IDE to test for your own setup.  If the magnet does not seem to be affecting the reed switch, try repositioning it or even adding a stronger magnet if you have one.

Test Switch

FUJ5OCOH3P0J9J4 copy.jpg
Load the code below onto the Arduino. Turn on the serial monitor. It should output 0.00. Start turning the bike wheel, you should see a print of the current mph each second.

LCD

IMG_9089 copy.jpg
IMG_9090 copy.jpg
IMG_9091 copy.jpg
IMG_9096 copy.jpg
IMG_9092 copy.jpg
Solder a row of female header sockets on the copper side of the protoboard- three of these will be used to connect to the LCD screen. The LCD should fit nicely on top of the protoboard.

Install Parallax LCD Library

IMG_9099 copy.jpg
IMG_9101 copy.jpg
Connect Arduino 5V, Ground, and TX (Arduino digital Pin 1) to the LCD socket. Read the labels on the LCD pins to make sure you have everything oriented correctly.

Parallax LCD

IMG_9190 copy.jpg
The underside of the Parallax LCD has two switches and a potentiometer. The pot controls the contrast of the display- you can adjust this to what you like. The switches must be set as they are shown in the image above for proper functioning.

Test LCD

IMG_9181 copy.jpg
Test the following code. For some reason my LCD starts making noise and displaying random characters when I first upload, but works fine once I unplug and reconnect the usb connection. I think this may have something to do will interference from the arduino communicating with the computer via digital pin 1 (TX) during the upload.

The LCD should display "Hello World" when it is turned on.

Backlight Switch

IMG_9183 copy.jpg
IMG_9184 copy.jpg
IMG_9185 copy.jpg
Wire a switch as shown in the image above. Connect a 10kOhm resistor and a green wire to one lead, and a red wire to the other.

Connect the red wire to Arduino 5V, the other side of the resistor to ground, and the green wire to D2.

Final Speedometer Code

IMG_9182 copy.jpg
Upload the following code onto the Arduino. Test to make sure the backlight switch works and the speed displays properly.  (Again, you may have to unplug the board after loading the firmware and plug it back in again to get it to work properly.)

Measure the radius of your tire wheel (in inches) and insert it in the line: float radius = ''''';


I used timer interrupts in this piece of code to keep the variable "timer" incrementing at 1kHz.  More info about interrupts and an explanation of how I set it up can be found here.

Battery

IMG_9186 copy.jpg
IMG_9189 copy.jpg
Wire the battery connector and switch in series as shown in the first image above. Connect the read lead from the switch to Arduino Vin and the black wire from the battery connector to Arduino ground.

Enclosure

IMG_9273 copy.jpg
Screen shot 2012-06-19 at 6.27.10 PM.png
Screen shot 2012-06-19 at 6.30.05 PM.png
Screen shot 2012-06-20 at 2.53.15 PM.png
I cut my project enclosure from 1/4" ply on an epilog 120Watt laser cutter.  The dimensions of the enclosure are 3.5"x4"x2".  I modeled the box in AutoCAD and generated the laser cut files (with finger joints) in Autodesk 123D Make.  Then I added two holes for the switches and a rectangular opening for the LCD screen.  I also added some holes on the bottom of the enclosure to make attaching it to the bike easier.

I glued the project enclosure together with wood glue and sanded the edges down. I finished the enclosure with some clear polycrylic.

Install Components in Enclosure

IMG_9277 copy.jpg
IMG_6944.jpg
IMG_9278 copy.jpg
IMG_9279 copy.jpg
Secure the switches onto the enclosure with nuts. Glue or screw the lcd to the underside of the front panel.
Fit the Arduino and Protoboard as well as the battery into the enclosure and secure with velcro or glue.
Screw or fasten the enclosure shut.

Attach to Bike

IMG_9345 copy.jpg
IMG_9346 copy.jpg
IMG_9347 copy.jpg
IMG_9350 copy.jpg
Wrap the reed switch wires around the bike frame, away from any moving bike parts. I used sugru and some zip ties to attach the speedometer to the handle bars.

Take It Out on the Road

Screen shot 2012-07-09 at 11.47.21 AM.png
You should be ready to hit the road. Don't let the awesomeness of your new bike speedometer distract you from road hazards!