Go Down

Topic: Speedometer calculation (Read 4377 times) previous topic - next topic

NI$HANT

Jan 08, 2012, 07:42 am Last Edit: Jan 08, 2012, 07:45 am by Nishant Reason: 1
The Radius of the front wheel is 30cm so i calculated the circumference 2pieR  to have it as 188.4 cm or 1.884 meters means in 1second it will cover a distance of 1.884 meters and the speed would be calculated by multiplying number of revolutions in 1 sec with 1.884 x 3600/100 thus the equation becomes as follows:

N × 6.784 or N × 6.8

SO I WANT TO KNOW THE WAY IN CODE TO HAVE THE VALUE OF "N"?(i'm using a hall effect sensor or a reed switch)

AND,

also i want to use the same magnet that is used by the speedometer wire so how should i mount the hall sensor or reed switch near it?

This is a link to the image of speedometer assembly with the bikes front wheel
http://winacro.com/images/stories/DSC_0044.JPG
"Real Men can Accomplish  Anything"

- skype : nishants5  

ਫ਼ਤੇਹ ਕਰੁਂ!

NI$HANT

ok i got that the number of times the reed switch or Hall sensor crosses the magnet it will get me the value of "N" now its left that where to mount this reed or hall nearby or in the speedometer console?
"Real Men can Accomplish  Anything"

- skype : nishants5  

ਫ਼ਤੇਹ ਕਰੁਂ!

robtillaart


If the magnet is on the wheel , you must place the hall sensor in such a place that the magnet passes the hall sensor as close as possible (but not closer!).

The best way to count the pulses is to use interrupts - see reference section of this site.

Furthermore you could get more precission by attaching more magnets on the wheel as you will get more pulses per rotation. Use an unsigned long as counter to prevent quick overflow.

Also worth trying is to make a speedo meter of your front wheel and of your back wheel. You will see that they will differ in value, up to you what is the right value, the front the back or something in between? 

Succes
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

AWOL

Remember also that the further from the axle, the faster the magnet will be travelling, and so the shorter the pulse.
This doesn't normally matter if you're using interrupts, but may make a difference if you're polling.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

NI$HANT

i wrote a program without interrupts but that is more or less half utilizing as its value will never be less than 6.8 (as bcz of this equation Nx6.8) and it will never increment like it does like 10-11-12-13-14-15km/hr and so on.

can you guys help me with an example and how will polling help?
"Real Men can Accomplish  Anything"

- skype : nishants5  

ਫ਼ਤੇਹ ਕਰੁਂ!

NI$HANT

The program i have till now goes like (N x 6.8) 1 x 6.8=6.8km/hr, 2x6.8= 13.6km/hr and so on but the increments should be like 1km/hr then 2km/hr then 3km/hr and so on
"Real Men can Accomplish  Anything"

- skype : nishants5  

ਫ਼ਤੇਹ ਕਰੁਂ!

robtillaart


Please post your code you have sofar.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

NI$HANT

Code: [Select]

long prevoiusMillis = 0;
Const int inputPin = 8;//input from the Hall Sensor/reed switch
int lastButtonState = LOW;
long interval = 1000;  // the amount of interval lag wanted

void Setup() {
pinMode(inputPin, INPUT);
Serial.begin(19200);
}

void loop() {

int reading = digitalRead(inputPin);
while(reading != lastButtonState) {
int m = m++;
}

if(currentMillis - previousMillis > interval) {

    previousMillis = currentMillis;   
    Compute();
    m=0;
}

void Compute() {

float n = m * 6.8;
float kmh = n; //the final km/hr value
}
"Real Men can Accomplish  Anything"

- skype : nishants5  

ਫ਼ਤੇਹ ਕਰੁਂ!

PaulS

Quote
Please post your code you have sofar.

But first, make sure it at least compiles.

AWOL

And that Compute does something useful.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

NI$HANT

I actually wrote that code in a copy bcz i want to give you guys an idea that where im going so anyone of you can show me a correct way however the code is follows which is too much extent correct:

Code: [Select]

long previousMillis = 0;
const int inputPin = 8;//input from the Hall Sensor/reed switch
int lastButtonState = LOW;
long interval = 1000;  // the amount of interval lag wanted
int m;// variable to hold pulses

void Setup() {
pinMode(inputPin, INPUT);
Serial.begin(19200);
}

void loop() {

unsigned long currentMillis = millis();
int reading = digitalRead(inputPin);
while(reading != lastButtonState) {
  m = m++;
}

if(currentMillis - previousMillis > interval) {

    previousMillis = currentMillis;   
    float n = m * 6.8;
    float kmh = n; //the final km/hr value
    m=0;
     }

}
"Real Men can Accomplish  Anything"

- skype : nishants5  

ਫ਼ਤੇਹ ਕਰੁਂ!

NI$HANT

also its worth defining here that i replied a lot late bcz something was there that was causing a BIG BIG problem so i wasn't able to login in and according to me that went for more than 10hours the problem with arduino site started with DB errors and 404 errors then accessing the site after logging in was not possible!
"Real Men can Accomplish  Anything"

- skype : nishants5  

ਫ਼ਤੇਹ ਕਰੁਂ!

PeterH


Code: [Select]

void loop() {

unsigned long currentMillis = millis();
int reading = digitalRead(inputPin);
while(reading != lastButtonState) {
  m = m++;
}



What is this code fragment intended to do? I don't see any way for reading or lastButtonState to change once you have entered the while loop.
I only provide help via the forum - please do not contact me for private consultancy.

PaulS

Code: [Select]
int m;// variable to hold pulses
One letter global variable names are not recommended. How does one associate m with pulse count. Now, pulseCnt or pulseCount would be easy to associate with pulse count.

Along with PeterH's question (which is probably the crux of your problem), I'd ask what the currentMillis variable is for. It is local, so it isn't accessible outside of loop().

Generally, if you want to create a speedometer, you separate the counting of pulses from the sensor from the use of pulse count. That is most easily done by connecting the sensor to pin 2 or 3, and defining an interrupt service routine to be called when the sensor is triggered. That ISR then just counts pulses (in a properly named volatile global variable).

The loop() function then just keeps track of time, and periodically checks how many pulses have occurred, computes the speed, and resets the counter (not necessarily in that order). How often to check depends on what type of counter you are using (byte, int, long) and how long it takes that counter to overflow (you do not want that to ever happen).

NI$HANT

Yes you both are correct i just wanted to get my idea down on paper and that
Code: [Select]
]unsigned long currentMillis = millis();
int reading = digitalRead(inputPin);
while(reading != lastButtonState) {
  m = m++;


intends to increment the variable to give me number of revolutions in a second(interval value) for this equation kmh = n * 6.8
"Real Men can Accomplish  Anything"

- skype : nishants5  

ਫ਼ਤੇਹ ਕਰੁਂ!

Go Up