Pages: [1]   Go Down
Author Topic: Arduino as a timing device using light beams  (Read 1121 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Sr. Member
****
Karma: 4
Posts: 331
Arduino - very interesting !
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

has anyone used an arduino for measuring timing of say a runner or car over a certain distance

could be a neat little project
Logged

'round the world...
Offline Offline
Faraday Member
**
Karma: 42
Posts: 3289
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, it could... have you done it?
Logged

Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

Dubuque, Iowa, USA
Offline Offline
Faraday Member
**
Karma: 49
Posts: 2544
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm working on it (for snowmobiles).

Based on my experience, the only problem you really need to take into account is making sure your photodiode (don't use a photoresistor) is calibrated properly for the beam that is being sent to it. In this respect you need to be able to turn your beam off so you can get a value measurement between the ambient light and when the beam is hitting it. It also verifies that your beams are targeted properly.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 546
Posts: 27363
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Might be better off having the beam go off a reflector and have the receiver mounted next to the transmitter. Less wiring that way. Mount one unit at the start point, have it send wireless (RF) signal to the end unit, have the end unit do the actual time keeping.
Just a thought.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

UK
Offline Offline
Sr. Member
****
Karma: 4
Posts: 331
Arduino - very interesting !
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

that is some smart thinking

maybe a laser could be used instead of light beam

or could bluetooth be used

would be interestingto see how the professional systems work (probably wired)
Logged

UK
Offline Offline
Sr. Member
****
Karma: 7
Posts: 436
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

2 x £1.99 laser pointers off ebay.  Disassemble them to remove the laser diodes and attach two wires then use these as the beams!  You can still use an LDR as the sensor with the same circuit ie BC547 or 2N2222 transistor with Emitter to GND then 10K + 10K pot between Base and GND and the LDR between Base and VCC.  Connect the collector to VCC via an LED and a resistor (220 for 5V).  You can then adjust the sensitivity with the pot with the arduino connected to the collector on each circuit.


With the above you simply need some very simple code.

so connect the first circuit to pin 2 and the second to pin 3.

while (digitalRead(2) == LOW) {
 // do nothing
}
int first = millis();
while (digitalRead(3) == LOW) {
 // do nothing
}
int timetaken = millis()-first
 
speed is a product of distance and time so the above can also give you the speed if you accurately measure the distance.

Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 223
Posts: 13896
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

millis() returns an unsigned long, an int would overflow within a minute....

Code:
unsigned long measureTime(uint8_t pinA, uint8_t pinB)
{
  while (digitalRead(pinA) == LOW) ;
  unsigned long first = millis();
  while (digitalRead(pinB) == LOW);
  unsigned long timetaken = millis()-first;
}

Another approach would be IRQ based, leaves room for the Arduino to do something while waiting....

Code:
volatile unsigned long first = 0;
volatile unsigend long second = 0;

void IRQA()
{
  first = millis();
}

void IRQB()
{
  second = millis();
}

void resetTime()
{
  first = second = 0;
}

unsigned long lapTime()
{
  return millis() - first;
}

unsigned long finalTime()
{
  if (second > 0) return second - first;
  return 0;
}

or use - http://www.arduino.cc/playground/Code/StopWatchClass -

Code:
volatile unsigned StopWatch MySW;

void IRQA()
{
  MySW.start();
}

void IRQB()
{
  MySW.stop();
}

my 2 cents
Rob
« Last Edit: June 15, 2011, 02:32:06 am by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

UK
Offline Offline
Sr. Member
****
Karma: 7
Posts: 436
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

millis() returns an unsigned long, an int would overflow within a minute....

my 2 cents
Rob


I actually wrote pseudo code then realised that it was nearly C so just re-wrote it slightly and hadn't even thought about the size of int.  The same code with "long" in front would do it though smiley

I am quite new to the Arduino and have not seen lots of things people keep coming up with like the stop watch class!  All very useful stuff.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 223
Posts: 13896
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Spend one evening reading through the playground and you will get enough ideas for a year of happy tinkering, probably even more smiley-wink

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: