Posted on

DIY Arduino-Based Bike Computer

The inspiration for this project came from trying to repair the bike computer that I had originally. I lost the base for it, and figured I could print a new base, and given that there were only 2 contact points for the magnetic sensor, I figured that it had to be a reed switch.
So I held the 2 leads of a reed switch to the 2 contact points, while moving it over a magnet, and sure enough, my assumption was correct. At this point, I knew what I had to do to fix the bike computer I had now, but there were still a few things I didn’t like about it – current speed was not available, and it had too many other metrics that I don’t care about.
The only logical solution was to build my own custom bike computer. Breadboarding the circuit with an Arduino, an OLED, and a reed swith connected to an external interrupt capable pin (D2 or D3 on the Uno, Nano) of the Arduino was simple. Figuring out the proper calculation to get from number of rotations per millisecond to kilometers per hour was a little trickier than expected. I did easily find one online, but wanted to see if I could come up with the same result.

With the basic circuit and programming complete, I started to design an enclosure for it in Fusion 360. The enclosure mounts to the bike through a separate piece which is zip-tied to the handlebars. The reed switch is will be permanently mounted to the bike (again with zip ties) to the fork. To connect the permanently mounted reed switch and the removable Arduino parts, I used an XT-60 connector. It’s only electrical purpose is to pass the signal from the reed switch to the Arduino, but it also holds the removable part in place. I could have accomplished the same thing with some dupont-style 2.54mm pin headers and designed a clip on to the model, but I went the route of XT-60 connectors because I felt it was easier.

In the removable part of the bike computer, I had to fit an Arduino nano, an OLED, a sliding power switch, 4 push buttons for menu navigation, the XT-60 connector, as well as a li-ion battery, a TP4056 charge and protection board, and a 5V boost converter. It was a tight fit, but I managed to get everything in.

The battery I used for this build is not the typical 18650 that I have in so many other projects, as that would have required the enclosure to be a lot bigger. For this project, I took a cell from an old cell phone that I got from an electronics recycling, removed the plastic casing and protection circuit, tested the voltage (it was around 2.7V), and charged it up. The cell was rated at 895mAh, and the TP4056 modules are pre-set to charge at 1A, which would be just over 1C for this cell, I decided to change the charging resistor on the TP4056 board. I could have done this with a soldering iron and a fine tip, but given that I recently got a hot air rework station, I figured now would be a good time to use it. Typically, Li-ion cells can be charged at 1C, but given that this cell was used and sitting at under 3V for a few years, I decided to go for a 0.5C (roughly 500ma) charge rate.

The appropriate resistor for that would be around 2.5K ohm, but the closest bigger resistor that I had was 3.3K, which worked out to roughly a 350mA charge rate. I replaced the resistor, and charged it up without issue. The battery got connected directly to the BAT+ and BAT- pads of the TP4056 module. The OUT+ of the TP4056 gets connected to one side of the power switch, while the other side is connected to IN+ of the boost converter. OUT- of the TP4056 is connected directly to IN- of the boost converter. The boost converter output was originally a USB type A port, which I removed, and soldered wires directly to the 5V and GND pads on the PCB (the outer 2 pins of the USB connector). They are not labelled, but the GND pad is directly connected to IN-, so I got my multimeter out to check continuity. Once I had that figured out, I connected the wires to 5V and GND on the Arduino. All the buttons got connected one side to GND and the other side to a digital pin, declared as INPUT_PULLUP in the code.

It was a very tight fit getting the Arduino into the enclosure. While putting it in the first time, I dislodged one of the SMD capacitors on the back of the board. I soldered it back without issue, but then it would not accept uploading a program to it. Most likely, I also damaged some of the traces going to the capacitor, but I’m not sure. I replaced the Arduino, and got everything properly mounted in the enclosure. I soldered the OLED to the Arduino before screwing it in to the enclosure with 4 M3 screws. Then the Nano went it next, secured with friction for now. I put the XT-60 connectors in both parts of the mount, and secured them with two-component adhesive, which I also used to secure the Arduino at this point, and the power switch. After soldering the 4 push buttons for menu navigation to the Arduino, they got glued in with a generous amount of hot glue. The TP4056 module went in directly on top of the Arduino, the boost converter slid in behind the switches, and the battery fit over top of everything. I’m sure I could have made the wiring more elegant, but it would have taken much more time.

Overall, this accomplished exactly what I wanted it to do – get me information on current speed, and distance travelled while riding my bike. I also added in some functionality to track trips, and save up to 10 of them in EEPROM memory.

 

Project By: Micah Black

Written By: Micah Black

Leave a Reply