Components and supplies
RAM Track 111 or 117 Dual Optical Detector PCB
Sound Replay PCB
DFRobot 4 Relay Shield
Arduino UNO
LED Flasher PCB
9 volt Power Supply
Screw Terminal Shield
Project description
Code
Capreol Museum Rail / Road Crossing Controller
arduino
1// set pin numbers: 2const int buttonAPin = A1; // the number of the pushbutton pins 3const int buttonBPin = A2; 4 5const int ledPin = 13; // the number of the LED pin 6const int RelayA = 2; // the number of the relay coil drive pin 7const int RelayB = 3; 8const int RelayC = 11; 9 10// Define Variables 11int buttonAState = HIGH; 12int lastButtonAState = HIGH; 13 14int RUNNING = LOW; 15int OCCUPIED = LOW; 16 17int buttonBState=HIGH; 18int lastButtonBState = HIGH; 19 20 21// the following variables are long's because the time, measured in miliseconds, 22// will quickly become a bigger number than can be stored in an int. 23 24unsigned long lastDebounceTimeA = 0; 25unsigned long lastDebounceTimeB = 0; 26 27unsigned long debounceDelay = 50; 28unsigned long loopdelayA = 500; 29unsigned long looptriggerA; 30unsigned long loopdelayB = 500; 31unsigned long looptriggerB; 32unsigned long RUNNINGtime = 3000; 33unsigned long RUNNINGtrigger; 34 35#include <LiquidCrystal.h> 36 37// Select the pin used on LCD 38LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 39 40void setup() { 41 42 lcd.begin(16, 2); 43 lcd.setCursor(0, 0); 44 lcd.print("KEVino 2017"); 45 lcd.setCursor(0, 1); 46 lcd.print("RAILCROSS"); 47 delay(1000); 48 // scroll 16 positions (string length) to the left 49 // to move it offscreen left: 50 for (int positionCounter = 0; positionCounter < 16; positionCounter++) { 51 // scroll one position left: 52 lcd.scrollDisplayRight(); 53 // wait a bit: 54 delay(30); 55 } 56 { 57 lcd.begin(16, 2); 58 lcd.setCursor(0, 0); 59 lcd.print("Railcross"); 60 } 61 Serial.begin(9600); 62 63 pinMode(ledPin, OUTPUT); 64 pinMode(RelayA, OUTPUT); 65 pinMode(buttonAPin, INPUT_PULLUP); 66 pinMode(RelayB, OUTPUT); 67 pinMode(buttonBPin, INPUT_PULLUP); 68 pinMode(RelayC, OUTPUT); 69 70} 71 72void debounceA() 73{ 74 int readingA = digitalRead(buttonAPin); 75 76 if (readingA != lastButtonAState) 77 { 78 lastDebounceTimeA = millis(); 79 looptriggerA = millis(); 80 } 81 if ((millis() - lastDebounceTimeA) > debounceDelay) 82 { 83 if (readingA != buttonAState) 84 { 85 buttonAState = readingA; 86 } 87 } 88 lastButtonAState = readingA; 89 lastDebounceTimeA = 0; 90 return; 91} 92 93void debounceB() // Debounce A2 input 94{ 95 int readingB = digitalRead(buttonBPin); 96 97 if (readingB != lastButtonBState) 98 { 99 lastDebounceTimeB = millis(); 100 looptriggerB = millis(); 101 } 102 if ((millis() - lastDebounceTimeB) > debounceDelay) 103 { 104 if (readingB != buttonBState) 105 { 106 buttonBState = readingB; 107 } 108 } 109 lastButtonBState = readingB; 110 lastDebounceTimeB = 0; 111 return; 112} 113 114void START() // 1/2 second pulse on Relay A, 115{ // RUNNING set HIGH,, Relay C set. 116 RUNNINGtrigger = millis(); 117 digitalWrite(RelayA, HIGH); 118 digitalWrite(RelayC, HIGH); 119 delay (500); 120 digitalWrite(RelayA, LOW); 121 RUNNING = HIGH; 122} 123void STOP() // 1/2 second pulse on Relay B, 124{ // RUNNING set LOW,, Relay C cleared. 125 RUNNINGtrigger = millis(); 126 digitalWrite(RelayB, HIGH); 127 digitalWrite(RelayC, LOW); 128 delay (500); 129 digitalWrite(RelayB, LOW); 130 RUNNING = LOW; 131 132} 133 134void loop() 135{ 136 lcd.setCursor(13, 0); // Display seconds elapsed 137 lcd.print(millis() / 1000); 138 139 140 debounceA(); //Debounce the sensor inputs 141 debounceB(); 142 digitalWrite(ledPin, OCCUPIED); // Use LED to indicate OCCUPIED 143 144 if (buttonAState == LOW || buttonBState == LOW) 145 { 146 OCCUPIED = HIGH; 147 RUNNINGtrigger = millis(); 148 Serial.write("OCCUPIED"); 149 Serial.println(); 150 lcd.setCursor(0, 1); 151 lcd.print("Occupied"); 152 } 153 else 154 { 155 OCCUPIED = LOW; 156 lcd.setCursor(0, 1); 157 lcd.print(" "); 158 } 159 160 if (OCCUPIED == HIGH && RUNNING == LOW) 161 { 162 START(); 163 Serial.write("START"); 164 Serial.println(); 165 lcd.setCursor(8, 1); 166 lcd.print("RUNNING"); 167 } 168 169 if (RUNNING == HIGH) 170 if ((millis() - RUNNINGtrigger) > RUNNINGtime) 171 { 172 STOP(); 173 Serial.write("STOP"); 174 Serial.println(); 175 lcd.setCursor(8, 1); 176 lcd.print(" "); 177 } 178 179} 180 181 182 183 184 185 186
Capreol Museum Rail / Road Crossing Controller
arduino
1// set pin numbers: 2const int buttonAPin = A1; // the number of the pushbutton pins 3const int buttonBPin = A2; 4 5const int ledPin = 13; // the number of the LED pin 6const int RelayA = 2; // the number of the relay coil drive pin 7const int RelayB = 3; 8const int RelayC = 11; 9 10// Define Variables 11int buttonAState = HIGH; 12int lastButtonAState = HIGH; 13 14int RUNNING = LOW; 15int OCCUPIED = LOW; 16 17int buttonBState=HIGH; 18int lastButtonBState = HIGH; 19 20 21// the following variables are long's because the time, measured in miliseconds, 22// will quickly become a bigger number than can be stored in an int. 23 24unsigned long lastDebounceTimeA = 0; 25unsigned long lastDebounceTimeB = 0; 26 27unsigned long debounceDelay = 50; 28unsigned long loopdelayA = 500; 29unsigned long looptriggerA; 30unsigned long loopdelayB = 500; 31unsigned long looptriggerB; 32unsigned long RUNNINGtime = 3000; 33unsigned long RUNNINGtrigger; 34 35#include <LiquidCrystal.h> 36 37// Select the pin used on LCD 38LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 39 40void setup() { 41 42 lcd.begin(16, 2); 43 lcd.setCursor(0, 0); 44 lcd.print("KEVino 2017"); 45 lcd.setCursor(0, 1); 46 lcd.print("RAILCROSS"); 47 delay(1000); 48 // scroll 16 positions (string length) to the left 49 // to move it offscreen left: 50 for (int positionCounter = 0; positionCounter < 16; positionCounter++) { 51 // scroll one position left: 52 lcd.scrollDisplayRight(); 53 // wait a bit: 54 delay(30); 55 } 56 { 57 lcd.begin(16, 2); 58 lcd.setCursor(0, 0); 59 lcd.print("Railcross"); 60 } 61 Serial.begin(9600); 62 63 pinMode(ledPin, OUTPUT); 64 pinMode(RelayA, OUTPUT); 65 pinMode(buttonAPin, INPUT_PULLUP); 66 pinMode(RelayB, OUTPUT); 67 pinMode(buttonBPin, INPUT_PULLUP); 68 pinMode(RelayC, OUTPUT); 69 70} 71 72void debounceA() 73{ 74 int readingA = digitalRead(buttonAPin); 75 76 if (readingA != lastButtonAState) 77 { 78 lastDebounceTimeA = millis(); 79 looptriggerA = millis(); 80 } 81 if ((millis() - lastDebounceTimeA) > debounceDelay) 82 { 83 if (readingA != buttonAState) 84 { 85 buttonAState = readingA; 86 } 87 } 88 lastButtonAState = readingA; 89 lastDebounceTimeA = 0; 90 return; 91} 92 93void debounceB() // Debounce A2 input 94{ 95 int readingB = digitalRead(buttonBPin); 96 97 if (readingB != lastButtonBState) 98 { 99 lastDebounceTimeB = millis(); 100 looptriggerB = millis(); 101 } 102 if ((millis() - lastDebounceTimeB) > debounceDelay) 103 { 104 if (readingB != buttonBState) 105 { 106 buttonBState = readingB; 107 } 108 } 109 lastButtonBState = readingB; 110 lastDebounceTimeB = 0; 111 return; 112} 113 114void START() // 1/2 second pulse on Relay A, 115{ // RUNNING set HIGH,, Relay C set. 116 RUNNINGtrigger = millis(); 117 digitalWrite(RelayA, HIGH); 118 digitalWrite(RelayC, HIGH); 119 delay (500); 120 digitalWrite(RelayA, LOW); 121 RUNNING = HIGH; 122} 123void STOP() // 1/2 second pulse on Relay B, 124{ // RUNNING set LOW,, Relay C cleared. 125 RUNNINGtrigger = millis(); 126 digitalWrite(RelayB, HIGH); 127 digitalWrite(RelayC, LOW); 128 delay (500); 129 digitalWrite(RelayB, LOW); 130 RUNNING = LOW; 131 132} 133 134void loop() 135{ 136 lcd.setCursor(13, 0); // Display seconds elapsed 137 lcd.print(millis() / 1000); 138 139 140 debounceA(); //Debounce the sensor inputs 141 debounceB(); 142 digitalWrite(ledPin, OCCUPIED); // Use LED to indicate OCCUPIED 143 144 if (buttonAState == LOW || buttonBState == LOW) 145 { 146 OCCUPIED = HIGH; 147 RUNNINGtrigger = millis(); 148 Serial.write("OCCUPIED"); 149 Serial.println(); 150 lcd.setCursor(0, 1); 151 lcd.print("Occupied"); 152 } 153 else 154 { 155 OCCUPIED = LOW; 156 lcd.setCursor(0, 1); 157 lcd.print(" "); 158 } 159 160 if (OCCUPIED == HIGH && RUNNING == LOW) 161 { 162 START(); 163 Serial.write("START"); 164 Serial.println(); 165 lcd.setCursor(8, 1); 166 lcd.print("RUNNING"); 167 } 168 169 if (RUNNING == HIGH) 170 if ((millis() - RUNNINGtrigger) > RUNNINGtime) 171 { 172 STOP(); 173 Serial.write("STOP"); 174 Serial.println(); 175 lcd.setCursor(8, 1); 176 lcd.print(" "); 177 } 178 179} 180 181 182 183 184 185 186
Downloadable files
Model Railroad Grade-crossing Controller
Model Railroad Grade-crossing Controller
Model Railroad Grade Crossing Controller
Model Railroad Grade Crossing Controller
Model Railroad Grade-crossing Controller
Model Railroad Grade-crossing Controller
Comments
Only logged in users can leave comments