An arrival and departure board can be seen at various different train stations and show trains that are coming and going from the station. Here, I use an I2C LCD board to recreate this. Arrival and departure times are randomly generated, along with a randomly generated train name. This project is one of the simpler ones I have and can be easily replicated and modified.
LCD w/ I2C Attachment
Arduino (Mega/Uno)
Extra Male to Female Wires
LCD Case (Optional)
GND on LCD to GND on Arduino
VCC on LCD to 5v/3.3v on Arduino
SDA on LCD to Analog 4 on Arduino
SCL on LCD to Analog 5 on Arduino
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x3F for a 16 chars and 2 line display
int delayTime = 6000; //time to delay between departure messages and arrival messages
int scrollTime = 3000; //time to delay between displaying messages and scrolling messages
int move_length = 0;
String message = "";
String train = "";
int rand_time = random(0, 8);
int rand_train = random(0, 3);
int loops = 1;
void setup() {
Serial.begin(9600);
if (rand_train == 0) {
train = "BNSF 3000";
} else if (rand_train == 1) {
train = "CSX 9019";
} else {
train = "B&P 1508";
}
lcd.begin();
lcd.clear();
lcd.backlight(); // Make sure backlight is on
// Print a message on both lines of the LCD.
lcd.setCursor(2,0); //Set cursor to character 2 on line 0
lcd.print("Departure and");
lcd.setCursor(2,1); //Move cursor to character 2 on line 1
lcd.print("Arrival Board");
delay(2000);
lcd.clear();
}
void loop() {
lcd.setCursor(1,0);
lcd.print("Train Arrivals");
lcd.setCursor(0,1);
message = (String(rand_time))+" min: "+(train)+" - Coming South";
move_length = message.length() - 16;
lcd.print(message);
delay(scrollTime);
for (int s = 0; s <= move_length; s++) {
lcd.scrollDisplayLeft();
delay(100);
}
delay(delayTime);
for (int s = 0; s <= move_length; s++) {
lcd.scrollDisplayRight();
delay(100);
}
delay(scrollTime);
lcd.clear();
lcd.setCursor(3,0);
lcd.print("Departures");
lcd.setCursor(0,1);
message = (String(rand_time+2))+" min: "+(train)+" - Going North";
move_length = message.length() - 16;
lcd.print(message);
delay(scrollTime);
for (int s = 0; s <= move_length; s++) {
lcd.scrollDisplayLeft();
delay(100);
}
delay(delayTime);
for (int s = 0; s <= move_length; s++) {
lcd.scrollDisplayRight();
delay(100);
}
delay(scrollTime);
if (millis() >= (60000 * loops)) {
Serial.println("Randomizing...");
int rand_time = random(0, 8);
int rand_train = random(0, 3);
if (rand_train == 0) {
train = "BNSF 3000";
} else if (rand_train == 1) {
train = "CSX 9019";
} else {
train = "B&P 1508";
}
loops++;
} else {
Serial.println(millis());
}
}
If your LCD has longer rows, you can change the rand_time variable parameters to something bigger. When using random(), the first parameter is the minimum value and the second parameter is one less than the maximum value. For the rand_train variable, I use three different engine names. You can add more options, and change them up. Remember that this is for a 16x2 LCD. If you have a different LCD, line 3 of your code should look like LiquidCrystal_I2C lcd(0x27, columns, rows);, changing the words columns and rows to the amount of columns and rows your LCD has.
If you do not have an I2C LCD, I will be making another tutorial later in the future for using a normal 16x2 LCD.