Arduino Hall Effect Bike Speedometer and Odometer

by The Plain Plane in Circuits > Arduino

1142 Views, 13 Favorites, 0 Comments

Arduino Hall Effect Bike Speedometer and Odometer

MOV_0168.JPG
MOV_0162.JPG
MOV_0163.JPG

In this Instructable we'll make a speedometer for a bike that uses a magnet and a hall effect sensor. I embarked on this project because I was always curious how fast I was traveling and how far I had travelled while I was riding my bike; to help solve this issue I previously used an app called Beacon however I wanted to know my speed and distance in real time rather than finding out after I had finished riding.

This speedometer uses a magnet attached to the bikes wheel so that when you make it move a hall effect sensor detects the magnet and sends signals to an Arduino which can then calculate the bikes speed and distance travelled, sending this information to an LCD display.

This is different to the more conventional GPS speedometers commonly used for bikes, I opted for a different approach because it provides a more 'mechanical' way of gathering speed that can be used anywhere from dense forests to cities, places where GPS speedometers don't work as efficiently. GPS modules are also more expensive and don't account for small bumps and slight path deviations which add-up over a long bike ride, especially in urban areas.

Supplies

MOV_0111.JPG
MOV_0148.JPG
MOV_0113.JPG
MOV_0110.JPG

Since I live in Australia, I purchased most of my stuff from Altronic's, these parts are:

  1. 2.2" TFT screen that uses the ILI9225 chip and has 176 x 220 resolution
  2. 44E hall effect sensor module:
  3. A reed switch could also be used instead
  4. 2 x 2 position switches
  5. Arduino nano
  6. 2 x 40mm+ m4 bolts + nuts
  7. 4 x 30mm+ m3 bolts + nuts
  8. 6 x 25mm+ m3 bolts + nuts
  9. 2 x m2 bolts + nuts
  10. A magnet from a small Arlec light or a magnet with a diameter of approximately 17.8mm and height of 2mm


I also recommend:

  1. Male and female servo connecters
  2. A long servo extension
  3. Small wire and heat shrink
  4. A power source between 5-12V (I used an Eneloop pack with 5 AA batteries)


The tools required are:

  1. A relatively accurate 3d printer
  2. Suitable screwdrivers
  3. Soldering iron (may also need a heat gun or open flame if using heat shrink tubing)

Soldering the Arduino Nano

MOV_0119.JPG
MOV_0116.JPG
MOV_0120.JPG
MOV_0117.JPG
MOV_0118.JPG

Firstly, we have to connect the screen to the Arduino nano. To do this I decided to directly solder some small gauge wire to the pins of the screen and used some heat shrink to ensure the pins or wires won't bend and touch together. The recommended pin connections are as follows:


  1. CS goes to A5
  2. RST goes to A4
  3. CD goes to A3
  4. LED goes to A0
  5. SDI goes to digital 11
  6. CLK goes to digital 13


  1. The NC pins have no control over the screen, they are only there to make it easier to attach to an Ardunio uno.


#Note:

You can change these pin attachments and adjust the code to suite the pins you used however these pins are recommended for faster screen refresh rates.


Secondly, we can solder the 'statistics' switch onto the Arduino. One of the outside pins of the switch can go to ground and the middle pin can go to any available digital pin, I opted for digital pin 5, remember to change this pin designation in the code if you attach it to a different pin.

Now, we can solder one of the on/off switches outside pins to the Vin pin of the Arduino. The middle pin of this switch can be connected to the positive side of a battery connection lead, here I used a female servo plug but an xt30 or xt60 connecter would be just as good.


Now, we can gather all of the 5V wires together, which includes:

  1. The screens 5V input
  2. The hall sensors 5V input (positive wire of a male servo lead)

and solder them to the 5V pin of the Arduino.


Then we can do the same for all of the ground connections except these go to the ground pin of the Arduino and include:

  1. The screens ground
  2. Hall sensors ground (negative wire of the male servo lead)
  3. Ground of the battery connection lead (negative wire of the batteries female servo lead)


Lastly, we can connect the hall sensor output wire (Signal wire of the servo lead) to the A2 pin of the Arduino. A digital pin should also be fine with a bit of tweaking in the code however I had some issues with my hall effect sensor not giving proper digital outputs, so I opted for an analogue connection instead.

Uploading the Code

MOV_0129.JPG
MOV_0131.JPG
MOV_0130.JPG

We now have to download 2 libraries LCDWIKI_GUI and LCDWIKI_SPI, unfortunately I could not attach the files here, but you can find these on the 2.2inch Arduino SPI Module ILI9225 SKU:MAR2201 - LCD wiki. You will have to go to the program download menu then download the file. Once downloaded open the file and navigate to:

1-Demo then Demo_Arduino then Install_Libaries

Uncompress the LCDWIKI_GUI and LCDWIKI_SPI files into the libraries folder of your Arduino directory.

Once you connect the nano to your computer you can open the BikeSpeedometerV5 code attached here and upload it to your nano, if this returns an error it may be because the libraries were installed incorrectly or were accidently put into the wrong file. The LCD Wiki page also has some good instructions on how to do this if you are stuck.

Remember to check all the pins in the code are the same as the ones which you used and remember to change the bike wheel radius to suite your bike wheel otherwise the values won't be accurate.

Constructing the Case

MOV_0122.JPG
MOV_0123.JPG
MOV_0126.JPG
MOV_0127.JPG
MOV_0128.JPG
MOV_0133.JPG
MOV_0135.JPG
MOV_0136.JPG
MOV_0138.JPG
MOV_0137.JPG

