Answer the question
In order to leave comments, you need to log in
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
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.
I'm afraid to be that dude who did not understand anything and wrote garbage, but you're not talking about interruptions?
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.
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question