Go Down

Topic: Arduino speedometer not working for an unknown reason (Read 224530 times) previous topic - next topic


Aug 24, 2012, 03:05 pm Last Edit: Aug 24, 2012, 03:08 pm by odometer Reason: 1
I was thinking about this some more.

I do not think that it is a good idea to measure the time between pulses. Two reasons:
1) The pulse itself takes time!
2) If the real speed is 0, there will be no pulse, and so the speedometer will be waiting forever for a pulse.

The basis for my method is this: Assume that the speed of your board is 1 kilometer per hour. One kilometer is 1000000 millimeters. Since your wheel is 217 mm in diameter, 1 kilometer equals about 4608 turns of your wheel. One hour is 3600 seconds. Divide these 3600 seconds by the 4608 turns, and you get about 0.781 second per turn.
The method itself, then, is to count the number of pulses in 0.781 second. That is your speed, in kilometers per hour.

Just count pulses. Every 781 milliseconds, display the number, then start counting again from zero.


Aug 25, 2012, 01:25 am Last Edit: Aug 25, 2012, 02:27 am by PGTBOOS Reason: 1
Well this kind of measuring using pulses is widely used in manufacturing, for example robotics.
NOTICE that it measures the duration of a pulse, so there is no loose of pulse time here.
Depending on how you set pulsin you can measure the time of low signal or high signal, after a previous pulse.
Light itself is extreme fast wheel side hole should be small (needle).. and measure the LOW signal duration
instead of a hole you might put some small reflecting on your wheel to and point a led or so next to a LDR
..you could also work with large holes like 1/4 of diameter but math below will be different then
..but wouldbe easy once you get it.

Of-course it takes time to measure using PulseIn  but the arduino will do nothing else until it has a next pulse.
Its the smallest code to to measure it.

for distance measuring, maybe something different might be better... dough you can work around it with some math
but if it is precise speed your after PulseIn is quite good, as it uses minimal code to measure time and so its more accurate.
to improve precision i would do a number a measurements then average them, and then display it

//  1000 micro seconds = 0,001 seconds
//  1 minute  = 60000000 microseconds
//  1 hour    = 360000000 microseconds
//  km/hour  >> lets say wheel diameter size = 217 mm (thats small)
//  diameter 217mm * pi =   681,725mm
//  so a full cycle gets you 681,725 mm away or ~  0.000681725 km  so  1/0,00681725 =   1 km =  1466,867 cyles  
//  so if you do 1466,867 cylces in a hour then your speed = 1km/p hour
//  so ( 1466,867 cycles per hour ) equals  1466,867 cycles  per 360000000 microseconds
//  thus 360000000 / 1446,867 = microsecond time required for 1 cycle
//   =  1 cycle should be done in 245421,023174 microseconds = 1km/hour  (large number but 1 km/h is quite slow)
//   so finally  >>  1 / 245421,023174 * you measurement time    =   yourspeed  in km/hour  
//                 >> this math wont work with a integers, use dword or float
//                 >> also you can put 1/245421,023174 in a constant so you wont need to calculate it each time
//                 >>
//     ~you might double check it but i think its ok√©
//    (and i think previous person forgot pi x diameter, because many more cycles are needed )

although i have to agree that if the wheel stands still its not measuring speed and the execution flow would halt.
on the other hand, this way allows for rapid measurements might be nice for quadcopter motor speed measuring etc.
but the required code for this would be small and likely fit in a tinyduno too, then it could respond speed to a normal arduino, if you dont want execution flow to stop.. (i wonder dough, maybe speed sensors allready exist ?).
On the otherhand a tiny duno a led and a LDR equals a speed meter below  4 dollar  or so, thats not exve   :))

another thing to use averages i recommend to use the last x samples
you might do   avSpeed = ( avSpeed * 9 + newspeedmeasurement ) / 10

PS a handy site to do conversions :
you can do all kind of conversions personally i prefer that, also you can calculate inside google search


I said "wheel diameter = 217 mm"
Sorry, that was a mistake.
Correct is "wheel circumference = 217 mm" (it is the week of a kind of skateboard)

Go Up