In this article we look at using a light-gate to measure speed, if you’ve not already read the article about building a light gate then I suggest you start there first. A video is also available showing the light gate build and measuring speed:
What is speed?
(Please skip this if you are up to speed with speed!) Speed is, as you might think, how fast something moves. But what does that mean? What makes an athlete who completes a 100m sprint faster than one who comes second? Obviously the winner did the distance in a shorter amount of time. What if one athlete runs for 250m and another for 273m and they did it in the same time, how do we know which one actually went faster? It seems obvious it’s the one that went the further distance in that given time. Obviously distance is a very important factor to speed as well as the time travelled. So the equation used to calculate a speed is the distance an object has travelled divided by the time it took to travel the distance and the equation is:
Speed = Distance/time
Why use a Light-Gate?
So in essence all we need to do (if we were measuring someones speed at a sports day for example) would be to start a stop watch when they start running and stop it when the cross the finishing line. We know how far they’ve run (say 100m) and we now know how long it took them, so we can calculate a speed. But there is some inaccuracy to that system due to the human pressing the stopwatch. For a children’s sports day over a 100m it’s probably not that important but if we want to measure objects over a much shorter distance – say a few cm’s – then those human reaction times make accurate results almost impossible. We need something with extremely fast reaction times and able to time to hundreds if not thousands of a second. This is where a Light-Gate comes in. Electronics have a much better reaction time than humans and can count time to incredibly small amounts, perfect for out uses.
Measuring speed – scenario 1 – don’t do it this way!
So we need to start a timer when the object goes past a certain point and stop it when it reaches another. If we know the distance between those two points then we can calculate its speed whilst it travelled from point 1 to point 2. Look at the diagram below:
When the car goes past the first light-gate, cutting the beam, we start a timer. When it cuts the second beam stop the timer. We know the distance between the two gates so we can calculate the speed of the car. BUT we have used two light gates to do this, we can do the exact same speed calculation using just one light gate, read on…
Measuring speed – scenario 2
Look at the diagram below
We have stuck a piece of thin card on top of the car which we know the length of, in this case 5cm. Obviously the card must be the only thing to pass the beam, so the beam must be higher than the car body. When the card first cuts the beam we start our timer, when the card clears the beam we stop our timer. In that time the car has travelled the length of the card, in this case 5cm. So we know how far it’s travelled and the time it’s done it in, we can calculate a speed. And we did this with only one light gate.
Here’s my set-up from the real world, with the light-gate and car.
The code
The code below will perform the speed calculation for you reporting it back in the serial monitor. Note your card length must be 5cm, if you want anything different then alter the #define at the start of the code to whatever your card length is.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
#include <IRremote.h> // card length in cm float CardLength=5; #define PIN_IR 3 #define PIN_DETECT 2 #define PIN_STATUS 13 IRsend irsend; void setup() { pinMode(PIN_DETECT, INPUT); pinMode(PIN_STATUS, OUTPUT); irsend.enableIROut(36); irsend.mark(0); Serial.begin(9600); delay(1000); // wait for system to settle } void loop() { // wait for active digitalWrite(PIN_STATUS,false); while(digitalRead(PIN_DETECT)==true); digitalWrite(PIN_STATUS,true); // wait for "thing" to cross beam while(digitalRead(PIN_DETECT)==false); // start timing digitalWrite(PIN_STATUS,false); long int StartTime=millis(); // wait for thing to stop blocking beam while(digitalRead(PIN_DETECT)==true); // end timing long int EndTime=millis(); long int TotalTime=EndTime-StartTime; float Secs=float(TotalTime)/1000; float Speed=CardLength/Secs; Serial.print(Speed); Serial.println("cm/s"); Speed=(CardLength/100)/Secs; Serial.print(Speed); Serial.println("m/s"); } |
Next article
In the next article we will look as calculating acceleration