Devices & Components
Arduino Uno Rev3
Photo transistor light sensor
Through Hole Resistor, 200 kohm
Through Hole Resistor, 2k ohm
High Brightness LED, White
Hardware & Tools
3D Printer (generic)
Solder Wire, Lead Free
Soldering iron (generic)
Project description
Code
Single LED Photogate
arduino
Single photogate code for measuring of the speed of a single Hot Wheels car. The code allows the photogate to work in either direction.
1/* PhototransistorVoltage Hot Wheels Timer 2 * Power phototransistor with 5v and GND 3 * Connect the phototransistors yellow wire into A1 4 * Optional: Use a piezo buzzer connected to pin 4 and GND. 5 */ 6 7const int buzzerPin = 4; // other end of buzzer connected to GND 8float threshold = 0.25; // voltage where phototransistor shows car is in the way 9const int interval = 5; // accuracy of timer in milliseconds 10 11void setup() // Built-in initialization block 12{ 13 Serial.begin(9600); // Set data rate to 9600 bps 14} 15 16float v1, timerCount; 17boolean waitFor2ndTrigger; 18 19void loop() { 20 tone(buzzerPin, 440*6, 50); // Sound "ready" 21 timerCount = 0; 22 waitFor2ndTrigger = true; 23 v1 = volts(A1); // measure voltage from phototransister in A1 24 tone(buzzerPin, 880, 150); // Sound for start of waiting for trigger 25 Serial.println("Waiting for trigger..."); // wait for phototransistor to be dimmed 26 while (v1 > threshold) { 27 delay(interval); // otherwise it's too fast to notice button press ((when one is used) 28 v1 = volts(A1); // measure voltage from phototransister in A1 29 } 30 Serial.print("Started..."); // Display "Start" 31 32 while (waitFor2ndTrigger) { // count time until phototransistor receives light again 33 delay(interval); // Delay for defined time 34 timerCount = timerCount+interval; // Add time to counter 35 v1 = volts(A1); // check A1 phototransistor 36 waitFor2ndTrigger = (v1 < threshold); // is "false" when phototransistor receives light again 37 } 38 39 // end timer count and display results 40 Serial.println("Stopped"); // Display " sec." & newline 41 tone(buzzerPin, 880, 50); // Sound at finish 42 delay(80); 43 tone(buzzerPin, 880, 80); 44 Serial.print("Final Time = "); // Display "Final Time = " 45 Serial.print(timerCount/1000); // Display timerCount in #.### format instead of milliseconds 46 Serial.println(" seconds"); // Display " sec." & newline 47 Serial.print("Speed = "); // Display "Speed = " 48 Serial.print(72/(timerCount/1000)); // Display speed based on 72 mm car 49 Serial.println(" mm/sec"); // Display "mm/sec" & newline 50 Serial.println(""); // print blank line 51 delay(3000); // wait 3 seconds and reset 52} 53 54float volts(int adPin) // Measures volts at adPin 55{ // Returns floating point voltage 56 return float(analogRead(adPin)) * 5.0 / 1024.0; 57} 58
Dual photogate code
arduino
Using two identical photogates to measure the speed of a Hot Wheels car going either direction. The code allows the photogates to work in either direction.
1/* PhototransistorVoltage Hot Wheels Timer 2 * Power each phototransistor with 5v and GND 3 * Connect the 2 phototransistors yellow wires 4 * into A1 & A2 to detect start and stop of car. 5 * Use a piezo buzzer connected to pin 4 and GND. 6 */ 7 8const int buzzerPin = 4; // other end of buzzer connected to GND 9float threshold = 0.25; // voltage where phototransistor shows car is in the way 10const int interval = 10; // accuracy of timer in milliseconds 11 12void setup() // Built-in initialization block 13{ 14 Serial.begin(9600); // Set data rate to 9600 bps 15} 16 17float v1, v2, timerCount; 18boolean v1trigger, waitFor2ndTrigger; 19int count=0; 20 21void loop() { 22 tone(buzzerPin, 440*6, 50); // Sound "ready" 23 timerCount = 0; 24 count = 0; 25 v1 = volts(A1); // measure voltage from phototransister in A1 26 v2 = volts(A2); // measure voltage from phototransister in A2 27 Serial.println("Waiting..."); // wait for either phototransistor to be dimmed 28 while (v1 > threshold && v2 > threshold) { 29 delay(interval); // otherwise it's too fast to notice button press 30 v1 = volts(A1); // measure voltage from phototransister in A1 31 v2 = volts(A2); // measure voltage from phototransister in A2 32 } 33 v1trigger = (v1 < threshold); // find which was triggered 34 Serial.println("Start"); // Display "Start" 35 tone(buzzerPin, 880, 150); // Sound for start of clock 36 v1 = volts(A1); 37 v2 = volts(A2); 38 waitFor2ndTrigger = true; // check only A1 phototransistor 39 40 while (waitFor2ndTrigger) { // count time until 2nd probe is triggered 41 delay(interval); // Delay for defined time 42 timerCount = timerCount+interval; 43 v1 = volts(A1); 44 v2 = volts(A2); 45 if (v1trigger) { 46 waitFor2ndTrigger = (v2 > threshold); // check A2 phototransistor 47 } 48 else { 49 waitFor2ndTrigger = (v1 > threshold); // check A1 phototransistor 50 } 51 } 52 53 // end timer count and display results 54 tone(buzzerPin, 880, 50); // Sound at finish 55 delay(80); 56 tone(buzzerPin, 880, 80); 57 Serial.print("Final Time = "); // Display "v Final Time = " 58 Serial.print(timerCount/1000); // Display timerCount in #.### format 59 Serial.println(" sec."); // Display " sec." & newline 60 Serial.println(""); // print blank line 61 delay(3000); // wait 3 seconds and reset 62} 63 64float volts(int adPin) // Measures volts at adPin 65{ // Returns floating point voltage 66 return float(analogRead(adPin)) * 5.0 / 1024.0; 67} 68
Single LED Photogate
arduino
Single photogate code for measuring of the speed of a single Hot Wheels car. The code allows the photogate to work in either direction.
1/* PhototransistorVoltage Hot Wheels Timer 2 * Power phototransistor 3 with 5v and GND 4 * Connect the phototransistors yellow wire into A1 5 * Optional: 6 Use a piezo buzzer connected to pin 4 and GND. 7 */ 8 9const int buzzerPin 10 = 4; // other end of buzzer connected to GND 11float threshold = 0.25; // voltage 12 where phototransistor shows car is in the way 13const int interval = 5; // accuracy 14 of timer in milliseconds 15 16void setup() // 17 Built-in initialization block 18{ 19 Serial.begin(9600); // 20 Set data rate to 9600 bps 21} 22 23float v1, timerCount; 24boolean waitFor2ndTrigger; 25 26void 27 loop() { 28 tone(buzzerPin, 440*6, 50); // Sound "ready" 29 30 timerCount = 0; 31 waitFor2ndTrigger = true; 32 v1 = volts(A1); // 33 measure voltage from phototransister in A1 34 tone(buzzerPin, 880, 150); // 35 Sound for start of waiting for trigger 36 Serial.println("Waiting for trigger..."); 37 // wait for phototransistor to be dimmed 38 while (v1 > threshold) { 39 40 delay(interval); // otherwise it's too fast to notice button 41 press ((when one is used) 42 v1 = volts(A1); // measure voltage 43 from phototransister in A1 44 } 45 Serial.print("Started..."); // 46 Display "Start" 47 48 while (waitFor2ndTrigger) { // count time 49 until phototransistor receives light again 50 delay(interval); // 51 Delay for defined time 52 timerCount = timerCount+interval; // Add time 53 to counter 54 v1 = volts(A1); // check A1 phototransistor 55 56 waitFor2ndTrigger = (v1 < threshold); // is "false" when phototransistor 57 receives light again 58 } 59 60 // end timer count and display results 61 62 Serial.println("Stopped"); // Display " sec." & newline 63 tone(buzzerPin, 64 880, 50); // Sound at finish 65 delay(80); 66 tone(buzzerPin, 880, 67 80); 68 Serial.print("Final Time = "); // Display "Final Time = " 69 70 Serial.print(timerCount/1000); // Display timerCount in #.### format 71 instead of milliseconds 72 Serial.println(" seconds"); // Display 73 " sec." & newline 74 Serial.print("Speed = "); // Display "Speed 75 = " 76 Serial.print(72/(timerCount/1000)); // Display speed based on 72 mm 77 car 78 Serial.println(" mm/sec"); // Display "mm/sec" & newline 79 80 Serial.println(""); // print blank line 81 delay(3000); 82 // wait 3 seconds and reset 83} 84 85float 86 volts(int adPin) // Measures volts at adPin 87{ // 88 Returns floating point voltage 89 return float(analogRead(adPin)) * 5.0 / 1024.0; 90} 91 92
Dual photogate code
arduino
Using two identical photogates to measure the speed of a Hot Wheels car going either direction. The code allows the photogates to work in either direction.
1/* PhototransistorVoltage Hot Wheels Timer 2 * Power each phototransistor with 5v and GND 3 * Connect the 2 phototransistors yellow wires 4 * into A1 & A2 to detect start and stop of car. 5 * Use a piezo buzzer connected to pin 4 and GND. 6 */ 7 8const int buzzerPin = 4; // other end of buzzer connected to GND 9float threshold = 0.25; // voltage where phototransistor shows car is in the way 10const int interval = 10; // accuracy of timer in milliseconds 11 12void setup() // Built-in initialization block 13{ 14 Serial.begin(9600); // Set data rate to 9600 bps 15} 16 17float v1, v2, timerCount; 18boolean v1trigger, waitFor2ndTrigger; 19int count=0; 20 21void loop() { 22 tone(buzzerPin, 440*6, 50); // Sound "ready" 23 timerCount = 0; 24 count = 0; 25 v1 = volts(A1); // measure voltage from phototransister in A1 26 v2 = volts(A2); // measure voltage from phototransister in A2 27 Serial.println("Waiting..."); // wait for either phototransistor to be dimmed 28 while (v1 > threshold && v2 > threshold) { 29 delay(interval); // otherwise it's too fast to notice button press 30 v1 = volts(A1); // measure voltage from phototransister in A1 31 v2 = volts(A2); // measure voltage from phototransister in A2 32 } 33 v1trigger = (v1 < threshold); // find which was triggered 34 Serial.println("Start"); // Display "Start" 35 tone(buzzerPin, 880, 150); // Sound for start of clock 36 v1 = volts(A1); 37 v2 = volts(A2); 38 waitFor2ndTrigger = true; // check only A1 phototransistor 39 40 while (waitFor2ndTrigger) { // count time until 2nd probe is triggered 41 delay(interval); // Delay for defined time 42 timerCount = timerCount+interval; 43 v1 = volts(A1); 44 v2 = volts(A2); 45 if (v1trigger) { 46 waitFor2ndTrigger = (v2 > threshold); // check A2 phototransistor 47 } 48 else { 49 waitFor2ndTrigger = (v1 > threshold); // check A1 phototransistor 50 } 51 } 52 53 // end timer count and display results 54 tone(buzzerPin, 880, 50); // Sound at finish 55 delay(80); 56 tone(buzzerPin, 880, 80); 57 Serial.print("Final Time = "); // Display "v Final Time = " 58 Serial.print(timerCount/1000); // Display timerCount in #.### format 59 Serial.println(" sec."); // Display " sec." & newline 60 Serial.println(""); // print blank line 61 delay(3000); // wait 3 seconds and reset 62} 63 64float volts(int adPin) // Measures volts at adPin 65{ // Returns floating point voltage 66 return float(analogRead(adPin)) * 5.0 / 1024.0; 67} 68
Downloadable files
1 photogate
Single photogate schematic
1 photogate
1 photogate
Single photogate schematic
1 photogate
2 photogates
Two photogates schematic
2 photogates
2 photogates
Two photogates schematic
2 photogates
Documentation
Photogate Holder
Holder for photogate parts that sits under a standard flexible Hot Wheels track.
Photogate Holder
Comments
Only logged in users can leave comments