RaylFX – Effects for model railroads and model making with Arduino Nano

RaylFX - Effects for model railroads and model making with Arduino Nano

The Miniature Wonderland in Hamburg really fascinated me. Of course, all the trains and tracks are already ingenious, but the real magic is the level of detail and not least the lighting and effects that are installed. And of course I wanted to recreate something like this with Arduino and make it available to you. I put special emphasis on customizability and ease of replication. I named the system RaylFX, because I want to expand it more and more in the future.

We need your consent to load the content of YouTube.

If you click on this video we will play the video, load scripts on your device, store cookies and collect personal data. This enables [Google Ireland Limited, Irland] to track activities on the Internet and to display advertising in a target group-oriented manner. There is a data transfer to the USA, which does not have EU-compliant data protection. You will find further information here.


The RaylFX System

I designed the RaylFX system in such a way that it consists of individual components which receive a common time via a central element, the control module, because, as with the Miniature Wonderland, it should become day and night with RaylFX after an adjustable time. This function is performed by a low-cost Arduino Nano, which sends a number from 0 to 23 to all modules in the system at adjustable intervals. These modules also use the Arduino Nano as a platform. Depending on the project (e.g. fairground, construction site, settlement, etc.) other components are integrated. Again, I have paid attention to simplicity and low cost, although both must please be seen in relation. Even though I tried to make the application as simple as possible, this is still a project for people with some experience in using Arduino. For this I recommend my e-book “Arduino für Anfänger und Anfängerinnen”. In it there are all the basics you need to get started.

Control Module – Wiring Diagram

RaylFX Control Module Arduino Model Railway Model Railway Wiring Diagram

The control module consists of an Arduino Nano whose pin D18 (A4) is connected to all other modules at pin D18. (The green cable in the picture is redundant.) In addition, there is a central power supply that connects all modules together (5V+ and GND).


Code for the RaylFX Control Module

The control module uses the TM1637 display library. This library must be installed first. For this go in the Arduino menu to Sketch>Include Library>Manage Libraries … and search for TM1637 in the search field. Install the current version of the TM1637 library from Avishay Orpaz.

This program must be loaded onto the control-module. To do this, the Arduino Nano must first be selected in the menu of the Arduino software under Tools>Board. Then you have to select under Tools>Processor “ATmega328P (Old Bootloader)” and last under Tools>Port the port where the Arduino Nano is connected.

     RaylFX Control Module 

#include <TM1637Display.h>

/* ***** ***** Settings ***** ***** ***** *****  ***** ***** ***** *****  ***** ***** ***** ***** */

long theTimeout = 6;  // duration of one model city hour in seconds (minimum approx. 6)

/* ***** ***** From here begins the program code, which does not need to be adjusted ***** ***** ***** ***** */

int sendPin = 18;
long theTimer = 0;
int hours = 19;
int minutes = 50;

/* ***** ***** Segment Display ***** ***** */
#define numberOfSeconds(_time_) ((_time_ / 1000) % 60)
#define numberOfMinutes(_time_) (((_time_ / 1000) / 60) % 60)

/* Control Module */

#define NODE_MAX_NUMBER 127
#define PAYLOAD_SIZE 2

TM1637Display display(2, 3);                      // segment display at D2 and D3

void setup() {
  // Set brightness
void loop() {
  if (theTimer + ((theTimeout)*1000/60) < millis()) {
    theTimer = millis();
    if (minutes >= 60) {
      minutes = 0;
      if (hours >= 24) hours = 0;


  showTime(hours, minutes);  // output on segment display

void sendData() {
  for (int i=0; i<24; i++){
    if (hours>=i) digitalWrite(sendPin, LOW);
    digitalWrite(sendPin, HIGH);

/* Segment Display */
void showTime(int theHour, int theMinute) {
  display.showNumberDecEx(theMinute, 0, true, 2, 2);
  display.showNumberDecEx(theHour, 0b01000000, true, 2, 0);

In the code, in the settings section, you can now determine how many seconds (theTimeout) in the real world should correspond to one hour in the model world.

After setting it up, you can just transfer the code to the Arduino nano and that’s it.