Car electronic speedometer

Hi,
I wish to replace the drive electronics for an older Toyota speedo (early 1990’s).
The micro driving the stepper motor has failed.The micro was driven by an inductive 2 wire
speed sensor mounted on the gearbox. These speedometers are no longer avaliable
I was thinking of using an Arduino to drive the stepper (lots of info to do this on the net) however
i cannot find info on connecting the sensor to the Arduino (ie how to clean up the sine wave to make
square waves and code to make the arduino act as a frequency counter to count the varying frequency square waves,which are directly related to speed).
I can find info on driving a small stepper motor and using an Arduino as a frequency counter
but not both at the same time.
I realise that the output level of the sensor will drop with speed.
Any info greatly accepted.
Cheers
George

Hi George,
I think for something like this it’s best to keep it modular and focus on a different challenge. Before we go on though I assume that this vehicle isn’t for road use?

Anyway, You’ll need to provide some more information on the type of signals you’re dealing with. Let’s focus on the frequency counting for now. I’m assuming that the sine wave uses 0V as a reference and has both positive and negative halves of the waveform. Now if you’re dealing with a low voltage (0-30V) signal we can process this quite easily. An Arduino generally is only rated for 5V so you’ll need to step the voltage down. Perhaps a simple voltage divider could do the job. Then the issue is with the negative voltage of the waveform. The way I see it you have two choices (as far as easy applications go):

  1. Create a DC reference voltage that is equal to the peak voltage of your waveform. This will allow you to use a high value (in the M-Ohms range) resistor to bias the signal so it’s only ever a positive voltage. Then provided the entire waveform is below 5V, you can read the values with an analogue input on your Arduino, and count the frequency.

  2. Take a similar approach to mains voltage regulation using a half-wave rectifier. Essentially you’re just using a diode (which only allows current to flow one way) to ‘block’ the negative half of the waveform. This will give you the top half of the waveform, followed by a low voltage for the time equal to half the signal frequency. You can then use an analogue input on your Arduino to count the frequency.

I think that the second option is better as it is far simpler, and will require less components. Bear in mind you’ll still need a voltage divider or some way to decrease the signal voltage if it’s above 5V.

As far as counting the frequency goes, I won’t go into the code specifics but if you’re using the second method I suggested, you’re going to want to measure the input of your analogue pin and increment a variable each time to pin rises above a certain level (the positive half of the sine wave).

1 Like

And as far as using stepper motors goes, check out some of our great tutorials on Arduino for using those types of motors.

Hi,
Thanks for your detailed reply.
I have worked out how to attenuate and square up the incoming wave from the sensor and drive Arduino.
I looked at many arduino sites but cannot find code that will allow me to drive a stepper motor and
count frequency at the same time. (just started trying to write code so impossible for me).
Cheers
George

Hi George, it might be worth finding some slightly less involved examples to learn more about Arduino and C before tackling this project. With that in mind, here is a bit of an idea of how something like this would work. It’s missing some key parts of the program, however you could use a pin change interrupt which will trigger everytime the attached pin changes from logic HIGH to logic LOW:

void pinChangeISR() {
sensorTime = millis() - sensorTime;
if(analogRead(pin) == HIGH) {
pulseState = 1;
}
else {
pulseState = 0;
}
}

This will log the time it changes as a variable (make sure the variable is volatile to allow for changes inside the ISR. Then you read whether it’s a HIGH or LOW change, set a variable accordingly. Then in your main loop you can use the times to work out the frequency of your squarewave, use that in some way, and there’s a great article up on our site for using stepper motors.

Thanks for the help Sam

Not a problem George, hope that goes a way to getting you on track :slight_smile: