I bought a set of rail road crossing lights that came of from Laketon Ave in Muskegon, MI. I used an Arduino to control 4 relays. Each relay controlled six suport bright white LED's. I also had a PIR to trigger the LED's. I ran this all of a 12 volts. The only bad thing was that the LED's did not show up during the day as I would have hoped. I used relays so I can change this at any point.
One challenge was using the IRQ. What I discovered was that if I did not turn off the IRQ during the light sequence, the lights would never turn off. So I would turn off the IRQ during the light sequence and turned them back on after it had ran.
I also had the lights run one timely bases. I would keep track of time. I would use an unsigned long and it would buffer over run after about 71 minutes. I would run the lights sequence four times during that time. So the lights would run even if the PIR did not trigger them.
Here is the video during the night.
Here is the source code:
/************************************ This code is to run my rail road crossing lights. It has a PIR to turn on the lights. I have 4 lights. I am controlling the LED's in the RR lights by relays. Each RR light has 6 LED's. I am using Interrupt to turn on lights from PIR. ************************************/ // pins for LED's/Relays int rrLight1 = 3; int rrLight2 = 4; int rrLight3 = 5; int rrLight4 = 6; int pir = 2; volatile byte flag_bit = LOW; // declare IRQ flag // used to keep track of running time // run the lights every 71 minutes unsigned long time; unsigned long seconds; unsigned long minutes; int onTime = 1000; // this is how long the lights stay on int LED = 13; // used for testing void setup() { // used for testing Serial.begin(9600); pinMode(LED,OUTPUT); // setup for Relays/LED's pinMode(rrLight1,OUTPUT); pinMode(rrLight2,OUTPUT); pinMode(rrLight3,OUTPUT); pinMode(rrLight4,OUTPUT); // setup for PIR Interrupt pinMode(pir,INPUT); digitalWrite(pir,1); attachInterrupt(0, flag, LOW); // interrupt 0 is Arduino digital pin 2 connected to PIR } void loop(){ // this is used to run the lights program every 71 minutes. time = micros(); // get current run time seconds = time/1000000; minutes = seconds/60; // used for testing Serial.print("Time: "); Serial.print(seconds); Serial.print(" seconds : "); Serial.print(minutes); Serial.print(" minutes : "); Serial.println(time); if (seconds 1065 && seconds < 1075) || (seconds > 2130 && seconds < 2140) || (seconds > 3190 && seconds < 3200)) { //if (seconds