Speedometer and tachometer with halk effect sensor, Arduino


hello world! m new in forum , make speedometer using hall effect sensor. understand code found :


//bike speedometer
//by amanda ghassaei 2012
//http://www.instructables.com/id/arduino-bike-speedometer/

/*
* program free software; can redistribute and/or modify
* under terms of gnu general public license published by
* free software foundation; either version 3 of license, or
* (at option) later version.
*
*/

//outputs speed of bicycle lcd

//calculations
//tire radius ~ 13.5 inches
//circumference = pi*2*r =~85 inches
//max speed of 35mph =~ 616inches/second
//max rps =~7.25

#define reed a0//pin connected read switch

//storage variables
float radius = 13.5;// tire radius (in inches)- change own bike

int reedval;
long timer = 0;// time between 1 full rotation (in ms)
float mph = 0.00;
float circumference;
boolean backlight;

int maxreedcounter = 100;//min time (in ms) of 1 rotation (for debouncing)
int reedcounter;


void setup(){
 
 reedcounter = maxreedcounter;
 circumference = 2*3.14*radius;
 pinmode(1,output);//tx
 pinmode(2,output);//backlight switch
 pinmode(reed, input);
 
 checkbacklight();
 
 serial.write(12);//clear
 
 // timer setup- timer interrupt allows preceise timed measurements of reed switch
 //for mor info configuration of arduino timers see http://arduino.cc/playground/code/timer1
 cli();//stop interrupts

 //set timer1 interrupt @ 1khz
 tccr1a = 0;// set entire tccr1a register 0
 tccr1b = 0;// same tccr1b
 tcnt1  = 0;
 // set timer count 1khz increments
 ocr1a = 1999;// = (1/1000) / ((1/(16*10^6))*8) - 1
 // turn on ctc mode
 tccr1b |= (1 << wgm12);
 // set cs11 bit 8 prescaler
 tccr1b |= (1 << cs11);  
 // enable timer compare interrupt
 timsk1 |= (1 << ocie1a);
 
 sei();//allow interrupts
 //end timer setup
 
 serial.begin(9600);
}

void checkbacklight(){
 backlight = digitalread(2);
 if (backlight){
   serial.write(17);//turn backlight on
 }
 else{
   serial.write(18);//turn backlight off
 }
}

isr(timer1_compa_vect) {//interrupt @ freq of 1khz measure reed switch
 reedval = digitalread(reed);//get val of a0
 if (reedval){//if reed switch closed
   if (reedcounter == 0){//min time between pulses has passed
     mph = (56.8*float(circumference))/float(timer);//calculate miles per hour
     timer = 0;//reset timer
     reedcounter = maxreedcounter;//reset reedcounter
   }
   else{
     if (reedcounter > 0){//don't let reedcounter go negative
       reedcounter -= 1;//decrement reedcounter
     }
   }
 }
 else{//if reed switch open
   if (reedcounter > 0){//don't let reedcounter go negative
     reedcounter -= 1;//decrement reedcounter
   }
 }
 if (timer > 2000){
   mph = 0;//if no new pulses reed switch- tire still, set mph 0
 }
 else{
   timer += 1;//increment timer
 }
}

void displaymph(){
 serial.write(12);//clear
 serial.write("speed =");
 serial.write(13);//start new line
 serial.print(mph);
 serial.write(" mph ");
 //serial.write("0.00 mph ");
}

void loop(){
 //print mph once second
 displaymph();
 delay(1000);
 checkbacklight();
}



i have understood code don't understand calcul concerning mph(

 mph = (56.8*float(circumference))/float(timer);//calculate miles per hour )

and have question : how can modifie code rps or rpm ?

ok...  there 5,280 feet (63,360 inches) in mile.  circumference / timer give inches per millisecond.  to miles per hour you'd multiply 3,600,000 milliseconds per hour , divide 63,360 inches per mile.  that gives factor of:

56.818181...




Arduino Forum > Using Arduino > Programming Questions > Speedometer and tachometer with halk effect sensor, Arduino


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'