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.
int signal, oldsignal;
long count, time, previoustime;
int a, b;
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!