Bicycle speedometer and odometer
Build it step by step
0 of 6 doneMount the sensor
Fix the A3144 on the fork leg so the magnet on a spoke passes within 5 mm of its flat face.
Fix the magnet
Glue or tape a magnet to a spoke, south pole facing the sensor. If nothing is detected, flip the magnet.
Wire the sensor
VCC to 5V, GND to GND, OUT to D2 with a 10 kΩ pull-up to 5V.
Wire the display
SDA to A4, SCL to A5, VCC to 5V, GND to GND.
Power it
Li-Po into the TP4056 for charging, TP4056 output through a switch to the MT3608 set to 5.0 V, then to the Nano. Never connect a boost output until it is set.
Calibrate
Ride 1 km (use a phone map) and compare the trip distance. Adjust WHEEL_MM in proportion.
How do you build a bicycle speedometer and odometer?
A hall sensor and a magnet on a spoke measure each wheel turn, so an OLED can show speed, trip distance, trip time and a saved odometer. You need Arduino Nano, Hall Effect Sensor A3144, Neodymium magnets (10 × 3 mm), SSD1306 OLED Display, Resistor 10 kΩ, Li-Po battery 3.7 V 1000 mAh, TP4056 Charging Module, MT3608 Boost Module and ABS project box (100 × 60 × 25 mm). It takes 6 steps and about 90 minutes.
- Level
- Beginner
- Time
- About 90 min
- Parts
- 9
Parts list
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- Mechanical & Hardware
- DisplaysBuy
- PassivesBuyResistor 10 kΩ × 1
- BatteriesBuy
- PowerBuy
- PowerBuy
- Mechanical & HardwareBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| A3144 pin 1 (VCC) / pin 2 (GND) | Nano 5V / GND | Sensor power (flat face towards you, pins down) |
| A3144 pin 3 (OUT) | Nano D2 | Pulse for each wheel turn |
| 10 kΩ between A3144 OUT and 5V | Pull-up | Open-collector output needs it |
| OLED SDA / SCL | Nano A4 / A5 | Display |
| OLED VCC / GND | Nano 5V / GND | Power |
| Li-Po through TP4056 OUT, then MT3608 set to 5.0 V | Nano 5V / GND | Portable power, with a switch in the Li-Po feed |
Code
Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones). Install Adafruit SSD1306 and Adafruit GFX. Set WHEEL_MM from your wheel: roll it one full turn on the ground and measure.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <EEPROM.h>
Adafruit_SSD1306 d(128, 64, &Wire, -1);
const float WHEEL_MM = 2105.0; // 700x25c road wheel; measure yours by rolling it one turn
volatile unsigned long lastPulse = 0, period = 0;
volatile unsigned long revs = 0;
unsigned long tripRevs = 0, moveMs = 0, lastDraw = 0, savedRevs;
void onPulse() {
unsigned long now = millis();
if (now - lastPulse > 25) { period = now - lastPulse; lastPulse = now; revs++; } // 25 ms debounce
}
void setup() {
pinMode(2, INPUT);
attachInterrupt(digitalPinToInterrupt(2), onPulse, FALLING);
d.begin(SSD1306_SWITCHCAPVCC, 0x3C);
EEPROM.get(0, savedRevs);
if (savedRevs == 0xFFFFFFFFUL) savedRevs = 0;
}
void loop() {
noInterrupts();
unsigned long p = period, lp = lastPulse, r = revs;
interrupts();
float kmh = 0;
if (millis() - lp < 3000 && p > 0) kmh = (WHEEL_MM / 1000.0) / (p / 1000.0) * 3.6; // metres per second to km/h
static unsigned long lastR = 0, lastT = 0;
if (r != lastR) { tripRevs += r - lastR; lastR = r; }
if (kmh > 0) moveMs += millis() - lastT;
lastT = millis();
if (r - savedRevs >= 250 && millis() - lp > 3000) { savedRevs = r; EEPROM.put(0, savedRevs); } // save when stopped
if (millis() - lastDraw > 250) {
lastDraw = millis();
float tripKm = tripRevs * WHEEL_MM / 1000000.0;
unsigned long s = moveMs / 1000;
d.clearDisplay(); d.setTextColor(WHITE);
d.setTextSize(3); d.setCursor(0, 0); d.print(kmh, 1);
d.setTextSize(1); d.setCursor(90, 14); d.print("km/h");
d.setCursor(0, 32); d.print("Trip "); d.print(tripKm, 2); d.print(" km");
d.setCursor(0, 44); d.print("Time "); d.print(s / 60); d.print(":"); if (s % 60 < 10) d.print("0"); d.print(s % 60);
d.setCursor(0, 56); d.print("ODO "); d.print((savedRevs + (r - savedRevs)) * WHEEL_MM / 1000000.0, 1); d.print(" km");
d.display();
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Spin the wheel by hand | Speed shows a value and falls to 0.0 about three seconds after you stop |
| Ride at a steady 20 km/h | Display shows near 20.0 km/h |
| Ride 1 km | Trip shows about 1.00 km after calibration |
| Switch off and on | ODO keeps its value, saved every 250 turns while stopped |
If it does not work
Speed reads zero while turning
The magnet is too far or the wrong pole faces the sensor. Flip it and bring it to 3 mm.
Speed is double or half
Two magnets or a missed pulse. Check mounting, or change WHEEL_MM only after fixing that.
Display glitches on bumps
Secure the wires and add a 100 nF capacitor at the display.
The sensor chip gets hot
It is in backwards. Check pin 1 is VCC and the flat face is towards the magnet.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the bicycle speedometer and odometer?
Arduino Nano, Hall Effect Sensor A3144, Neodymium magnets (10 × 3 mm), SSD1306 OLED Display, Resistor 10 kΩ, Li-Po battery 3.7 V 1000 mAh, TP4056 Charging Module, MT3608 Boost Module and ABS project box (100 × 60 × 25 mm).
How long does the bicycle speedometer and odometer take to build?
About 90 minutes for a beginner maker, in 6 steps.
How do I know the bicycle speedometer and odometer works?
Spin the wheel by hand: Speed shows a value and falls to 0.0 about three seconds after you stop. Ride at a steady 20 km/h: Display shows near 20.0 km/h. Ride 1 km: Trip shows about 1.00 km after calibration.
Speed reads zero while turning: what should I check?
The magnet is too far or the wrong pole faces the sensor. Flip it and bring it to 3 mm.
Speed is double or half: what should I check?
Two magnets or a missed pulse. Check mounting, or change WHEEL_MM only after fixing that.
Display glitches on bumps: what should I check?
Secure the wires and add a 100 nF capacitor at the display.
The sensor chip gets hot: what should I check?
It is in backwards. Check pin 1 is VCC and the flat face is towards the magnet.
