Good day, I Need help I am busy building a small scale Drag Timing System for a hobby and I am struggling with coding I will share my code and image of my system.
What It should do is
Detect a Car Pre-stage(Photosensor) light up an led
Detect a Car Stage(PhotoSensor) Light up an led
When a start button is pressed initiate a countdown and light up an led every 500 mill
Yellow
Yellow
Yellow
Green
If the vehicle moves before green red light and nothing should happen after that
if the vehicle moves on or after green start a timer and stop it when the vehicle reaches the finish line
a reaction time from when vehicle left to when the green led was lit up if he left before green a negative reaction time should be available.
From when the vehicle left the beam to the finish the running time should be displayed on a lcd and when the vehicle reaches the finish line the ET (Elapsed time and reaction time should be displayed.) (Later on I would like to add distance to calculate the speed the vehicle was traveling) This is how far I came but I can not program for the life of me I can build the system but I am not a programer and need help.
#include <LiquidCrystal.h>
const int RS = 8;
const int EN = 9;
const int D4 = 10;
const int D5 = 11;
const int D6 = 12;
const int D7 = 13;
const int BAUD_RATE = 9600;
const int LED_Prestage = 2;
const int LED_Stage = 3;
const int LED_Y1 = 4;
const int LED_Y2 = 6;
const int LED_Y3 = 7;
const int LED_Start = A2;
const int LED_RED_Light =A3;
const int Pre_Stage_Sensor = A0;
const int Stage_Sensor = A1;
const int Finish_Sensor = A4;
const int Start_Button = 5;
const String (MESSAGE) = "System Ready.";
LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);
void setup() {
pinMode(LED_Prestage,OUTPUT);
pinMode(LED_Stage,OUTPUT);
pinMode(LED_Y1,OUTPUT);
pinMode(LED_Y2,OUTPUT);
pinMode(LED_Y3,OUTPUT);
pinMode(LED_Start,OUTPUT);
pinMode(LED_RED_Light,OUTPUT);
pinMode(Pre_Stage_Sensor,INPUT);
pinMode(Stage_Sensor,INPUT);
pinMode(Finish_Sensor,INPUT);
pinMode(Start_Button,INPUT_PULLUP);
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(0, 1);
lcd.print(MESSAGE);
delay(2000);
lcd.clear();
}
void loop() {
int Pre_Stage_Sensor_Value = analogRead(Pre_Stage_Sensor);
int Stage_Sensor_Value = analogRead(Stage_Sensor);
boolean StartFlag = true;
if (Pre_Stage_Sensor_Value < 500) {
digitalWrite(LED_Prestage, HIGH);
} else {
digitalWrite(LED_Prestage, LOW);
}
if (Stage_Sensor_Value < 500) {
digitalWrite(LED_Stage, HIGH);
} else {
digitalWrite(LED_Stage, LOW);
}
if ((Pre_Stage_Sensor_Value <500) && (Stage_Sensor_Value <500)) {
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Vehicle Staged");
delay(500);
} else {
lcd.clear();
lcd.begin(16,2);
lcd.setCursor(0,1);
lcd.print("Please Stage");
delay(500);
}
if ((Stage_Sensor_Value < 500) && (digitalRead(Start_Button) == LOW)) {
delay (500);
digitalWrite (LED_Y1, HIGH);
delay (500);
digitalWrite (LED_Y1, LOW);
digitalWrite (LED_Y2, HIGH);
delay (500);
digitalWrite (LED_Y2, LOW);
digitalWrite (LED_Y3, HIGH);
delay (500);
digitalWrite (LED_Y3, LOW);
digitalWrite (LED_Start, HIGH);
StartFlag = true; // set StartFlag to true
}
else if (Stage_Sensor_Value > 500) { // check if the car has left the stage
digitalWrite(LED_Start, LOW);
StartFlag = false;
}
if (StartFlag == false) {
digitalWrite(LED_RED_Light, HIGH);
} else {
digitalWrite(LED_RED_Light, LOW);
}
}