Speedometer with reed switch.

I'm trying to make a speedometer with an arduino uno and a reed switch. The only code that I have so far is the code below which I got help from my teacher to write. If someone could please help me complete the code as I am lost and don't know what to do.

unsigned long timer; unsigned long total; int analogValue =10; unsigned long counter=0; void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(10,INPUT); } void loop() { // put your main code here, to run repeatedly: timer=millis(); while(!digitalRead(10)) { // } total=millis()-timer; Serial.println(total); }


Well, you are going to have to think about how you calculate the speed. You need to figure the circumference of the wheel you are using (assuming your pickup is on the wheel). How do you calculate speed from the time of rotation of the wheel ? Two methods depending on the speed and how fast you want to update the display - measure the time a rotation takes (for very slow speed) or number of rotations in a given period of time (faster speed). Then you need to convert to a meaningful display string if you are using serial for example - mph, kph ? Do you want it to track distance as well? Once you come up with a detail plan of how you are going to get and handle it, then you can start writing code. Writing code without having hardware (or at least a detailed plan of how it is going to work) is simply wasting your time.