I read the other thread but couldnt make much sense of it.
I tried modifying the Fan speed sensor code, and that didnt work either.
Im trying to make a speedometer that detects the speed of the output shaft of the diff, and then workout the speed of the vehicle. Using a hall sensor to detect axle/wheel speed.
Here is my code, it is not finished and I have some questions:
/* Speed sensor
* Detects diff ouput speed and works out vehicle speed.
*/
volatile byte rpmcount;
unsigned int rotations;
unsigned long timeold
int tyresize;
int speed;
void setup()
{
Serial.begin(9600);
attachInterrupt(0, rpm_fun, RISING);
rpmcount = 0;
rotations = 0;
timeold = 0;
tyresize = 2345; //Enter the circumfrence of your tyre size here, meausred in mm
}
void loop()
{
if (rpmcount >= 20) {
//Update RPM every 20 counts, increase this for better RPM resolution, decrese for faster update
rotations = 30*1000/(millis() - timeold)*rpmcount;
timeold = millis()
rpmcount = 0;
speed = (rotations * tyresize) //Calculation to work out speed.
Serial.PrintIn(speed,DEC);
}
}
void rpm_fun()
{
rpmcount++;
}
But i get a error when I try and compile it:
error: expected intializer before 'int'
error: expected initializer before 'int' In function 'void setup()':
In function 'void loop()':'
I know that my calculation for speed is wrong.
I dont understand what this part of the code does
rotations = 30*1000/(millis() - timeold)*rpmcount; (remember its modifed code from the fan rpm code)
I need a way to work out rpm of the wheel so I can work out speed. since i am planning on using this calculation to work out vehicle speed:
meterspm = wheelrpm * wheelcircumfrence / 1000 //times wheelrpm and wheel circumfrence (in millimeters) to give millimeters a minute, devide by 1000 to give meters per minute
speed = (meterspm /1000) *60 //devide meterspm by 1000 to give kilometers per minute, times 60 to give kilometers per hour.
So basically, I need to read RPM of a spinning axle with a hall effect sensor (or maybe some other sensor?) So I can work out vehicle speed. I think once I can get RPM into a varible I will be able to work out vehicle speed easily.
Sorry if this is hard to understand, my head is spinning.
Also, I cant get the original Fan speed RPM code to compile, which is:
volatile byte rpmcount;
unsigned int rpm;
unsigned long timeold;
void setup()
{
Serial.begin(9600);
attachInterrupt(0, rpm_fun, RISING);
rpmcount = 0;
rpm = 0;
timeold = 0;
}
void loop()
{
if (rpmcount >= 20) {
//Update RPM every 20 counts, increase this for better RPM resolution,
//decrease for faster update
rpm = 30*1000/(millis() - timeold)*rpmcount;
timeold = millis();
rpmcount = 0;
Serial.println(rpm,DEC);
}
}
void rpm_fun()
{
rpmcount++;
//Each rotation, this interrupt function is run twice
}