shortest code for techometer using reed switch

i want the shortest possible code for tachometer using reed switch. plz help

Don't use a reed, they bounce. Use a digital Hall effect.

Where is your code so far?

gangradesudarshan: i want the shortest possible code for tachometer using reed switch. plz help

Why is it for a compertition? Short code is very often the most difficult to read and understand.

actually i want to measure the speed of my bicycle using arduino, and i have ready made reed switch assembly available to be placed on bicycle

uint32_t x;float d=1;void setup(){}void loop(){if(digitalRead(4))x++;Serial.println(x*P*d);}

Can't make it shorter than 1 line ;)

Connect the reed switch through a circuit that will produce a fixed-length LOW pulse. In the example below the LOW time has been determined experimentally to be 3446 microseconds. Add the LOW time to the HIGH time measured by 'pulseIn()' to get microseconds per revolution. Divide that into microseconds per minute (60 * 1000 * 1000) to get REVOLUTIONS PER MINUTE.

int RPM = 60000000UL / (pulseIn(5, HIGH)+3446);

Because of the LOW pulse time the maximum measurable RPM is around 17,000. How short a LOW pulse you can use depends on the bounce time of your reed switch.

the maximum measurable RPM is around 17,000

It’s a bicycle - that’s unlikely to be a problem.

thanx... and from this speed i want to drive a high torque servo motor which is connected to the gear shifter. so at regular speed interval gear shift can be achieved. so please provide me with an ultra responsive code which would perform this job perfectly. Assume every gear shift at 10 degree of servo rotation for every increment in speed of 5 km/hr

thanx... and from this speed i want to drive a high torque servo motor which is connected to the gear shifter.

OK,

so please provide me with an ultra responsive code which would perform this job perfectly. Assume every gear shift at 10 degree of servo rotation for every increment in speed of 5 km/hr.

Sorry, helped you to get started, now it is your turn to do some coding (we help people here to help themselves)

After a serious try you can post your code and we will help you to make another step.

thanx :) i undestand