Okay , I have a motor running with a magnet , a sensor picking up the magnet . I get correct RPM numbers on my screen , everything seems to be working well.
My problem : How to I get it to convert my RPM to MPH , I know my wheel spinning is 5inches in diameter.
what code would do the math for me ??? is this possible , thank you to all that try to help, its appreciated
matt
Circumference is pi*diameter. Each revolution is 1 circumference. For your 5 inch wheel, that is a factor of 15.71 or so. If you can live with 2% error, you can just multiply by 16 and keep things in integers.
First,,, thank you Keith for replying.
I am with you a 100% on the equation for the wheel speed conversion. Could you possible supply me with an example of how you would sketch/code the equation , thats my main problem .
THANK YOU
oops, I gave you inches per hour.
1 mile = 30,960 inch so you have:
pi * d(inch) * 1 mile/30960 inch.
Since it is much less than one, we will go ahead and use floating point.
float mph = rpm * 3.14159 * 5.0 / 30960.0;
or 5.07E-4 mph per each rpm
If your wheel is spinning really fast and mph actually means something, you can also use the formula:
unsigned int mph_ten_thousandths = rpm * 5;
so 2000 RPM will be 1 mph.
Not sure what the trouble is.
KeithRB:
oops, I gave you inches per hour.1 mile = 30,960 inch so you have:
pi * d(inch) * 1 mile/30960 inch.
That is incorrect.
One mile is 5280 feet. One foot is 12 inches. Therefore, one mile is 5280 * 12 = 63360 inches.
You are right. Somehow I typed 2580 into the calculator. (My new prime shows me the history so my mistake was preserved for all to see.)
Thank you Keith for not yelling at me . Im helping my boss with this project. He as written the supplied sketch, I am at work just trying to help him in between machining parts. He has more expericene than I do by far, so i will show him what you wrote me . We understand the math needed , he just wanted the screen to display it and thats the part of the sketch that did not work. When I would try to add the equation into the sketch it would crash and not verify. So I thought going to the forum would help me. You have helped me , and I really really appreciate you taking your time to help. I must be new to this forum thing as well. hehe. Take care !
const float TireDiameter = 5.0; // Tire diameter in inches
const float TireCircumference = TireDiameter * PI;
const int FeetPerMile = 5280;
const int InchesPerFoot = 12;
const long InchesPerMile = (long)FeetPerMile * (long)InchesPerFoot;
const int MinutesPerHour = 60;
float RPM = 1000; // test example
void setup() {
float InchesPerMinute = RPM * TireCircumference;
float InchesPerHour = InchesPerMinute * MinutesPerHour;
float MPH = InchesPerHour / InchesPerMile;
Serial.println(MPH);
}
void loop() {}
Delta_G:
Are you 100% sure of that math? inch/min / min/hour == inch*hour / min^2. The units aren't coming out right for me which usually means the math is off.
Oops! You are right. I've corrected the code to convert from inch/min to inch/hour and then to mile/hour.