Introduction: Arduino Bike Speedometer

Picture of Arduino Bike Speedometer
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
wood glue
hot glue
zip ties

Download Arduino IDE

Step 1: Schematic

Picture of Schematic

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!)

Step 2: Protoboard

Picture of Protoboard

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

Step 3: Reed Switch

Picture of Reed Switch

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.

Step 4: Mount Reed Switch on Wheel

Picture of Mount Reed Switch on Wheel
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.

Step 5: Test Switch

Picture of Test Switch
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.

Step 6: LCD

Picture of LCD

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.

Step 7: Install Parallax LCD Library

Picture of Install Parallax LCD Library

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.

Step 8: Parallax LCD

Picture of Parallax LCD

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.

Step 9: Test LCD

Picture of Test LCD
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.

Step 10: Backlight Switch

Picture of Backlight Switch

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.

Step 11: Final Speedometer Code

Picture of Final Speedometer Code
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.

Step 12: Battery

Picture of Battery

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.

Step 13: Enclosure

Picture of Enclosure

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.

Step 14: Install Components in Enclosure

Picture of Install Components in Enclosure

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.

Step 15: Attach to Bike

Picture of Attach to Bike

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.

Step 16: Take It Out on the Road

Picture of Take It Out on the Road

You should be ready to hit the road. Don't let the awesomeness of your new bike speedometer distract you from road hazards!


kilimanjaro1029 (author)2017-11-01

I connected the Arduino to a 16x2 LCD, but its not powering on. Will any 16x2 LCD turn on by just connecting those 3 pins mentioned?

Shahid Khattak made it! (author)2016-11-23

I modified the Schematic and Sketch for use with 128 x 64 Graphics LCD (with blue Background), I am using it with my Motor Cycle. It is giving good result. Further testing it, And seeking permission from Amanda to upload it as instructable on this site. Image of the final Display is attached. I am currently using it with the reed switch, but I have tested it with hall effect sensor, and it is working perfectly, (a little change will be made in sketch and schematic to use it with hall effect sensor).

Amanda!!! Can i upload it as instructable on this site?

This is awesome dude,

Can you help me?

wanted that too

Yes, I can. I have a instructable for that. Please check it.

awesome! yeah go for it!


amandaghassaei (author)2017-03-23

For those asking about the mph calc:

mph = (56.8*float(circumference))/float(timer);

"circumference" is measured in inches

time per revolution of the wheel ("timer") is measured in milliseconds (0.001s)

miles/hr = 1/(inches per mile) * (miliseconds per hr) * (circumference / timer)

there are 63360 inches in a mile and 1000*60*60 = 3,600,000 ms in an hr:

mph = 1/63360*3600000*circumference/timer

mph = 56.8*circumference/timer

to do this in km/hr:

km/hr = 1/(inches per km) * (miliseconds per hr) * (circumference / timer)

km/hr = 1/39370*3600000*circumference/timer

km/hr = 91.4*circumference/timer

PhremC (author)amandaghassaei2017-05-31

hi amanda , may i know which library u use for the coding .

yerrasandeep (author)PhremC2017-10-16

Hi amanda,same request like PhremC "Which library u use for the coding"

it will help me.

YasirA50 (author)amandaghassaei2017-03-31

Can you use any LCD or would it have to be specific one?

ahunkeri (author)2017-08-01

Hey. i'm doing an shoulder wheel rotation count project. In this total count of wheel rotation by patient is sent to doctor by text message. For this I need little help regarding How to count rotations. also i want to check whether patient is exactly how much hand is moving or 90degree, 180degree,270 degree and 360/0degree.

RăzvanN4 (author)2017-06-27

Can i make the same project (speedometer) and attach a photoresistor-LED-on/off (the LED should power on automatically when dark) using the same arduino board and the same breadboard?

Photoresistor :

VasaCZ (author)2017-06-08

Dobrý den, šel by tento projekt udělat tak že by se místo magnetického spínače použil magnetický senzor?

puljiun (author)2017-06-01

My reed switch test has a lot of noise. Is it because I haven't soldered the switch into the board?

arduinolife (author)2017-05-14

hi, I'm having trouble displaying the speed on the lcd. what code did you use?

Lucaszech (author)2017-05-10

How do I test the LCD?

nico_0001 (author)2017-04-28

HI AMANDA ...CAN YOU HELP ME in km/hr...where I modify/add code...pls Thank you

DocRules (author)2017-01-28

Instead of using a Parallax LCD, can i use an LCD with a I2C module attached to it?

Like this one:

DocRules (author)2017-01-28

Instead of using a Parallax LCD, can i use an LCD with a I2C module attached to it?

Like this one:

franciscaa7 (author)2016-12-17

here's a short video of the installation, to give you a better idea of what it is

franciscaa7 (author)2016-12-17

Hi, I used this code to use my bike as a light switch (speed higher than 3mph, lights on, lower, lights off). It is an art installation, so the bike is static and a 5v relay acts as a switch for 40 3w led bulbs. Initially it worked fine, but after a while the lights didn't go off when people stopped pedalling. I know nothing about programming and posted this problem on the arduino forum. Tweaked a few things (made the variables in the interrupt volatile and declared the reed pinmode as INPUT_PULLUP. This made the thing more stable, but eventually the error happens anyway. The worst part is I can´t predict whether it will happen after 3 or 6 hours or 2 or 20 users. If any of you guys have ANY clues as to what might be going on here, I'd really appreciate the help- THANKS!!!

Rifale (author)2016-12-13

hi amanda i will built like yours but i'am using magnetic sensor, can it work?

SteveW238 (author)2016-10-12

I'm curious if someone could answer this question for me (outside the OP) I use the code above from Step 11. if my reed makes just 1 contact (1 iteration) the MPH displayed is 47 mph. Even if I slowly move the wheel it is always 47 or 50 mph. Can someone explain why and how I can make it more realistic?

I noticed in her console outputs that those figures are about what I am getting.

GarrettS13 (author)SteveW2382016-10-19

I commented out the first time this line was used and it seemed to fix it.

reedCounter -= 1;//decrement reedCounter

I don't think you won't to drop the counter if the reed sensor is closed and the bike is not moving.

Mase13 (author)2016-10-01

gotta say thanks for the great idea and the code. used a 12c lcd, added a smoothing section of the code to average out some of the results. put it on my four wheeler and love it.

essexgary (author)2016-07-31

