I don't have a writeup, but I do have some old code. Be prepared for a STEEP learning curve if you're new to electronics. I'll be happy to help along the way, so please post here in this thread as you run into issues or have additional questions. Expect this process to take several months.
- Grab yourself an Arduino. Uno is a fantastic starter model, but you'll probably want to use a Nano once you're ready to do it for real. An LCD screen output will also be necessary in order for you to track values while you're working. A small stepper motor will also be needed to move the needle, but this will be one of the last things you do.
- Break the problem down into solvable chunks. Computers and electronic devices are inherently stupid. They only do what you tell them to do, so it's up to you to figure out how to accomplish your goals. This is generally the part that represents the initial hurdle to folks new to computers and electronics. In this case, you have two main problems:
- Calculate your speed
- Translate that value into an angle for your gauge needle
We're going to focus on step 2.1 at this point and revisit other items as and when necessary.
The first thing we need to do when tackling how to calculate speed is figure out what that means at a very basic level. Think high school science/physics classes. The calculation for speed is based on time and distance. Speed x Time = Distance, so the algebra tells us that Speed = Distance / Time. So we need to figure out distance and we need to figure out time. There are several ways of figuring this out, but the simplest to implement for this problem will be to start with a known distance (e.g. the diameter of your front wheel) and then measure how long it takes to complete one rotation. The measuring of the rotation can also be handled in many ways, but the simplest would be to use a magnet to trigger either a Hall Effect sensor or a reed switch. A Hall Effect sensor is an Integrated Circuit (IC) that sends a signal when it detects a magnet passing in close proximity. A reed switch is also triggered by a magnet, but it just allows the flow of current through it when the magnet is near enough. Reed switches are slower and less accurate than Hall Effect sensors, but also cheaper and (in my opinion) easier to use/understand. My recommendation is the reed switch for this application.
So there's the theory behind our first step. What's that look like in the real world? Well time to start on figuring out the Arduino. This is a great place to start:
https://www.circuito.io/blog/arduino-uno-pinout/
For our purposes, we only care about the digital pins. This is because we're waiting for the magnet to pass by the sensor and it's either passed by the sensor or it hasn't. A yes/no question means digital.
Now to figure out what that looks like for the hardware. We have several methods of determining a digital signal, but the core of the issue is are we waiting until a digital signal goes from high to low or from low to high. 0 to 1 or 1 to 0 if you prefer binary. Either method is appropriate, but we're going to be going from 1 to 0 because it's generally easier for us to detect a clean signal going from high to low than it is from low to high (at least with a reed switch). If we were using a Hall Effect we might be inclined to go with the opposite approach.
The basic hardware setup now looks like the Arduino, hooked up to power, and with a wire going from a digital pin through the reed switch, and then back to ground.
Code time!
I'm going to be intentionally vague here so that you can do a bit of research and see how you might be able to find solutions in the future.
- Configure your digital pin to enter pullup mode. This forces the pin to read a HIGH state until it's intentionally grounded. This prevents "noise" on the circuit that would otherwise give us false readings.
- Start a loop that will run continuously.
- Inside the loop, first record the system time and preserve that value.
- Create a second loop, inside the first. The loop should continue until one of the two following things occurs: We get a LOW signal on our digital pin or too much time has elapsed. "Too much" is going to be a judgement call. Using a large number means your speedometer will be less responsive at low speeds. Using a small number means the speedo won't work at all under a certain speed. You may need to test a few different values to find out what works best, but I recommend starting at two seconds and seeing how it goes.
- When the digital pin is triggered, it's time to do some math. Subtract your starting time from your current time to get the time difference. Divide the circumference of your wheel by the elapsed time to get your speed. More math will be required to convert the speed wheel speed to MPH or KPH.
At this point, you will hopefully have a useful value and you should look into outputting that value to your LCD screen so that you can see how close you are to where you want to me.