Bike Speedometer

Views: 617 Difficulty: 4 Status: Development
Screen_shot_2012-12-21_at_7.15.15_pm

A hall effect sensor and an LCD screen gives you a DIY bike speedometer.

We put a magnet in our spokes and sense bicycle tire revolutions with a hall effect sensor. We output speed and and distance to an alpha-numeric LCD screen. We also throw in a temperature sensor for good measure.

Board FIle

Screen_shot_2013-03-08_at_2.31.29_am
  • Screen_shot_2013-03-08_at_2.31.29_am
    Screen_shot_2013-03-08_at_2.31.29_am
    Board FIle
    An Image of the EAGLE board file.
  • Screen_shot_2013-01-26_at_3.50.07_pm
    Screen_shot_2013-01-26_at_3.50.07_pm
    Kit Contents
    See the parts list for part numbers and component values.
  • Screen_shot_2012-12-21_at_7.15.15_pm
    Screen_shot_2012-12-21_at_7.15.15_pm
    Bike Shaped PCB
    We shaped our bicycle speedometer like a bicycle. Onomatopoetic isn't it? We connect the hall sensor to the hardware interrupt pin on the arduino. Then we add a magnet to our tire spokes. Now every tire rotation is detected and we can update the speed and distance travelled accordingly.
  • Screen_shot_2012-12-21_at_7.13.47_pm
    Screen_shot_2012-12-21_at_7.13.47_pm
    Hall Effect PCB
    This PCB can hold either a rare-earth magnet in the square slot in the middle or surface mount hall effect sensor on the other side. The 3 wire are power ground and the hall sensor signal which we plug into the bike-shaped PCB.
  • Screen_shot_2012-12-21_at_7.14.05_pm
    Screen_shot_2012-12-21_at_7.14.05_pm
    The Whole Pakage
    Here see the reverse side of the hall effect sensor PCB along with the bike-shaped PCB and the alpha-numeric LCD screen.
  • Screen_shot_2012-12-21_at_6.45.45_pm
    Screen_shot_2012-12-21_at_6.45.45_pm
    Little Bikey
    The 3 wires at top go to the hall-effect sensor PCB. The two wires at bottom are hooked up to a battery pack. The bike speedometer runs on top of arduino so it can be re-programmed using the ISP pins near the bike seat.
  • Bike_scheme
    Bike_scheme
    Schematic
    Electrical schematic for the bike circuit. The source file can be downloaded below.
  • Screen_shot_2013-01-25_at_11.51.37_pm
    Screen_shot_2013-01-25_at_11.51.37_pm
    Iterations!
    Several iterations of the bike computer PCB.
  • Screen_shot_2013-03-08_at_2.32.51_am
    Screen_shot_2013-03-08_at_2.32.51_am
    Silkscreen Bitmap
    The bicycle silkscreen. Want to use this or any of our PCB silkscreens in your project? Download our EAGLE bitmap library.
An Image of the EAGLE board file.

FFW Speedometer Movie

The making of the through hole component speedometer in fast forward. The actual process takes about 45 minutes but here you can watch it in 45 seconds!
J0308903 ako: ultra speed !

Speedometer Code

Speedometer code keeps track of tire revolutions using a hall effect sensor. Code assumes 26 inch tires but this can be tweaked to your tire size by changing the variable:
float tire_diameter = 26.2; // put in your tire dimaeter in inches
The code that does the heavy lifting is the function:
void updateSpeedAndDistance(){
  distance = tire_circumference * revolutions;
  distance /= miles_in_inches;
  float ipm = tire_circumference / (float)last_interval;
  mph = ipm * k_ipm_2_mph;
}
This code translates from the number of tire resolutions to the speed you are going and the distance you have travelled. We know the tire revolutions by checking the hall effect sensor as we do in the following code found in the loop function:
int hall_val = digitalRead(hall_pin);
  if (hall_state != hall_val && hall_val == LOW) {
    revolutions++;
    last_interval = millis()-last_fall;
    last_fall = millis();
  }
  hall_state = hall_val;
So we check to see if the state of the hall pin has changed, and if it has changed to low so we are on the falling edge of the clock. Then we know the tire has made a complete revolution so we increment the revolutions variable. Then we calculate how long this revolution took and we will use that number to derive our speed.
/* LucidTronix bike Speedometer
 * For instructions, details and schematic, See:
 * http://www.lucidtronix.com/tutorials/13
 * Hall effect sensor on pin 16, 
 * doesn't use hardware interrupt.
 */
#include <LiquidCrystal.h>

LiquidCrystal lcd(4, 5, 0, 1, 2, 3);
String message = "Luf";

int mode = 1;
int num_modes = 2;
int cur_scroll = 0;
int cur_msg_length = 0;
int cursor_index = 0;
int char_index = 0;
int btn = 3;
int hall_pin = 16;
byte backlight_pwm = 200;
int hall_state = 1;
int revolutions = 0;
float miles_in_inches = 63360;
float mph = 0.0;
float distance = 0.0;
float tire_diameter = 26.2;
float k_ipm_2_mph;
int tire_circumference;
unsigned long last_fall = 0;
unsigned long last_interval = 0;

int backlight_pin = 9;
int cur_x = 8;
int cur_y = 1;
void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  delay(500);
  k_ipm_2_mph = 3600000 / miles_in_inches;
  tire_circumference = tire_diameter*3.14159;
  pinMode(btn, INPUT);
  pinMode(hall_pin, INPUT);
  pinMode(backlight_pin, OUTPUT);
  analogWrite(backlight_pin , backlight_pwm);
  lcd.blink();
  lcd.print("hello, world!");
  delay(1000);
}

void loop() {
  int hall_val = digitalRead(hall_pin);
  if (hall_state != hall_val && hall_val == LOW) {
    revolutions++;
    last_interval = millis()-last_fall;
    last_fall = millis();
  }
  hall_state = hall_val;
  updateSpeedAndDistance();
  
  lcd.setCursor(0, 0);
  lcd.print("Hall:" );
  lcd.print( hall_state);
  lcd.print("Mph:");
  lcd.print(mph);
  lcd.setCursor(0, 1);
  lcd.print("Miles:");
  lcd.print(distance);

  backlight_pwm = analogRead(0)/4;
  analogWrite(backlight_pin , backlight_pwm);

}

void updateSpeedAndDistance(){
  distance = tire_circumference * revolutions;
  distance /= miles_in_inches;
  float ipm = tire_circumference / (float)last_interval;
  mph = ipm * k_ipm_2_mph;
}

Parts

Title Description # Cost Link Picture
LCD HD44780 16x2 characters, White Characters Blue Backlight Value: HD44780 1 $9.95 Link Screen_shot_2012-12-28_at_7.44.53_pm
PCB Bike Kit The circuit board for the bike computer 1 $8.0 Link Screen_shot_2013-01-26_at_4.13.47_pm
ATMEGA168A-PU IC MCU AVR 16K FLASH 28PDIP Value: 16KB (8K x 16) 1.8 V ~ 5.5 V 1 $2.54 Link Screen_shot_2012-12-28_at_7.40.44_pm
Hall Effect Sensor Magnetic Hall Effect, 30mT Trip, 9.5mT Release, 3.5 V ~ 24 V Unipolar Switch, TO-92 Value: 3.5 V ~ 24 V 1 $1.08 Link 413-to-92
Potentiometer POT ROTARY, Linear 10K OHM 9MM SNAPIN Value: 10k 1 $0.76 Link Screen_shot_2012-12-28_at_7.41.04_pm
Crystal CRYSTAL 16.0 MHZ 18 PF FUND Value: 16MHz 1 $0.35 Link Screen_shot_2012-12-28_at_7.30.51_pm
Button Tactile switch SMD SPST 0.05A 12V Value: SPST 2 $0.2 Link Fsm4jsma
Transistors (BJT) - Single IC TRANS NPN SS GP 200MA TO-92 Value: 40V 300mV @ 5mA, 50mA 100 @ 10mA, 1V 1 $0.18 Link Screen_shot_2012-12-28_at_7.39.40_pm
Resistor RES 10K OHM 1/4W 5% CF MINI Value: 10k 4 $0.08 Link Screen_shot_2012-12-28_at_7.28.15_pm
Permalink: http://lucidtronix.com/tutorials/13
Viewed: 7:55AM, May 21
Viewed: 7:40AM, May 21
Viewed: 7:33AM, May 21
Viewed: 7:32AM, May 21
Viewed: 7:10AM, May 21
Viewed: 7:04AM, May 21
Viewed: 7:03AM, May 21
Viewed: 7:00AM, May 21
Viewed: 6:51AM, May 21
Viewed: 6:45AM, May 21
Viewed: 6:34AM, May 21
Viewed: 6:30AM, May 21
Viewed: 5:53AM, May 21
Go to page: 1 2 3