Go Down

Topic: Cheap DIY Speedometer (Read 2 times) previous topic - next topic


I needed to know the specific speed of a device I am working with, and didn't have a speedometer handy. I couldn't find any examples of this online, but I tested it.... and it worked great! So, if anyone is in need of a cheap speedometer, I figured I could offer some advice.

*Low torque bipolar steppermotor
*Arduino + some jumper cables
*1k ohm resistor

Basically, for those who don't know a 4 wire bipolar stepper motor has 2 internal coils: A-C and B-D. What I did was send the 5V pin from the arduino into the A, and then read the signal from the B. As the motor spins, it breaks the signal and I can count those breaks. You will need to run the resistor from your return signal line to the ground, to get a good reading.

Code wise, it is really basic, well I guess the whole system is! But I needed to send the data over to a Processing program that captured the data and exported it so I could graph it in Excel. You'll see below, it isn't too special, it would be wise to modify it heavily for your specific application. I wanted to take multiple samples of data, so I was capturing data every 20 milliseconds.

Code: [Select]
#include <SoftwareSerial.h>

int signal, oldsignal;
long count, time, previoustime;
int a, b;

void setup()
  pinMode(8, INPUT);

void loop()
  signal = digitalRead(8);
  time = millis();
  if((signal == 0) && (oldsignal == 1))
  if(time == (previoustime + 20))
    previoustime = time;
    a = (count/10);
    b = ((count - ((a)*10)));
    count = 0;
  oldsignal = signal;

So, just in case some of you out there could use a quick and easy DIY speedometer. There ya go!
Webmosa is a marketing firm that works specifically with small and


Very interesting idea!
Have you considered using the IRQ pin (2 or 3) for it, so your main loop is free to do anything else..  - http://www.arduino.cc/en/Reference/AttachInterrupt -

xported it so I could graph it in Excel.

Can you post them too? just for fun!
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


I'd be happy to, Robtillaart!

I have been a lurker of this forum for about a year now, back when I struggled writing a blink sketch; so this feels good to finally be contributing some helpful advice  :)

Again, this is a Processing Sketch, that was SPECIFICALLY written for my unique case. I purposely needed to monitor the pulses over short periods of time. The machine would go right, then left, and right, etch; so I had the sketch clear out the count every time the count saw 0, so that I could see in the data where the 'break' would be.

Code: [Select]
import processing.serial.*;

int A, B, index, count;
long totalcount;
PrintWriter output;
String[] lines;

Serial myPort;

void setup()
  size(200, 200);
  println("Testing Serial Communication....");
  println("Serial Communication Test Complete!");
  myPort = new Serial(this, Serial.list()[1], 19200);
  println("All Serial Setup Complete!");
  String savePath = selectOutput();
  if(savePath == null)
    println("No output was selected...");
  } else {
    println("I think it worked?");
  output = createWriter(savePath);

void draw()
  if(myPort.available() > 0)
    A = myPort.read() - 48;
    if(myPort.available() > 0)
      B = myPort.read() - 48;
    count = (A*10)+(B*1);
    totalcount = totalcount+count;
    output.println((count) + "\t" + (totalcount));
    if(count == 0)
      totalcount = 0;

void keyPressed()
  if(key == 'a')

In regards to the Interrupt, I'm going to have to research that further as I was not aware of that function. This was simply used for a 1 time test, so consuming the entire loop wasn't an issue. However, I have had to develop some very complex codes to run three stepper motors at a time by utilizing a similar tactic as "Blink without Delay"..... that Interrupt function might be something that'd help me. If not, always good to learn new things!
Webmosa is a marketing firm that works specifically with small and


If what you're measuring is RPM then you have a tachometer. What most people do is attach a magnet to the shaft or wheel hub and use a hall sensor to detect RPM. Some use light beam interrupt by spokes but dirt can foul that. What's good with that way is it can be fit to anything with a wheel.

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.


Though, the only difference between the tach and the speedometer is the factor of circumference. Point being, this is a simple a cheap way for someone to slap this together.

For my application, I did convert the data into the true speed, and what was even better is that I would get 50 increments of data for 1 revolution compared to a normal tach; this gave me very precise measurements of speed. I was trying to track error of the system, and the travel was only 10 inches, so I was able to collect hundreds of points of data compared to just 2 or 3.

But as I initially stated, I looked for this application before I tested it and hadn't found it before; so I thought it'd be good to share it if/when some other person became in need of such a device.
Webmosa is a marketing firm that works specifically with small and

Go Up