Could I use 3 x 7 segment led digits for my read out as these are large (5")

jorgito123 (author)2014-09-08

What things should i change to use it in km/h? And whats that 56.8 in the code?

JingxueT (author)jorgito1232015-10-21

Hi, have you figured out what 56.8 is? I also want to use it in km/h, but don't have no idea what this is.

JochemB3 (author)JingxueT2016-07-29

Change it to 91.44 for km/h.

Calculation: 1 inch/second = 2,54 cm/s = 0.09144 km/h = 91.44 inch/ms.

Or just multiply 56.8 by 1.6090712742981 (= 19.40)

JingxueT (author)jorgito1232015-10-21

Hi, have you figured out what 56.8 is? I also want to use it in km/h, but don't have no idea what this is.

AndresC45 (author)JingxueT2015-11-08

1 inch/second is 0.0568 mph therefore 1 inch/millisecond = 56.8 mph

StephiewH (author)2016-07-22

Hi Amanda ! I Made it, but I just to know how did you madethe calcul for mph?(

mph = (56.8*float(circumference))/float(timer);//calculate miles per hour ) ) I don't understand ?!! :(

And Ihave another question : how can I do if I only want to print RPM on the screen ?

TayoO2 (author)2016-04-24

can anyone explain the purpose of the reed counter ?

Kutluhan (author)TayoO22016-06-18

It is working like a rpm sensor. Every time wheel makes one turn, magnet closes the reed switch and this pulse goes to input pin of arduino. Arduino counts every pulse and convert it to speed with built-in code.

highwingpilot (author)2015-12-28

Hi Amanda, very helpful tutorial! Question for you... I'm trying to use this for measuring speed and distance of my son's hamster wheel. And will try to use a light sensor and LED to measure the revolutions of the wheel (no wires for the hamster to chew). For now just testing the code with a pushbutton switch to simulate RPMs. The radius of the wheel is 4.25 inches. With low RPMs (between 1 and 2 revs per second), I get a fixed speed of 15.02mph. Higher revs start to give me fluctuating speeds as expected. When RPMs drop to 0, it shows a speed of 0.002 mph (never 0.00). Any suggestions on how to fix it? Thanks in advance!

A light sensor sends a HIGH signal when there is no light. So, you need to add a "!" somewhere. I think if (!reedVal

Đình TàiN made it! (author)2016-05-17

Made it, not exactly the same but still working. Great!!

CornelN1 (author)2016-04-10


i am workind on something similar, he differences are:

- i have a line follower sensor on digital pin 2

- i have a black and white stripe with 20 mm between 2 white stripes

- i need the output on the serial monitor, and not on the lcd.

i have put up a sketch, but i have some issues with the time.

i need to:

- start the counting every time the pin 2 changes (the sensor has moved) and count the millis until next pin 2 changes, and have the speed. at the end, if the pin 2 does not changes for 1 sec, the program stop's

can someone help me?

i have this sketch until now:

// Constante:

const int buttonPin = 2; // pinul digital pentru senzorul de linie

// Variabile:

int buttonPushCounter = 0; // counter numar impulsuri (1 sau 0)

int buttonState = 0; // starea actuala a senzorului de linie (1 sau zero)

int lastButtonState = 0; // starea anterioara a senzorului de linie (1 sau zero)

long time = 0;

void setup() {

// inititalizeaza intrarea pentru senzorul de linie:

pinMode(buttonPin, INPUT);

// initializeaza comunicatia seriala:



Serial.println("Program test");



void loop() {

// citeste intrarea senzorului de linie:

buttonState = digitalRead(buttonPin);

time = 0;

// compara starea butonului actuala cu cea anterioara

if (buttonState != lastButtonState) {

// if the state has changed, increment the counter

if (buttonState == HIGH) {

// if the current state is HIGH then the button

// wend from off to on:




Serial.print("Deplasare [mm]: ");


Serial.print("Timp [s]: ");

time = millis();

//prints time since program started


Serial.print("Viteza [mm/s]: ");



// Delay a little bit to avoid bouncing



// save the current state as the last state,

//for next time through the loop

lastButtonState = buttonState;

time = 0;


ztaticz (author)2016-01-15

can anyone explain the purpose of the reed counter and max reed counter? is it the max time for one rotation or something to that effect?

b3nz1 (author)2014-04-14

I've tried using this code to measure windspeed on an anemometer for a project of mine. it's a rotating magnet and a reed switch so it's the same principle. The reed test works fine. i've changed the radius (0.87 inches) to fit with my windspeed sensor. However when i upload the code, the serial port view just gives me 0's for MPH for the first reading then a steady steam of 28.21 MPH. Any ideas?

poor_leno (author)b3nz12015-08-25

Did you manage to work this out in the end b3nz1? I'm doing similar.

blitss (author)poor_leno2015-09-04

I had the same problem. What i found was that my reed switch was dong one of 3 things; 1.chattering when the magnet was passed over it. To fix this I just increased the maxreedcounter value to 150 or 200ms. The original 100ms wasnt enough to sstop the second switch cycle induced when the switch left the magnetic field. 2. If i passed the magnet too slowly over the switch the switch would stay closed for more then 1 sample cycle, so the maximum speed reading would output. ;so eithur move the magnet faster over the switch or find a mag with a more concentrated field. 3. My first reed switch was normally closed, my own stupitidy there... get one thats n/o. goodluck

have u found out what that 56.8 value is? im tryna chang the code and lost where that comes from.

JingxueT (author)blitss2015-10-21

hi,have you figured out what the 56.8 value is? I am also doing a similar project, but I want to show the speed in km per hour. I have changed something, but still have no idea what 56.8 is.

phillip.manock (author)2015-10-07

Hello Amanda! Im trying to do something similar to your project, but I would like to use a hall effect sensor as it can be used at higher frequencies, how would the code change to accomodate the Hall Effect sensor?

lililibre (author)2015-10-07

for me the code is not correct. The pulse should be captured when reedVal and reedcounter=maxreedcounter not when reedcounter=0

ikowalska (author)2015-02-14

Hi Amanda, I have a problem with your's code on my stationary bike. Speed calculated by arduino is very low (sth like 1 - 5 km/h max) and I don't know what is wrong :/ I changed only radius for 0.12 m (this is radius of my stationary bike wheel). Is that any problem with fact then my bike have a belt drive ? Something like this ? Please help!

AshleyD2 (author)ikowalska2015-08-20

A little late, but FYI the wheel size should be in Inches not meters

mholthaus99 (author)2015-06-12

Alessandro Ansa (author)2015-03-30

Hi Amanda

Great instructable! I'm trying to use the same principles in a slightly different project in which I am importing a library what already uses the Timer1 interrupt - what would be the implications of using Timer 2 as the interrupt in the code to measure the speed of the wheel in terms of accuracy of measurement? And is it simply a case of amending the timer setup to use TCCR2A etc.?

ŽanP (author)2015-03-24


Can anyone share code for this but with classic display? I dont have experience with programming so i need some help. Thanks for helping.

About This Instructable




Bio: I'm a grad student at the Center for Bits and Atoms at MIT Media Lab. Before that I worked at Instructables, writing code for ... More »
More by amandaghassaei:OTCA Metapixel - Conway's Game of Life"9 Degrees of Freedom" IMUTwitter Controlled Pet Feeder
Add instructable to: