Go Down

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

#### DaBeej

##### Nov 15, 2011, 05:37 pm
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: [Select]
#include <SoftwareSerial.h>

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

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

void loop()
{
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!
Webmosa is a marketing firm that works specifically with small and

#### robtillaart

#1
##### Nov 15, 2011, 07:35 pm
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!
Rob Tillaart

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

#### DaBeej

#2
##### Nov 15, 2011, 07:46 pm
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.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);

if(myPort.available() > 0)
{
}

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!
Webmosa is a marketing firm that works specifically with small and

#### GoForSmoke

#3
##### Nov 15, 2011, 07:59 pm
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.

2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

#### DaBeej

#4
##### Nov 15, 2011, 08:09 pm
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

#### GoForSmoke

#5
##### Nov 15, 2011, 08:13 pm
And it works for stepper motors. So why wasn't it posted in Exhibition?

2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

#### DaBeej

#6
##### Nov 15, 2011, 08:22 pm
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.
Webmosa is a marketing firm that works specifically with small and

#### masavee

#7
##### Jun 18, 2012, 11:15 am
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
and see better in night

#### PeterH

#8
##### Jun 18, 2012, 01:27 pm

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.
I only provide help via the forum - please do not contact me for private consultancy.

#9
##### Jun 18, 2012, 03:30 pm
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.
General Arduion tutorials = http://tronixstuff.wordpress.com
http://www.gammon.com.au/forum/bbshowpost.php?bbtopic_id=123

#### kivig

#10
##### Jun 18, 2012, 07:54 pm
If speedometer is the goal itself, I bought Chinese one for a bicycle for 2\$ on ebay. Still works great.

#### mykiscool

#11
##### Jun 19, 2012, 02:15 am
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.
Technician at Yuneec Electric Aviation

#12
##### Jun 19, 2012, 04:16 am

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.
General Arduion tutorials = http://tronixstuff.wordpress.com
http://www.gammon.com.au/forum/bbshowpost.php?bbtopic_id=123

Go Up

Please enter a valid email to subscribe