car mileage (odometer)

@alamirah93

I am working on a trip computer at the moment, I mean, I have been working on it for almost a year now.

Even the most modern cars usually have some kind of speed sensor or transducer installed at the transmission somewhere, which generates a symmetric square wave, which the car's electronics then use to calculate the car's speed. In the end, this is also how a digital odometer works which is found in most cars from about the late 1990s onwards. It just counts the pulses and knows what distance you have traveled after a given number of pulses.

This is how I worked out the precise speed of my car in relation to the speed sensor pulses:

Get an oscilloscope or logic analyzer and connect it to the car's speed sensor at the transmission (remember to step down the voltage if your scope/analyzer doesn't tolerate 12V). Then either put the car on a car lift, or take it out on the road, and make an Excel table of the speed shown on the speedometer in one column and the pulse length of the speed signal in the second column at a particular speed. For added accuracy, maybe use a GPS app instead for the vehicle speed readings.

Do this at a few different speeds. Just to be sure. Maybe 10, 20, 50, 80, 120 kph. Collect your data. Then try to calculate a linear equation from your data (there are online tools for this). This linear equation will later become part of your Arduino code and tell you how fast you are going at different pulse intervals. Or if you are really only interested in the distance you have traveled, do a rudimentary Arduino sketch on an Arduino Uno-type board (the best choice for beginners) that just counts up the number of pulses. Then compare that to your distance reading from your GPS app. And form a linear equation from that.

You could still keep your system variable and flexible; in the end, from one type of car to the next, you would only have to work out new equations for your odometer calculations. The rest should always be the same.