This project uses an Arduino Uno and IR sensors to detect who wins a pine wood derby car race.
The schematic and Arduino code can be found below.
/*
Electrnic line judge
*/
const int statled = 11; // the number of the LED pin
const int lane1 = 6;
const int lane2 = 7;
const int camera_trigger = 2;
const int lane1sense = 8;
const int lane2sense = 9;
int State = 0; // variable for reading the pushbutton status.
int L1=1, L2=1; //active low for the beam sensor.
void setup() {
pinMode(statled, OUTPUT);//running LED
pinMode(lane1,OUTPUT);//hight is when the light is broken
pinMode(lane2,OUTPUT);//hight is when the light is broken
pinMode(camera_trigger, OUTPUT);
pinMode(lane1sense,INPUT);
pinMode(lane2sense,INPUT);
//Ready output
digitalWrite(lane1,HIGH);//Yellow LED
digitalWrite(lane2,HIGH);//Blue LED
delay(250);
digitalWrite(lane1,LOW);
digitalWrite(lane2,LOW);
}
void loop(){
digitalWrite(statled, HIGH);
L1=digitalRead(lane1sense);
L2=digitalRead(lane2sense);
if((1==L1) or (1==L2)){
//somebody won the race
digitalWrite(camera_trigger,HIGH);
if(1==L1){
//lane 1 won
digitalWrite(lane1,HIGH);
}
if(1==L2){
//lane 2 won
digitalWrite(lane2,HIGH);
}
delay(500);
digitalWrite(camera_trigger,LOW);
delay(10000);
digitalWrite(lane1,LOW);
digitalWrite(lane2,LOW);
}
digitalWrite(statled, LOW);
}