Loading...
Loading...
// Basic crossing signal - alternating LEDs
const int LED1 = 2;
const int LED2 = 3;
const int SENSOR = 4;
void setup() {
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(SENSOR, INPUT);
}
void loop() {
if (digitalRead(SENSOR) == LOW) {
// Train detected - flash lights
digitalWrite(LED1, HIGH);
digitalWrite(LED2, LOW);
delay(500);
digitalWrite(LED1, LOW);
digitalWrite(LED2, HIGH);
delay(500);
} else {
// No train - lights off
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.