Arduino Bike Speedometer Zack Einhorn and Trey Oehmler


We began this project with the goal of making biking safer. Bikers face many dangers on the road. For example, unless there is a bike lane, bikers must share roads with vehicles that are much bigger and often driven by distracted drivers increasing the risk of deadly collisions. Bikers must also adhere to the rules of the road, including speed limits, to make sure they are safe and do not cause any traffic disruptions. Our project is built around these safety concerns. We want bikes to be more visible, preventing collisions. And by providing feedback to riders, they can maintain a safe speed.


We used an Adafruit HUZZAH32 to control our system and code in C++ through the Arduino interface. The first piece of our system is LED headlights that turn on when it is dark outside. We attached a photoresistor to an analog read pin to detect changes in outside light. When the light is below a certain brightness a pair of LEDs illuminates.

We display the speed of the bike on a backlit LCD display. The LCD update code and the light detection code are in the main loop and run continuously. To help with displaying information on the LCD, we used the Arduino LiquidCrystal library.

Image: Soldering the LED headlights together.

To detect the speed of the bike, our board is connected to a reed switch which is mounted on the front wheel’s tire fork. The switch’s trigger is mounted to the wheel and closes the circuit when the tire makes a full rotation, then it triggers an interrupt.

We began to configure the reed switch by following amandaghassaei’s steps in her Instructables guide (see resources). Her project uses an Arduino Uno, so we could not use her code directly, but we set up code to figure out when the reed switch was opened or closed.

Image: Adafruit HUZZAH32

To calculate the MPH, we started with amandaghassaei’s strategy which uses a timer to check if the tire has made a complete rotation 1,000 times every second and then calculates speed using the time it took. Constantly using a timer interrupt limits our ability to add more peripherals which also use interrupts. Instead, our speedometer figures out how long it takes the wheel to make one rotation by saving the current time when the interrupt fires and then subtracts it from the time of the last called interrupt. Then it divides the distance of the circumference of the bike tire by the travel time.

Other than the LCD, which only displays the current speed, the bike speedometer does not have a user interface! After the device is powered up, it does everything on its own.

Image: Our system not mounted on a bike.

Algorithm Diagram

Bill of Materials



Original plan:

One week to:

- Set up the display and write a driver - similar to the lab in class

- Set up the reed switch - figure out how the board reads inputs and reacts to the switch

- Attach the switch to the bike

- Configure the switch to read the speed of the bike by counting the rotations of the tire in a certain amount of time

One week to:

- Configure the LED

- Configure the light sensor and write a driver to turn on the LED when it is dark

Last week to:

- 3D-print a box to hold the board and the LED. Mount the box on the bike

Followed Plan

First week:

- Set up the display

- Began to write and understand how the reed switch works

Second week:

- Complete the reed switch code

- Configure the light sensor

Third week:

- Attach the LED

- Attach the prototype to a bike

- Create final presentation

We followed our schedule fairly closely. We realized that we should not attach anything to the bike until it was all put together so those steps were moved to the last week. We also had difficulty configuring the reed switch and took more time to figure it out than expected.


We had difficulty creating an effective way of figuring out when the bike has stopped moving. Our speedometer only does speed calculations when the reed switch is triggered, so if the bike stops, the speedometer is stuck at the last calculated speed, waiting for the next interrupt to update the speed. We solved the problem by forcing the speed to zero if there has not been an interrupt after a certain amount of time.

We also had issues with the LCD. We originally displayed the speed on the bottom line of the display. Every time on startup, it would display 27.68 and then after a few seconds reset to 0. We thought the number was the MPH from the last time the board was on, but it was consistently 27. Also, the code sets the saved MPH to 0 on startup. Our first attempt at fixing the bug was to clear the board after initializing it and at the beginning of each loop. But this made the display hard to read. We decided that working with both lines of the display was causing the issues, so we moved all of the information to the first line. We are not sure why, but this gave us more control over what we were displaying, and we could set the displayed MPH to 0 on startup.

On the hardware side, the reed switch was difficult to rig onto the bike. The switch and the trigger need to be very close to each other in order to get a reading. On the bike we used for the prototype, the tire and the fork are farther than this minimum distance, so the speedometer could not make readings. We used foam and a lot of electrical tape to give the trigger a platform and put it in the range of the switch (see image).

We bought a 3.7V battery pack to power the board. But the display we use needs 5V so the system would not power up. To solve the problem, we power the speedometer with a 5V USB battery pack.

Future Work

If we had more time to work on the project, we would figure out the slowest reasonable riding speed to make the speed display zero as fast as possible (right now it takes four seconds to display zero). We would also add more safety features. To increase visibility in addition to the LED headlights we would add taillights and turn indicators. The taillights would work in the same fashion as the headlights and the indicators would be triggered by a button on the board and would flash for five seconds. We also want to add a temperature sensor to alert the rider when the roads could be slippery. To make the bike pedestrian-friendly we would create a digital bell that is triggered by a button on the bike’s handles.

We also want to make a case for the system so it can be left out in the rain and not be damaged.




Created with images by Adafruit • Andrew Gook - "Beware of these Streets" • Luke van Zyl - "untitled image" • Luís Sousa - "COUNTERFEITING" • Robert Ruggiero - "Biking in the Snow"