I have attached all the 3mf files which I have made under each separate section, and they will all have to be 3d printed. I used a 0.4mm nozzle with 0.24mm layer height, and a 2-layer wall count. I printed all of the parts with Overture PLA.

Once printed we can start assembling all the components. To do this we start with the gasket part, light blue, and feed the Arduino through the rectangular hole such that the screen will sit nicely above it and the SD card holder fits within the open cutout. Then we can fit the switches into the rectangular holes on the side.

Now we can fit the topmost part over the screen and switches such that it holds everything down, after we do this, we can squeeze the Arduino into the cavity in the base of the component making sure to feed the battery and hall sensor connecters through the hole in the bottom. Then we can put the m3 x 30mm bolts through the 4 holes and tighten them down.

Attaching the Case to the Bike

MOV_0139.JPG
MOV_0140.JPG
MOV_0141.JPG
MOV_0142.JPG

The bike Speedometer case should press fit onto the thickest part of the handlebars however this is not the case for all handlebars and a spacer may be required to get the optimum fit, you can adjust it to you desired angle at this stage. Use the bottom bracket and tighten the 2 m4 x 40mm bolts and nuts to lock the Speedometer into position on the handlebars.

Attaching the Magnet

MOV_0143.JPG
MOV_0144.JPG
MOV_0145.JPG
MOV_0146.JPG
MOV_0147.JPG

I got this magnet from an old Arlec light, if you use a different magnet you may have to adjust the size of the hole and or use glue. The magnet is encased in 2 metal plates and when I removed the magnet the top metal plate came off, but the bottom didn't. This left a magnet that was sitting in a metal dish, this is what I put inside the plastic case.

The hall effect sensor only works with a certain magnet pole. Due to this I recommend holding the magnet close to the sensor when it's powered on and flip the magnet around until the light turns red, mark whichever side makes the hall effect sensor's light turn red. Insert the magnet into the middle hole of the plastic case such that the marked side is facing the thin plastic shell (away from you).

Now align the grooves in the plastic case with the spokes of your wheel and face the plastic shell with the magnet towards the outside of the spokes, tighten down both sides of this component using 2 m3 bolts and nuts.

Downloads

Attaching the Hall Effect Sesnor

MOV_0148.JPG
MOV_0149.JPG
MOV_0150.JPG
MOV_0151.JPG
MOV_0153.JPG
MOV_0154.JPG

Bolt the hall effect sensor onto the slider (the long thin part with a large rectangular cutout) using m2 bolts and spacers if necessary. Bend the small black component such that the flat side is perpendicular to the end of the slider, this ensures the best magnet detection.

Bolt both sides of the clamps to the wheel fork with m3 x 25mm bolts, when doing this you should place the slider on the clamp with the rail and adjust the height of the clamp so that the hall effect sensor is vertically aligned with the magnet. Also try to make sure it is as perpendicular to the wheel as possible.

You can push or pull the rail until you achieve a suitable distance between the magnet and the hall effect sensor and use an m3 x 25mm bolt to clamp down the rail. I left 2 positions to bolt the rail on however I could only use one as the other was obscured by the hall effect sensor. Try to leave a minimal gap as possible with only a very slight distance apart so that the magnet holder doesn't hit the hall effect sensor when you're riding.

Connecting the Wiring and Battery

MOV_0155.JPG
MOV_0156.JPG
MOV_0157.JPG
MOV_0158.JPG

A male servo connecter matches up perfectly with the hall sensor's pins, I used a long servo connecter that barely just fit between the hall sensor and the female hall sensor connecter that leads to the Arduino. For this stage I'd recommend a longer servo lead and zip tie it to the bike frame, so it doesn't flop around and get caught in the bike tire.

To power the speedometer, I used a battery pack I had laying around that essentially has 5 AA batteries. So far, I have zip tied this pack to the handlebars until I find a more permanent location. A pack of 4-6 AA's or AAA's would be sufficient to power the Arduino or you could use any other power source you desire as long as it has between 5-12V output, such as a 9v battery.

Using the Speedometer

MOV_0163.JPG
MOV_0161.JPG
MOV_0159.JPG

The moment the Arduino is supplied with power, and you flick the power switch it should start up and start recording. You can double check that everything is working by keeping the magnet over the hall sensor. This should turn the digits red, and they will hover around the 15-20 mark. This indicates that the speedometer thinks the magnet is stuck near the sensor showing it is properly receiving and computing signals from the sensor. If the hall sensor has power but its red light does not turn on when the magnet passes over it is likely too far away, or the wrong side of the magnet is facing the sensor, or the sensor pin has a faulty connection.

When the Statistics switch is flipped the screen should clear then display all of the data it has collected. If the speeds or distance values are incorrect it could be because of a faulty hall effect sensor, or an incorrect wheel size is used in the code.

Making It Move

MOV_0167.JPG

Now you have a speedometer that measures your bikes speed in a different way to the conventional GPS ones. It is now time to make it move and take your bike out for a spin. During low speeds (below 10km/h) the screen should update every time the moving magnet passes over the sensor, above 10km/h the screen takes too long to refresh so the code waits for the magnet to pass the sensor then it calculates the speed.

So far I have used this speedometer a couple of times on my 9km bike rides, it consistently under predicts my distance by about 300m compared to the GPS however the speed values seem to be pretty accurate. This is most likely due to me being lazy and not updating my wheel radius in the code however I'm quite happy with, so I'll leave it as is!

I hope you have enjoyed this Instructable and if you have any questions or queries, I will be more than happy to help out! Make sure to comment if you've made this and if you have any suggestions or improvements, I'll be happy to update my project, Thanks!