Go Down

Topic: speedometer (Read 2222 times) previous topic - next topic


so im trying to make a speedometer for an gokart whith lcd is it posible to use an optical encoder and if so do enyone have a toutorial?

its going to run on an arduino mega 2560


Jul 09, 2013, 10:56 pm Last Edit: Jul 09, 2013, 11:00 pm by DVDdoug Reason: 1
That should be possible.

There is an LCD Library, although if you use a different LCD you may have to interface it differently.

There are timing functions (millis() & micros()), so if you know how many pulses you get from your encoder over a known distance you can count the pulses per second (or over some other time period) and calculate speed.    You could also write a calibration sketch that counts the pulses over a pre-measured distance.


I went thru a similar exercise for my vintage racecar.
I had encoder counts froma gearbox transducer (GM, $10 on ebay), then to calibrate it to mph, I decided to use my GPS iphone speed app.
Then I decided to forget the encoder and just use iphone GPS directly.
Then I realized that the iphone GPS update rate is too slow and the display is not bright enough for sunshine use (I wanted to capture the speed with my GoPro camera).
So I hooked up an arduino 328  with a GPS shield and a downloaded GPS library. To my astonishment it worked immediately.
Then I made a large, bright 3x7 segment display, using I2C and eventually it worked.
So my first race weekend I occasionally had a speed readout.  Sadly I did not need 3 digits, 2 would have been enough, 91 mph was all I could get out of my MGA at Laguna Seca.
Now I need to fix reliability and change the update rate to 10/s.
Perhaps a nitrous bottle would be nice also !
Happy to provide more detail.


I am currently doing the same thing. The way mine works is I have a magnet on a wheel and a hall effect sensor within range of the magnet, when the magnet passes the hall effect sensor it triggeres an interupt which records the time it happened (millis), the second time this happens the second time is recorded, the interupt is disabled, the time difference is calculated in void loop() when it gets the chance, 60000 is divided by the time difference to get the rph (revolutions per hour) of the wheel, times that by the circumference of the wheel in miles to get the mph. This could work with other sensors like a photointerrupter or something but I would think that they would be quite vulnerable to dirt and other debris in a gocarting enviroment.

Here is the code for calculating MPH and KPH
Code: [Select]
volatile long pulse1 = 0;
volatile long pulse2 = 0;
volatile byte speedReadingCount = 0;
int rpm;
int mph;
int kph;

void pulse_detect(){
  pulse2 = pulse1;
  pulse1 = millis(); //record latest interrupt time
  speedReadingCount++; //increase the reading counter
  if(speedReadingCount == 2){ //if 2 readings have been made...
    detachInterrupt(0); //detach interrupt

void setup(){
attachInterrupt(0, pulse_detect, FALLING); //attach interupt on the falling edge on digital pin 2 (for uno and mega)

void loop(){
  //mph calculation
  if(speedReadingCount == 2){ //if the 2 times have been recorded...
    pulsetime = pulse1 - pulse2; //calculate the time between pulses
      rpm = 60000 / pulsetime; //RPM = 60000 / time between pulses
      mph = ((rpm * 60) * wheelCir); //Speed = the RPH of the front wheel times the wheel circumference in miles
      kph = (mph / 0.62137); //convert to kph
    speedReadingCount = 0; //reset the reading counter
    attachInterrupt(0, pulse_detect, FALLING); //re-attach the interrupt

  if ((millis() - pulse1) >= 2000){ //If a pulse is not registered for 2 second / 2000ms it is assumed that the wheel is not moving
    mph = 0;
    speedReadingCount = 0;


This project might be of some help...


Go Up