Timing Gates for Racing Cars
Being a teacher can be an interesting gig. One day you're out on the oval in freezing slush, separating overly enthusiastic teenagers intent on wrestling one another into submission and wondering where your life went astray.
Then some days you will have an experience of sublime excellence in your chosen field (mathematics natch), be complimented by a parent, be paid to go to a wonderful concert, and leave work early because you can.
It's the proverbial box of chocolates!
A couple of weeks ago I was asked to help out on a STEM project where CO₂ gas-powered model cars are fired along a wire to test student design.
In the past the "runs" were measured using manual techniques such as a stopwatch.
We can improve the accuracy of the timing using a laser gate - a laser light shines into a photodiode. When the light is shining, there is a voltage generated. When there is no light, this voltage drops.
The difference can be used to see when a laser beam is interrupted, in this case by a toy car!
The photodiode is connected reversed biased with VCC to cathode and the anode via a resistor to ground. If light falls on the diode it will cause a current through the resistor, which will cause a voltage across it.
There needs to be enough voltage drop across the photodiode to measure.
The following code is a skeleton for the students to work with, but it demonstrates how such a circuit can be used to capture start and stop times for this project.
/* Timing gate using laser diodes as transmitters and photodiodes as receivers. 25 May 2022 */ const int startPin = A0; // starting receiver const int stopPin = A1; // stopping receiver int sensorValue = 0; // value read from the photodiode int outputValue = 0; // scaled value long gotime = 0; // timing variables used by long stoptime = 0; // millis() long racetime = 0; float printtime = 0; // converted for display byte ambient = 50; // can use this or a 10k pot in // circuit to adjust for ambient light void setup() { Serial.begin(9600); Serial.println("RACING: "); delay(500); // settle time before race } void loop() { sensorValue = analogRead(startPin); outputValue = map(sensorValue, 0, 1023, 0, 100); if ((outputValue > ambient)) { gotime = millis(); // and we're racing Serial.println("GO!"); delay(500); // delay while end of car goes past start gate sensorValue = analogRead(startPin); outputValue = map(sensorValue, 0, 1023, 0, 100); delay(2); // ADC convert time delay while (outputValue < ambient) { sensorValue = analogRead(startPin); outputValue = map(sensorValue, 0, 1023, 0, 100); delay(2); // keep reading } stoptime = millis(); // and we've finished Serial.println("STOP!"); racetime = stoptime - gotime; printtime = racetime / 1000.0; Serial.print("Racetime: "); Serial.print(printtime, 3); Serial.println(" seconds"); Serial.println(); Serial.println(); delay(5000); // delay until next race possible Serial.println("RACING: "); } delay(2); }
That all works fine, but some fine tuning (due to OH&S considerations) has seen the laser swapped out for an ordinary LED so the kiddies don't burn out their eyeballs staring too long at the pretty red light!
In the video below I use a straw hat LED which actually has quite a wide throw, so perhaps another LED or indeed the proposed glass/aluminium "tunnel" which should focus the light better.
It doesn't really matter as the sensitivity can either be adjusted in the circuit (via R), or in the code (via the variable "ambient").
I'm now handing this all over to the students and their teachers for the next stage - they need to do some of the development work, right?
No comments:
Post a Comment