Struggiling with IR speed detector


hi,
i'm trying build device sits in tube , uses 2 ir beams detect speed of foam rocket. in head, first beam broken, timer started , stopped when second beam broken. turning out not simple!!

at moment have trying splice other people's code together:

code: [select]

#include <irremote.h>

#define pin_ir 3
#define pin_detect 2
#define pin_status 13

long previousmillis = 0;
long starttime;
long elapsedtime;

int irstate;
int lastirstate;

irsend irsend;
void setup()
{
  serial.begin(9600);
  pinmode(pin_detect, input);
  pinmode(pin_status, output);
  irsend.enableirout(38);
  irsend.mark(0);
}

void loop() {

irstate = digitalread(pin_detect);

if (irstate == low && lastirstate == high){
  starttime = millis();
  delay(10);
  lastirstate = irstate;
}

else if (irstate == low && lastirstate == low){
  elapsedtime = millis()- starttime;
  lastirstate = irstate;
  serial.println(elapsedtime);
 
}



however a) 1 light gate (i need 2 measure time between , speed) , b) seems display time broken for, added onto increasing time arduino has been on for?

i can't seem find online can use this, use 2 gates , 38khz signal ir leds (to stop sunlight triggering it)


my aim have system measures time between 2 breaks, calculates speed in mph , displays through either lcd screen or 7 segment display.


any appreciated i'm finding frustrating!!
thanks :smiley-lol:

quote
in head, first beam broken, timer started , stopped when second beam broken.
that sounds right

you have taken right approach starting 1 sensor, need save value millis() when beam becomes broken.  there no need, or sense, in calculating elapsed time until have millis() values when each beam broken.



Arduino Forum > Using Arduino > Programming Questions > Struggiling with IR speed detector


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor