Introduction: DIY Bike Speedometer
Hello people,
I just finished my latest project: A speedometer for my bike. It uses an attiny84 chip as its main processor and an 74ls47 chip as a driver for its 7-Segment Display (7SD from now on). If you have the parts it's a project you can finish in a day. It requires simple arduino coding skills, intermediate soldering skills and some knowledge on electronics but we are going to cover everything in this instructable. The total cost of the project is around 15€.
Parts List:
- Attiny84: 2.60€
- 74ls47 or 7447 IC (If using a common cathode 7SD go with the 4511 IC): 2.20€
- Triple Digit 7-Segment Display (Common anode displays are easier to find and that's what I used but you can go with a common cathode if you buy the correct driver as mentioned above): 1.40€
- 14 pin DIP Socket: 0.06€
- 16 pin DIP Socket: 0.08€
- Magnetic Switch (This is a tricky one but you can see what I mean here): 5.00€
- 1 or more (The more the better) small neodinium magnets: 0.00 (I found mine in an old toy)
- L7805CV 5V Voltage Regulator: 0.4€
- 1uF Electrolytic Capacitor: 0.06€
- 10uF Electrolytic Capacitor: 0.05€
- 1KΩhm Resistor: 0.01€
- (OPTIONAL) 3 330Ωhm Resistors
- Mini slide switch: 0.20€
- Right angle pin headers: 0.30€
- 4 pin Female Dupont Terminal and Connector: 0.40€
- A piece of prototyping board (I used about 8x4cm): 1.5€
- Heatshrink
- TOTAL: 14.26€
Tools:
- Soldering Iron and Solder
- Drill
- Pliers
- Wire Stripper
- Cutters
- Multimeter (To test connections)
Step 1: Circuit: Power Supply
First things first. The attiny84 works just like an arduino and it needs constant 5V power supply and so does the 7447. We are going to use the L7805CV Voltage Regulator the two capacitors and the switch. The schematic is pretty straight forward: You connect the ground of the two capacitors to the ground pin of the regulator, the positive side of the 10uF to the input and the positive side of the 1uF to the output. Now the 9V supply from battery is going to come through a connector so now its a good time to start soldering. On one side of your prototyping board you want to fit as many things as possible. Solder your regulator after bending its pins in the middle of the board in order to fit it without the heatshink sticking out. Solder the two capacitors in front of it. Leave some space for the switch too. Solder 4 right-angle headers on the top of your circuit. These will provide power and signal from the sensor that will go on your bike. It is important to decide now and remember which pin is used for what. The pin that you chose that is used for positive side of your battery is connected to the middle pin of your switch and one of the edge pins of the switch go to the input of the voltage regulator. The pin you chose for the negative end of the battery goes to the ground pin of the regulator and your power supply is done.
Step 2: Circuit: Display
On the other side of the board you will want to solder your 7SD leaving some space above for a hole. Next to it solder the 16 pin DIP socket for the 74ls47 or 7447 IC. Connecting the sockets pins is the same as connecting the ICs pins but you can remove the IC anytime. The IC is going to face up so the pins that connect to the 7SD are next to it. Now connect the a,b,c... pins of the display to the corresponding pins on the IC. Remember that the pin order gets mirrored when you flip the board as you are looking at it from behind. Connect pin 16 of the 74ls47/7447 to the output of the regulator and pin 8 to ground. If you are working with a common cathode 7SD you may want to see how it is connected to the appropriate IC (4511) here. It's pretty much the same.
Image sources:
Step 3: Circuit: Attiny
The attiny84 is a board that works just like an Arduino but it has fewer pins and it costs WAY less. I will explain how you connect it right away but first you might want to see how to program it using an Arduino UNO as an ISP here (use 8MHz instead of 1MHz as shown in the tutorial). Solder the remaining socket for the attiny between the power supply and the 7447. The attiny is going to be installed face up too so the first of its pins are near the 7447s inputs. Connect the pins a,b,c and d (actual pins 7, 1, 2, 6) from the 7447 to digital pins 0,1,2 and 3 (actual pins 13, 12, 11 and 10) of the attiny and pins 1 and 14 output and ground of the regulator respectively. Next you need to connect the anode pins of the 7SD to the attiny as shown on the diagram. Connect the pins that correspond to anodes 1, 2 and 3 of the 7SD as shown on the diagram to digital pins 4, 5 and 6 of the attiny (actual pins 9, 8 and 7). Last thing for the display is to connect the dp pin of the 7SD to digital pin 7 of the attiny (actual pin 6).
Image sources:
Step 4: Circuit: Sensor
The sensor is not going to be directly connected to the circuit but through the remaining 2 pins on the header you shouldered on the first step. Again choose the pin used for power and for signal. The connection here is a bit tricky so I'm providing a schematic. You basically connect the power pin to the output of the voltage regulator and the signal pin to digital pin 8 of the attiny84 (actual pin 5). You also connect the signal pin to ground with the 1KΩhm resistor. Have a look at the schematic it makes more sense. The connection is similar to the connection of a button to the Arduino as explained on this Arduino tutorial.
Step 5: Cable
I made a pretty messy cable to connect the sensor and the battery to the board but this helped me with cable management on the bike. First you need to make the dupont cables. Follow the instructions here. First connect the 9V battery holder and attach it to the right position on the dupont connector. Remember your connections on the header and plan the cable that will fit there. You want the + and - side of the battery to appropriately go to the INPUT and GROUND of the regulator. Next connect two small wires to the remaining connectors. You will later use them to connect the sensor. Don't forget to secure everything with electrical tape and heat shrink.
Step 6: Sensor
First of all find a nice spot on your bike, near the front or back wheel where you can attach the sensor. Screw the magnetic switch to a nice, small, flat piece of wood and secure it next to the wheel. You want it to be as close to the spokes as possible without touching them. Manage your cables and secure the sensor firmly so nothing interferes with the bikes mechanics. Now you need to attach the small, neodymium magnets on the bikes spokes. If you choose to go with only one you can place it wherever you like but if you want to go with more for better accuracy be sure that the angle between every magnet is equal. For example, if you go with two like I did place them on the bikes diameter. You want your magnets to be in the appropriate distance from the wheel's center to trigger the switch. Move the wheel around and find the right position. You might also want to move your sensor further away from the wheel's spokes to be out of the magnets way when the wheel spins but not too far away for the switch to get triggered. See the pictures on how I did it.
Step 7: Putting Everything Together
When you have your sensor installed you want to connect it to the cable you made on a previous step. Use as much wire as you need to connect the output of the switch and the two small wires you left unconnected on your wire. Secure everything with zip ties on your bike, use electrical tape and heatshrink to insulate your connections and be sure that nothing interferes with the bikes mechanism.
Step 8: Coding
I'm providing the full code for your speedometer to work. Use the tutorial mentioned in a previous step to program your attiny84 and don't forget to burn the bootloader before first use. I will keep the code updated with fixes and recommendations!
**Skip this if you don't care about the physics**
The speed is calculated using the formula for uniform circular motion. The rotational speed ω is calculated by dividing 2π by the duration of a full circle. A full circle is 360 degrees or 2π rad so dividing 2π by T, the duration of one full circle, with get the rotational speed of the wheel. The rotational speed of the wheel can be measured on any point on the radius of the wheel because it spins with the same speed as a solid object. Although the linear speed (u) is different on any point on the radius of the wheel is different. We know that the perimeter of a circle is calculated by multiplying the radius (R) of the circle with 2π. If we divide this by T we get the linear speed of the wheel and therefore of the bike. So we get the formula u=(2*π*R)/T that can be transformed to u=ω*R. So by knowing the time it takes for a whole circle we can calculate the speed of the bike. Know if you use more than one magnet the sensor signals not every full circle but every half or third or quarter circle. So we measure T/2 or T/3 or T/4 making the measurement more reliable. The formula is corrected to u=ω*R*(number of magnets).
If you want any more explanation on the code ask in the comments.
The code is provided under Attribution-NonCommercial-NoDerivatives 4.0 International Licence.
Attachments
Step 9: Done.
You are basically done with this project. Go ahead and make a small hole on the right upper corner of your speedometer. When you attach it to your bike on the cable you made, use a zip tie to secure it on the bikes steering wheel in order to keep your cable unstressed. This allows you to remove your speedometer from your bike to fix it and flash it with updates!

Participated in the
Maker Olympics Contest 2016
16 Comments
2 years ago
Is it possible to use a Hall sender instead a magnetic sender?
Thanks!
Reply 2 years ago
Sure, it might even be a more accurate option!
Reply 2 years ago
Thank you
I will use a Mini Arduino Pro instead of a Attiny84.
I will update you!
Question 3 years ago on Step 9
Which senser use
Question 3 years ago on Step 3
Hello, thanks for sharing. Im having trouble programming attiny84. I followed instructions from the link you shared, and when I tried to upload your sketch I got a ton of avrdude messages about program not responding. Im wondering if the jumper wires to the breadboard need to be any different from how it was shown for the example blink sketch. any help would be appreciated.
Answer 3 years ago
Hi thanks for reaching out. It's very nice to see people still engaging 4 years after I posted this instructable!
Programming the attiny84 and attiny85 is still a pain for me to this day. The Arduino IDE libraries for the attiny have changed so be sure to use the latest versions. It's also important to boot the chip into programming mode which is done by grounding certain pins. You will find more luck searching for how to program the more popular attiny85 instead of the 84, the method is similar.
If you could send me the errors you are getting on the IDE maybe I can be of more help.
Reply 3 years ago
Thanks for such a quick reply!
"avrdude: stk500_getsync(): not in sync: resp=0x00"
I've since changed the programmer to "Arduino as ISP" Before I had left it on "AVR ISP"
After changing that it finished uploading with no errors. I haven't even tested a blink sketch to see that it actually is programming the attiny so... I'll be sure to let you know if it works.
4 years ago on Introduction
you have full circuit diagram?
Reply 4 years ago
Unfortunately I do not, I made this instructable a long time ago. The provided schematics provide almost a complete diagram. With basic knowledge of electronics and a bit of tinkering arround following them carefully will do the trick. Let me know specifically where you need help!
5 years ago
Any help in modifying the code for race car speedo, where the decimals aren't needed. Just 3 digit number for speeds up to 310kph? I've been studying the code for 2 evenings now and my head just doesn't bend to understand what to remove and change from the code to get rid of the decimal data stored for velocity. I'm pretty sure that velocity has wrong data type for my application, but don't know how to make the code work when i change velocity data from double to ex. long. Pls help.
Reply 4 years ago
I'm very sorry for the delayed reply, I have been inactive for a while. I wrote that code a long time ago so I had to take a look and that's what I came up. My code uses the function shutter to return the digits of the number that you want to print. What it does is it multiplies the number by ten (ex. 14.5 -> 145) and returns the 1st, 2nd, 3rd digit depending on the attribute y. When you feed it a 3 digit number like 145 it will turn it into 1450 and will return 4, 5 and 0 instead of 1, 4, 5. What i think will solve your problem is deleting or commenting out the line in the function that multiplies x by 10 (I actually quickly tested this in Python and it works so you should be ok). Then to remove the dot from the display just don't connect the pin of the 7 segment to power!
5 years ago
sir can you give the circuit diagram of the whole project as such it would be really helpfull
7 years ago
This would be really fun to have on a bike. I have always wondered how fast I am going on my bike.
Reply 6 years ago
Have a look at this
https://www.instructables.com/id/Arduino-Bike-Speed...
7 years ago
I'll bet with a little code modification this may make for a good machine tool r.p.m. display, something very handy to know on a lathe, mill, or drill press.
Reply 7 years ago
Basically remove the part of the code that calculates the speed. Just place the sensor far away from the center. A problem I had was the sensor not being able to catch the magnet due to the high speed.