I am planning to build an odometer for my motorcycle..
need some ideas of how to calculate for Kilometers with the pulses from the hall sensor...I want to have the odometer reading to 1 decimal..
My wheel diameter is 203.5 cm .. So if I use one magnet on the wheel there will be one pulse every 203.5 cm I travel that is 0.002035 Km approx...
So for 1 Km I will have 491.4 pulses..
So is it better to have one pulse every revolution of the wheel or its better to have two pulses every half revolution of the wheel for little precision of the decimal.. ..
Moreover what is going to be the best method of calculating the Km traveled (reading) in the code...??
For the purposes of an odometer, that should be plenty of accuracy. You only really need accuracy of about a tenth of a km (assuming your odometer is going to display tenths of a km). In the real world, you don't need more than about 5-10 times the resolution of the 'quantity' you want to measure. Minimum recommended is at least 2x. Your sensor has almost 50 times the resolution of a tenth of a km. So, for that purpose, it is more than adequate.
As for how to keep track of it, I say keep it simple. Keep track of the pulse count in an unsigned long. This will be more than enough storage to keep track of over 8 million miles of travel.
then just divide this by 491 to get the number of kilometers. Take the modulus of 491 to get the tenths of a km.
If you had two, that would provide better resolution of speed/acceleration if you wanted to to add that at some point.
Ignoring half the pulses for distance would be easy enough.
I wouldn't worry about the .4. Just divide by 491. The .4 is in the noise range. There will be a variety of real world factors introducing far more error.
And you can get the 'tenths' portion of the distance by taking the modulus:
int fraction = pulse % 491 // This gives you the fraction of a km in pulse counts
int tenths = fraction / 49 // This gives you the tenths of a km driven.
If you had two, that would provide better resolution of speed/acceleration if you wanted to to add that at some point.
Ignoring half the pulses for distance would be easy enough.
You just give me an idea... The odometer sensor can also be use to calculate the speed and distance. I hope you get this idea Joy. You get the pulse ( maybe use a 555 in monostable mode / 74LS14 ) to clean the signal ( if needed ) get that signal into interrupt pin ( 2 or 3 ), get the number of pulses per sec and calculate the speed and distance. I am also awear of the RPM counter.
I believe, based on a past thread, that Joy has already (or is currently) worked on using the sensor as a tachometer as well.
Yes, but the sensor is a different, The RPM sensor get the pulse from the spark plug wire, The distance/speed sensor get the pulse from a magnet attach to the wheel. Two sensors He has to change the RPM program and make a new one to take account the distance/sensor AND the RPM sensor. Therefore the use of two interrupts, they have to be sample, but it going to be "tricky"
Joy:
So is it better to have one pulse every revolution of the wheel or its better to have two pulses every half revolution of the wheel for little precision of the decimal.. ..
Inflation/deflation of the tire will probably change the circumference a bit. Most tools don't actually take this into consideration.
Two magnets may give you better balance in the wheel, so you might as well use that, assuming you can track the pulses fast enough. 1000 pulses per kilometer (roughly), at 120 kilometers per hour, is 120,000/3600 pulses per second or about 33 pulses per second -- if you can keep up with this, you're probably good.
Inflation/deflation of the tire will probably change the circumference a bit. Most tools don't actually take this into consideration.
There's a lot more than just that involved.
Tread wear is going to change the circumference of the tire over time.
Different styles/makes of tires, even of the same advertised dimensions, can vary significantly in actual circumference.
As you make turns and accerelate, forces on the tires will deform them, changing their circumference as a result.
Motorcycle tires in particular, as you make turns, the contact patch with the grounds shifts from the center of the tire towards the outside of the tire, steadily changing the effective circumference of the tire.
I am using the pin 2 of arduino to detect pulses for calculating the Enging RPM....I am using FALLING
At the same time can I use the same pin 2 of arduino to detect the pulses of odometer..?? as RISING..??
The reason I am saying RISING is because you are using a 555 monostable mode for your RPM counter. I did that design in my telephone call counter project, it work better.
As for your second question : No .. it will confuse the interrupt and your program. For the odometer pulse, use pin 3 ( Interrupt 1 ) ---> attachInterrupt(1, myododmeter, RISING); I use rising if you use a positive pulse when the magnet activate the sensor... that I am just guessing...
I am using the pin 2 of arduino to detect pulses for calculating the Enging RPM....I am using FALLING
At the same time can I use the same pin 2 of arduino to detect the pulses of odometer..?? as RISING..??
No. If you trigger the same interrupt handler for two different reasons, you have to then determine, in the interrupt handler, which condition triggered the interrupt.
In your case, the reason for using interrupts are because the pulses are short and frequent. By the time the ISR is started, and you try to determine whether it was a RISING edge or a FALLING edge that triggered the interrupt, that HIGH or LOW may have changed already, so you won't be able to determine why the ISR was called.
Not knowing why the ISR was called is bad. It's better to use two separate interrupts (or more). If you don't have enough external interrupts, get a Mega which has more.
Think of the interrupt as waking you from sleep when either the front door bell or rear door bell was rung. By the time you wake up, and figure out that nobody is at the front door, whoever rang the rear door bell may be long gone. Better to KNOW which bell woke you up.
Think of the interrupt as waking you from sleep when either the front door bell or rear door bell was rung. By the time you wake up, and figure out that nobody is at the front door, whoever rang the rear door bell may be long gone. Better to KNOW which bell woke you up.
Think of the interrupt as waking you from sleep when either the front door bell or rear door bell was rung. By the time you wake up, and figure out that nobody is at the front door, whoever rang the rear door bell may be long gone. Better to KNOW which bell woke you up
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int HALL = 7;
int Hallsense;
void setup(){
pinMode(HALL, INPUT);
pinMode(13, OUTPUT);
lcd.begin(16, 2);
}
void loop(){
Hallsense = digitalRead(HALL);
if (Hallsense == HIGH){
digitalWrite(13, HIGH);
}
else{
digitalWrite(13, LOW);
}
unsigned long Hallsense;
int fraction = Hallsense % 491; // This gives you the fraction of a km in pulse counts
int tenths = fraction / 49; // This gives you the tenths of a km driven.
lcd.setCursor(0, 0);
lcd.print(tenths);
lcd.setCursor(0, 1);
lcd.print(fraction);
}