Trouble Reading Sensor correctly to calculate speed


hi there,

i trying calculate speed of springloaded ejecting mechanism. have mounted 2 through beam infrared modules spx 1189 honeywell . have response time of 5 microseconds.
i have connected them arduino uno , placed them 7.5 cm apart

i use following program calculate time , display both time , speed.

code: [select]

//sample using liquidcrystal library
#include <liquidcrystal.h>

/*******************************************************
 *
 * speedcount  for arduino
 * peter h
 * jan 2015
 ********************************************************/



double starttime =0.0;
double endtime =0.0;
double duration =0.0;
double speed=0.0;
const int firstirpin = 2;
const  int secondirpin = 3;
boolean firstirstate = true;
boolean secondirstate = true;

// select pins used on lcd panel
liquidcrystal lcd(8, 9, 4, 5, 6, 7);
// define values used panel , buttons
int lcd_key     = 0;
int adc_key_in  = 0;
#define btnright  0
#define btnup     1
#define btndown   2
#define btnleft   3
#define btnselect 4
#define btnnone   5


void setup()
{
  lcd.begin(16, 2);              
  lcd.setcursor(0,0);
  lcd.print("   speedcount");
  delay(2000);


  lcd.setcursor(0,1);
  lcd.print("     ready    ");
  lcd.setcursor(0,0);

  pinmode(firstirpin, input_pullup);
  pinmode(secondirpin, input_pullup);
}

void loop()
{
  if(!digitalread(firstirpin))
  {
    firstirstate=true;
  }
  if(!digitalread(secondirpin))
  {
    secondirstate=true;
  }
  if(digitalread(firstirpin)&&(firstirstate)) //pin must low , first time round
  {
    starttime=micros();
    
    firstirstate=false;
  }
  if(digitalread(secondirpin)&&(secondirstate))
  {
    endtime=micros();
    duration =endtime-starttime;
    lcd.setcursor(0,0);
    lcd.print("t: ");

    lcd.print(duration,0);
    lcd.print(" usec   ");
    lcd.setcursor(0,1);
    lcd.print("s: ");
    speed =360000/duration; // distance of 10 cm
    speed = speed*3/4; // because distance reduced 7.5 cm
    lcd.print(speed,2);
    lcd.print("  km/h  ");
    secondirstate=false; // stop repeated calculation
  }

}





the problem that,  to me looks if unit "lightning fast", time , speed calculated program approx. 17 km/h

i believe uno , sensors capable of handling short timing, , have tried moving sensor , measure distance of 2.5 cm , end of passage gain max speed, difference minor.
i wondering if have factor 10 wrong cant find it. i have enclosed short video showing contraption in action oops not possible  :)

so questions is: there major error or accept speed of less 20 km/h?

/peter

i have enclosed short video showing contraption in action
no haven't :p

i've not looked @ code on short distances speeds lot faster are.  if ever try catch housefly in mid air you'd swear fly pretty damned fast.  yet fly slower average human walks.  top speed 5 mph.  (about 8 km per hour)


Arduino Forum > Using Arduino > Programming Questions > Trouble Reading Sensor correctly to calculate speed


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code