Pages: [1]   Go Down
Author Topic: Cheap DIY Speedometer  (Read 2366 times)
0 Members and 1 Guest are viewing this topic.
Tacoma, WA
Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Parts:
*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:
#include <SoftwareSerial.h>

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

void setup()
{
  Serial.begin(19200);
  pinMode(8, INPUT);
}

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

So, just in case some of you out there could use a quick and easy DIY speedometer. There ya go!
Logged

Webmosa is a marketing firm that works specifically with small and

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 170
Posts: 12462
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 -


Quote
xported it so I could graph it in Excel.
Can you post them too? just for fun!
Logged

Rob Tillaart

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

Tacoma, WA
Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley

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:
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.list());
  println("Serial Communication Test Complete!");
  delay(200);
 
  myPort = new Serial(this, Serial.list()[1], 19200);
 
  println("All Serial Setup Complete!");
  delay(100);
 
  String savePath = selectOutput();
  if(savePath == null)
  {
    println("No output was selected...");
  } else {
    println("I think it worked?");
    println(savePath);
  }
  output = createWriter(savePath);
}

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

void keyPressed()
{
  if(key == 'a')
  {
    println("Done!");
    output.flush();
    output.close();
    exit();
  }
}

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!
Logged

Webmosa is a marketing firm that works specifically with small and

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 58
Posts: 4019
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.



Logged

Examples can be found in your IDE.

Tacoma, WA
Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Webmosa is a marketing firm that works specifically with small and

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 58
Posts: 4019
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And it works for stepper motors. So why wasn't it posted in Exhibition?

Logged

Examples can be found in your IDE.

Tacoma, WA
Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

10 posts..... 20% of which are explaining my use of terminology with you.

My apologies Mr. Listings Moderator, I shouldn't have tried sharing something useful as there are things FAR more important.
Logged

Webmosa is a marketing firm that works specifically with small and

Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hall sensor at near wheel or other place(volswagen car)have in speed/odometer own disc were can read whit hall -sensor all ,speed,odometer,kilometers,easy.
why use steppermotor then LCD have good and easy ?
or if understand good arduino use graphical screen.and led bar have beauty than needle meter smiley
and see better in night smiley
Logged

UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11173
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

10 posts..... 20% of which are explaining my use of terminology with you.

My apologies Mr. Listings Moderator, I shouldn't have tried sharing something useful as there are things FAR more important.

Sharing is all very well, but since you aren't asking for help the Exhibition forum is the appropriate place for this thread.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Greenville, IL
Offline Offline
Edison Member
*
Karma: 11
Posts: 1309
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
why use steppermotor

 This would work well with a cable output from a transmission or front wheel of a motorcycle. You might even be able to use it with a bicycle if you have a cable to indicate speed.
Logged


Offline Offline
Full Member
***
Karma: 0
Posts: 101
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If speedometer is the goal itself, I bought Chinese one for a bicycle for 2$ on ebay. Still works great.
Logged


California
Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Use a magnet, magnetic reed switch, and math. Attach the magnet, use the reed switch to detect when the magnet passes by therefore one revolution, then calculate speed based on wheel diameter.
Logged

Proud Member of the Nighthawk Robotics Club Team 569 B

Greenville, IL
Offline Offline
Edison Member
*
Karma: 11
Posts: 1309
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


 All of the other ideas are good but, the point of the post is that the OP found a new way to skin a cat. We have conveyors at work that use a system similar to the one described in the first post. The advantage is precision, it may not be the best thing for every application but, it does work.
Logged


Pages: [1]   Go Up
Jump to: