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.
#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!