Hello everybody,
I am very new to Arduino world and I have only just started learning it for a rather specific reason. I am wanting to create a sketch that will operate Drag racing staging lights. I have so far written below sketch and have a little prototype working on tinkercad circuit whilst I'm waiting for Arduino controller to come in mail.
Now, I would like to expand this sketch in a way where I will have a second Arduino with 2 more sonar sensors connected to my first Arduino. I would like it to capture time from when green lights light up on Arduino 1 and trigger the sonar sensors on Arduino 2. In effect showing me time spent of an object traveling between Arduino 1 and 2.
From what I understand I could somehow use Millis() for this, however I am unsure how to get Millis() synced over 2 Arduino controllers?
Any help you could provide me would be greatly appreciated and needed as I am currently out of ideas and am unsure of what to research to get the right answers.
!
/* Pin allocation */
#define stageLEDL A5 //Left staging light
#define stageLEDR 5 //Right staging light
#define yellow1 A4 //first yellow row
#define yellow2 2 //second yellow row
#define yellow3 3 //third yellow row
#define greenLEDR 4 //green left go light
#define greenLEDL A3 //green right go light
#define TRIGGERLS_PIN 8 //for left staging sensor
#define ECHOLS_PIN 9 //for left staging sensor
#define TRIGGERRS_PIN 12 //for left staging sensor
#define ECHORS_PIN 13 //for left staging sensor
#define SWITCH_PIN 11 //switch pic alocation
int echoTimeLS; //time in us
int distanceLS; //distance in mms
int echoTimeRS; //time in us
int distanceRS; //distance in mms
void setup()
{
/* Pin I/O allocation */
//Serial.begin(9600);
pinMode(SWITCH_PIN, INPUT);
//LEDS
pinMode(stageLEDL, OUTPUT);
pinMode(stageLEDR, OUTPUT);
pinMode(yellow1, OUTPUT);
pinMode(yellow2, OUTPUT);
pinMode(yellow3, OUTPUT);
pinMode(greenLEDR, OUTPUT);
pinMode(greenLEDL, OUTPUT);
//Staging Sensors
pinMode(TRIGGERLS_PIN, OUTPUT);
pinMode(ECHOLS_PIN, INPUT);
digitalWrite(TRIGGERLS_PIN, LOW); //set trigger pin LOW - idle state
pinMode(TRIGGERRS_PIN, OUTPUT); //same as above but for right staing sensor
pinMode(ECHORS_PIN, INPUT);
digitalWrite(TRIGGERRS_PIN, LOW);
}
void loop()
{
stagingSensors();
if (digitalRead(SWITCH_PIN) == HIGH)
{
//LEDS
if (digitalRead(stageLEDL) == HIGH && (digitalRead(stageLEDR) == HIGH))
{
delay(3000); //staging lights delay
digitalWrite(yellow1, HIGH); //first yellow row on and off
delay(1000);
digitalWrite(yellow1, LOW);
digitalWrite(yellow2, HIGH); //second yellow row on and off
delay(1000);
digitalWrite(yellow2, LOW);
digitalWrite(yellow3, HIGH); //third yellow row on and off
delay(1000);
digitalWrite(yellow3, LOW);
stagingSensors();
if (digitalRead(stageLEDL) == HIGH )
{
digitalWrite(greenLEDL, HIGH); //green left go lights on
}
if (digitalRead(stageLEDR) == HIGH )
{
digitalWrite(greenLEDR, HIGH); //green left go lights on
}
delay(2000);
digitalWrite(greenLEDL, LOW);
digitalWrite(greenLEDR, LOW);
digitalWrite(stageLEDL, LOW);
digitalWrite(stageLEDR, LOW);
}
}
}
/* This is staging sensors left and right constant check function */
void stagingSensors()
{
/* Left lane staging sensor */
digitalWrite(TRIGGERLS_PIN, HIGH); //send trigger pulse
delayMicroseconds(10);
digitalWrite(TRIGGERLS_PIN, LOW);
echoTimeLS = pulseIn(ECHOLS_PIN, HIGH); //capture the echo signal and determine duration of pulse when HIGH
distanceLS = (echoTimeLS*0.034*10)/2; //obtain distance (in mm), from time
/* Right lane staging sensor */
digitalWrite(TRIGGERRS_PIN, HIGH); //send trigger pulse
delayMicroseconds(10);
digitalWrite(TRIGGERRS_PIN, LOW);
echoTimeRS = pulseIn(ECHORS_PIN, HIGH); //capture the echo signal and determine duration of pulse when HIGH
distanceRS = (echoTimeRS*0.034*10)/2; //obtain distance (in mm), from time
/* Distance sensitivity of the sonar sensors in mm */
if (distanceLS >= 200 && distanceLS <=2000)
{
digitalWrite(stageLEDL, HIGH);
} else {
digitalWrite(stageLEDL, LOW);
}
if (distanceRS >= 200 && distanceRS <=2000)
{
digitalWrite(stageLEDR, HIGH);
} else {
digitalWrite(stageLEDR, LOW);
}
}