How to work out the rotation speed of a bike wheel.

Hi
I need help with programming the speed rotation of a bike wheel.
Im going to use a reed swtich or hall effect sensor for the pulse.

I have tried programming it but I don't know the language well enough..
Here's what i have so far. I think im on the wrong track. Any help would be greatly appreciated.
p.s this code is just rough, not made to work exactly, as its missing int etc..

String Location = "Start"
int wheelRevTime = 0
String Speed "Stop"

loop

Delay 1 // 1 second delay - for testing purposes.

wheelRevTime++ // timer

If reedSwitch = HIGH

if (wheelRevTime >0 && <10 && Location == "Start" && Speed == "Stop");{
set pin HIGH
Location = "A"
Speed = "increase"
wheelRevTime = 0
}

If wheelRevTime >0 && <10 && Location =="A" && Speed == "decrease");{
set pin LOW
Location = "A"
Speed = "decrease"
wheelRevTime = 0
}

If wheelRevTime >10 && <20 && Location =="B" && Speed == "increase");{
set pin HIGH
Location = "B"
Speed = "increase"
WheelRevTime = 0
}

If wheelRevTime >10 && <20 && Location =="C" && Speed == "descrease");{
set pin LOW
Location = "B"
Speed = "decrease"
WheelRevTime = 0
}

If wheelRevTime >30 && <30 && Location =="C" && Speed == "increase");{
set pin HIGH
Location = "C"
Speed = "increase"
WheelRevTime = 0
}

If wheelRevTime >30 && <30 && Location =="D" && Speed == "descrease");{
set pin LOW
Location = "C"
Speed = "decrease"
WheelRevTime = 0
}

here you go: Arduino Playground - ReadingRPM

Thanks for that!
Im running my simulator in Virtual Breadboard, and it doesn't accept a couple commands.

attachInterrupt(0, rpm_fun, RISING); -- im guessing that because i don't have any input ?

and

rpm = 30 * 1000 / (millis() - timeold) * rpmcount; - error, type 'long' is not assignable as a 'int'

I have compiled it without problem, so i guess the simulator does not support interrupts. Aybe try with a simple program first to see if that's the case.

And for that conversion, try if just putting (int) or (long) in front of the calculation makes a difference. That converts to respectively an int and a long.

if (wheelRevTime >0 && <10 && Location == "Start" && Speed == "Stop");{

There are a number of things wrong with this line.


First the semicolon means that whatever is in brackets is unconditionally executed so the "if" does nothing useful.


Second, this doesn't do what you appear to think it does:

wheelRevTime >0 && <10

You have to repeat the subject of the test, eg.

wheelRevTime > 0 && wheelRevTime < 10

Third, I wouldn't be using the String class myself. Use a variable with values like 1 = start and 2 = stop. Otherwise you might get memory fragmentation.


set pin HIGH

This is just pseudocode, right? Better look up the digitalWrite function in the reference section.