D
D
dreamjke2012-10-10 21:17:33
Arduino
dreamjke, 2012-10-10 21:17:33

Arduino speedometer

Good evening!
Actually, by closing the reed switch, we count how much has passed since the previous circuit and divide the circumference of the wheel by this value. It remains to describe the interrupt conditions.

I propose a solution below:

  sensorState = digitalRead(gerkon);
  
  if (sensorState == HIGH) {
    if (lastState != HIGH) {
        lastTime = thisTime;
        thisTime = millis();
        spinTime = thisTime - lastTime;
        mySpeed = (wci / spinTime)*3.6 ;  // wci — диаметр колеса, как правильно напомнили в комментариях, умноженный на пи.
        if (mySpeed < 200) {Serial.print(mySpeed);Serial.print(" km/h");} // Периодически пролетают значения за 2000 км/ч, для этого ограничим максимальную скорость. (В данном примере шоссейный велосипед на станке развивает скорость до 100км/ч).
        lastState = HIGH;
    }

  } else { 
   lastState = LOW;
 }

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Alexey Huseynov, 2012-10-10
@kibergus

First you throw out the arduino IDE, then you refuse the libraries provided by arduino and read the manuals for the AVR. And then it turns out that there is such a thing as input capture. When the reed switch is closed, the processor puts the time when this happened in a special register in hardware, and then causes an interrupt.
Only the IC hangs not on the timer that is used to count the time in arduino.
Without the use of an IC, your speedometer will not work normally.

D
Denis, 2012-10-10
@uscr

I'm afraid to be that dude who did not understand anything and wrote garbage, but you're not talking about interruptions?

N
nochkin, 2012-10-11
@nochkin

If Arduino, then here is an approximate approach:
1. How to attach to an interrupt:
www.arduino.cc/en/Reference/AttachInterrupt
2. The current time can be taken through millis (). Here's just in case for rollover:
www.arduino.cc/playground/Code/TimingRollover
Then it's enough to count the time since the previous interrupt and find the speed.

S
sam_satan, 2012-10-11
@sam_satan

You can put a capacitor in series with the reed switch, but you have to put diodes on the ground.
Such circuits are used in the timing of PWM controllers.

S
sergof, 2012-10-11
@sergof

just in case: it is necessary not only to divide the diameter by the time delta, but also multiply by pi.
sorry for offtopic

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question