Loading...
Loading...
// Grade Crossing Flasher
const int IR_SENSOR = 2;
const int LED1 = 3;
const int LED2 = 4;
const int FLASH_DELAY = 500;
void setup() {
pinMode(IR_SENSOR, INPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
}
void loop() {
if (digitalRead(IR_SENSOR) == LOW) { // Train detected
digitalWrite(LED1, HIGH);
digitalWrite(LED2, LOW);
delay(FLASH_DELAY);
digitalWrite(LED1, LOW);
digitalWrite(LED2, HIGH);
delay(FLASH_DELAY);
} else {
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
}
}This is starter code - modify and expand for your specific needs.
Before building this project, make sure you have the Arduino IDE installed and are comfortable uploading basic sketches to your board.
Most projects use standard Arduino libraries. Some may require additional libraries like AccelStepper, Servo, or NmraDcc - install these through the Arduino Library Manager.