Go Down

Topic: Arduino as a timing device using light beams (Read 1 time) previous topic - next topic

Gadget999

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

could be a neat little project

bubulindo

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).

Chagrin

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.

CrossRoads

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.
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.

Gadget999

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)

cowasaki

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.


robtillaart

#6
Jun 15, 2011, 09:30 am Last Edit: Jun 15, 2011, 09:32 am by robtillaart Reason: 1
millis() returns an unsigned long, an int would overflow within a minute....

Code: [Select]
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: [Select]
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: [Select]
volatile unsigned StopWatch MySW;

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

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


my 2 cents
Rob
Rob Tillaart

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

cowasaki


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 :)

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.

robtillaart


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

Rob Tillaart

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

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview