Arduino Bike Speedometer
Arduino Bike Speedometer
Table of Contents
Step 1: Schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Step 2: Protoboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Step 6: LCD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
http://www.instructables.com/id/Arduino-Bike-Speedometer/
Author:amandaghassaei amandaghassaei.com
Currently working for instructables!
Parts List:
Additional Materials:
22 Gauge Wire Radioshack #278-1224
Solder Radioshack #64-013
sand paper
plywood
wood glue
hot glue
screws
zip ties
sugru
Step 1: Schematic
The schematic for this project is shown above.
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!)
http://www.instructables.com/id/Arduino-Bike-Speedometer/
Step 2: Protoboard
Solder three rows of header pins on the protoboard so that the arduino will snap to it as shown in the images above.
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.
Image Notes
1. switch
2. magnet
http://www.instructables.com/id/Arduino-Bike-Speedometer/
Image Notes Image Notes
1. i made a mistake here- the black wire should be connected to A0 1. i made a mistake here- the black wire should be connected to A0
Image Notes
1. I made a mistake here- the black wire should be connected to A0
http://www.instructables.com/id/Arduino-Bike-Speedometer/
Step 4: 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.
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
*/
//storage variable
int reedVal;
void setup(){
Serial.begin(9600);
}
void loop(){
reedVal = analogRead(reed);//get val of A0
Serial.println(reedVal);
delay(10);
}
Image Notes
1. switch attached to bike frame
2. magnet attached to spoke
Image Notes
http://www.instructables.com/id/Arduino-Bike-Speedometer/
1. switch
2. magnet
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
*/
//calculations
//tire radius ~ 13.5 inches
//circumference = pi*2*r =~85 inches
//max speed of 35mph =~ 616inches/second
//max rps =~7.25
//storage variables
int reedVal;
long timer;// time between one full rotation (in ms)
float mph;
float radius = 13.5;// tire radius (in inches)
float circumference;
int maxReedCounter = 100;//min time (in ms) of one rotation (for debouncing)
int reedCounter;
void setup(){
reedCounter = maxReedCounter;
circumference = 2*3.14*radius;
pinMode(reed, INPUT);
// TIMER SETUP- the timer interrupt allows precise timed measurements of the reed switch
//for more info about configuration of arduino timers see http://arduino.cc/playground/Code/Timer1
cli();//stop interrupts
sei();//allow interrupts
//END TIMER SETUP
Serial.begin(9600);
}
void displayMPH(){
Serial.println(mph);
}
void loop(){
//print mph once a second
displayMPH();
delay(1000);
}
Step 6: 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.
http://www.instructables.com/id/Arduino-Bike-Speedometer/
Step 7: 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.
http://www.instructables.com/id/Arduino-Bike-Speedometer/
Image Notes
1. Adjust contrast
2. switches must be in this configuration to send messages to LCD
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
*/
//this code should print "Hello World" on the LCD and the backlight switch connected to digital pin 2 should work
void setup() {
Serial.begin(9600);
pinMode(1,OUTPUT);//tx
Serial.write(12);//clear
Serial.write("Hello World");
}
void loop() {
}
http://www.instructables.com/id/Arduino-Bike-Speedometer/
Step 10: 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.
Image Notes
1. to 5V
2. to ground
3. to digital pin 2
Image Notes
1. to switch
Measure the radius of your tire wheel (in inches) and insert it in the line: float radius = ''''';
//bike speedometer
//by Amanda Ghassaei 2012
//http://www.instructables.com/id/Arduino-Bike-Speedometer/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
*/
//calculations
//tire radius ~ 13.5 inches
//circumference = pi*2*r =~85 inches
//max speed of 35mph =~ 616inches/second
//max rps =~7.25
//storage variables
http://www.instructables.com/id/Arduino-Bike-Speedometer/
float radius = 13.5;// tire radius (in inches)- CHANGE THIS FOR YOUR OWN BIKE
int reedVal;
long timer = 0;// time between one full rotation (in ms)
float mph = 0.00;
float circumference;
boolean backlight;
int maxReedCounter = 100;//min time (in ms) of one rotation (for debouncing)
int reedCounter;
void setup(){
reedCounter = maxReedCounter;
circumference = 2*3.14*radius;
pinMode(1,OUTPUT);//tx
pinMode(2,OUTPUT);//backlight switch
pinMode(reed, INPUT);
checkBacklight();
Serial.write(12);//clear
// TIMER SETUP- the timer interrupt allows preceise timed measurements of the reed switch
//for mor info about configuration of arduino timers see http://arduino.cc/playground/Code/Timer1
cli();//stop interrupts
sei();//allow interrupts
//END TIMER SETUP
Serial.begin(9600);
}
void checkBacklight(){
backlight = digitalRead(2);
if (backlight){
Serial.write(17);//turn backlight on
}
else{
Serial.write(18);//turn backlight off
}
}
void displayMPH(){
Serial.write(12);//clear
Serial.write("Speed =");
Serial.write(13);//start a new line
Serial.print(mph);
Serial.write(" MPH ");
//Serial.write("0.00 MPH ");
}
void loop(){
//print mph once a second
displayMPH();
delay(1000);
checkBacklight();
}
http://www.instructables.com/id/Arduino-Bike-Speedometer/
Step 12: 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.
I glued the project enclosure together with wood glue and sanded the edges down. I finished the enclosure with some clear polycrylic.
http://www.instructables.com/id/Arduino-Bike-Speedometer/
File Downloads
enclosure.stl (1 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to 'enclosure.stl']
http://www.instructables.com/id/Arduino-Bike-Speedometer/
Step 15: 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.
http://www.instructables.com/id/Arduino-Bike-Speedometer/
Step 16: 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!
Related Instructables
Digital
Wireless Altoids Arduino Anemometer Amp up your Arduino Bicycle
Cycle Computer Skateboard (wind meter) by VW Bug Alarm and
by Alexdlp Speedometer by Arduino Timer Speedometer by Lights by
dan
leonardor Interrupts by kcrichar cheeyah
amandaghassaei
http://www.instructables.com/id/Arduino-Bike-Speedometer/