{"id":435,"date":"2021-02-23T10:55:55","date_gmt":"2021-02-23T10:55:55","guid":{"rendered":"https:\/\/starthardware.org\/en\/?p=435"},"modified":"2021-03-27T14:25:03","modified_gmt":"2021-03-27T14:25:03","slug":"raylfx-fair-module","status":"publish","type":"post","link":"https:\/\/starthardware.org\/en\/raylfx-fair-module\/","title":{"rendered":"RaylFX \u2013 Fair Module"},"content":{"rendered":"\n<p>The first module of the <a href=\"https:\/\/starthardware.org\/en\/raylfx-effects-for-model-railroads-and-model-making-with-arduino-nano\/\" target=\"_blank\" rel=\"noreferrer noopener\">RaylFX series<\/a> is the Fair module. These are various effects that you can expect to see at a fair:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Ferris Wheel<\/li><li>Carousel<\/li><li>Running light<\/li><li>Street lights<\/li><li>Stroboscope<\/li><li>Sound module<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Video \u2013 RaylFX Fair Module<\/h2>\n\n\n\n<figure class=\"wp-block-embed aligncenter is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<div class=\"sp-dsgvo sp-dsgvo-embedding-container sp-dsgvo-embedding-youtube \"><div class=\"sp-dsgvo-blocked-embedding-placeholder sp-dsgvo-blocked-embedding-placeholder-youtube\">  <div class=\"sp-dsgvo-blocked-embedding-placeholder-header\"><img decoding=\"async\" class=\"sp-dsgvo-blocked-embedding-placeholder-header-icon\" src=\"https:\/\/starthardware.org\/en\/wp-content\/plugins\/shapepress-dsgvo\/public\/images\/embeddings\/icon-youtube.svg\"\/>We need your consent to load the content of YouTube.<\/div>  <div class=\"sp-dsgvo-blocked-embedding-placeholder-body\"><p>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 <a target=\"_blank\" href=\"#\" class=\"sp-dsgvo-navigate-privacy-policy\">here<\/a>.<\/p>   <div class=\"sp-dsgvo-blocked-embedding-button-container\"> <a href=\"#\" class=\"sp-dsgvo-direct-enable-popup sp-dsgvo-blocked-embedding-button-enable\" data-slug=\"youtube\">Click here to enable this content.<\/a><\/div>  <\/div><\/div><div class=\"sp-dsgvo-hidden-embedding-content sp-dsgvo-hidden-embedding-content-youtube\" data-sp-dsgvo-embedding-slug=\"youtube\">Jmx0O2RpdiBjbGFzcz0mcXVvdDtudi1pZnJhbWUtZW1iZWQmcXVvdDsmZ3Q7Jmx0O2lmcmFtZSB0aXRsZT0mcXVvdDtSYXlsRlggSmFocm1hcmt0ICZuZGFzaDsgRWZmZWt0ZSBmJnV1bWw7ciBNb2RlbGxiYWhuIHVuZCBNb2RlbGxiYXUgbWl0IEFyZHVpbm8mcXVvdDsgd2lkdGg9JnF1b3Q7MTIwMCZxdW90OyBoZWlnaHQ9JnF1b3Q7Njc1JnF1b3Q7IHNyYz0mcXVvdDtodHRwczovL3d3dy55b3V0dWJlLmNvbS9lbWJlZC9kcGJ2RjV3WHo5ND9mZWF0dXJlPW9lbWJlZCZxdW90OyBmcmFtZWJvcmRlcj0mcXVvdDswJnF1b3Q7IGFsbG93PSZxdW90O2FjY2VsZXJvbWV0ZXI7IGF1dG9wbGF5OyBjbGlwYm9hcmQtd3JpdGU7IGVuY3J5cHRlZC1tZWRpYTsgZ3lyb3Njb3BlOyBwaWN0dXJlLWluLXBpY3R1cmUmcXVvdDsgYWxsb3dmdWxsc2NyZWVuJmd0OyZsdDsvaWZyYW1lJmd0OyZsdDsvZGl2Jmd0Ow==<\/div><\/div>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Components<\/h2>\n\n\n\n<p>These are the components I used:<\/p>\n\n\n\n<ul class=\"wp-block-list\" id=\"block-9d6c53bd-a1ab-4f6c-b036-b84b50ecc391\"><li><a rel=\"noreferrer noopener\" href=\"https:\/\/amzn.to\/3mSDyrO\" target=\"_blank\">Arduino Nano<\/a>*<\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/amzn.to\/3lSYPAy\" target=\"_blank\">Breadboard<\/a>*<\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/amzn.to\/37MqeyK\" target=\"_blank\">Jumper wires<\/a>*<\/li><li><a href=\"https:\/\/amzn.to\/3prCcpv\" target=\"_blank\" rel=\"noreferrer noopener\">Ribbon jumper wires<\/a>* to pull apart<\/li><li><a href=\"https:\/\/amzn.to\/3jCHX1v\" target=\"_blank\" rel=\"noreferrer noopener\">Stepper motors and driver boards*<\/a><\/li><li><a href=\"https:\/\/amzn.to\/2Y7zObl\" target=\"_blank\" rel=\"noreferrer noopener\">LEDs<\/a>*<\/li><li><a href=\"https:\/\/amzn.to\/3ofDLVO\" target=\"_blank\" rel=\"noreferrer noopener\">DFPlayer-Mini<\/a>* MP3 player module<\/li><li><a href=\"https:\/\/amzn.to\/3a1OyxQ\" target=\"_blank\" rel=\"noreferrer noopener\">Speaker<\/a>*<\/li><li>1x 1kOhm resistor<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Wiring Diagram<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><a href=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module-3-wiring-diagram2.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"544\" src=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module-3-wiring-diagram2-1024x544.jpg\" alt=\"RaylFX fairground carousel wiring diagram with Arduino Nano for model making model railroad\" class=\"wp-image-466\" srcset=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module-3-wiring-diagram2-1024x544.jpg 1024w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module-3-wiring-diagram2-300x159.jpg 300w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module-3-wiring-diagram2-768x408.jpg 768w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module-3-wiring-diagram2.jpg 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>Like all RaylFX modules the fairground module needs connections to the control module (Of these you need only one module in the whole system!). This is a connection of all A4 pins (this pin is used as digital input 18) and a connection to the power supply (5V+ and GND).<\/p>\n\n\n\n<p>Attention: The control signal of the <a href=\"https:\/\/starthardware.org\/en\/raylfx-effects-for-model-railroads-and-model-making-with-arduino-nano\/\" target=\"_blank\" rel=\"noreferrer noopener\">RaylFX control module<\/a> is applied to pin A4. It controls the time of day and is mandatory to synchronize all modules.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module-overview-1024x768-1.jpg\" alt=\"RaylFX effects for model railroad and model making with Arduino Nano fairground module overview\" class=\"wp-image-469\" srcset=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module-overview-1024x768-1.jpg 1024w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module-overview-1024x768-1-300x225.jpg 300w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module-overview-1024x768-1-768x576.jpg 768w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module-overview-1024x768-1-500x375.jpg 500w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The Ferris wheel and carousel are two stepper motors that drive the models of the respective rides. Both stepper motors are controlled by one stepper motor driver each.<\/p>\n\n\n\n<p>The LEDs for the running lights, the street lights and the strobe are each connected to digital Arduino pins via a series resistor. The resistor limits the current flow. If you need more LEDs you can simply connect them in parallel after the resistor. They will then all shine less brightly. Surely there is a maximum of LEDs you can connect like this. I don&#8217;t have an exact number. I recommend to simply try it out. <\/p>\n\n\n\n<p>If you need many more LEDs, you should amplify the channels. This can be achieved e.g. with a ULN2803A Darlington transistor array.<\/p>\n\n\n\n<p>The DFPlayer Mini is used for the sound output. It plays MP3 and WAV files from an SD card. The SD card must be formatted in the FAT16 or FAT32 file system. In addition, the files must be in the folder &#8220;01&#8221; and the file names must be sequentially named 001.mp3, 002.mp3, 003.mp3, and so on. As mentioned, WAV files may also be used: 001.mp3, 002.wav, 003.mp3 \u2026<\/p>\n\n\n\n<p>Since the stepper motors need a lot of power and therefore can interfere with the DFPlayer, you can put a backup capacitor (100uF) in the power rails near the driver boards.<\/p>\n\n\n\n<p>The operation site module uses the <em>DFRobotDFPlayerMini<\/em>, and the <em>CheapStepper <\/em>library. These libraries must be installed first. For this go in the Arduino menu to Sketch>Include Library>Manage Libraries \u2026 and search for <em>DFRobotDFPlayerMini<\/em> in the search field. Install the current version of the <em>DFRobotDFPlayerMini<\/em> library from <em>DFRobot<\/em> and then search for, and install the <em>CheapStepper<\/em> library by <em>Henry Tyler<\/em>.<\/p>\n\n\n\n<p>Further info about the DF-Player on this page: <a href=\"https:\/\/starthardware.org\/en\/dfplayer-mini-mp3-player-for-arduino\/\" target=\"_blank\" rel=\"noreferrer noopener\">DFPlayer Mini-MP3-Player for Arduino<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module-2-1024x768-1.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module-2-1024x768-1.jpg\" alt=\"RaylFX effects for model railroads and model making with Arduino Nano Schematic of the Fair module Close-Up\" class=\"wp-image-467\" srcset=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module-2-1024x768-1.jpg 1024w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module-2-1024x768-1-300x225.jpg 300w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module-2-1024x768-1-768x576.jpg 768w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module-2-1024x768-1-500x375.jpg 500w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Code Settings<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>int runningLightTimeout = 100;        \/\/ running light speed (ms)\nint strobeFlashTimeout = 100;         \/\/ strobe impulse duration (ms)\nint strobePauseTimeout = 1000;        \/\/ strobe pause duration (ms)\nint ferrisWheelPauseTimeout = 3;      \/\/ ferris wheel pause duration (s)\nint carouselPauseTimeout = 2;         \/\/ carousel pause duration (s)\nint streetLightsTimeout = 100;        \/\/ switch-on time of the street lights (ms)\nint volumeDFPlayer = 10;                      \/\/ volume of the DFPlayer (0 \u2013 30)\n\nint mp3Count = 7;                               \/\/ amount of MP3 files on the SD-card\nint mp3Duration&#091;] = {28, 9, 20, 2, 4, 17, 23};  \/\/ duration of the MP3 files in seconds\nint mp3Likelihood = 10;                         \/\/ likelihood with which MP3s are played, 10 often, 100 rarely\n<\/code><\/pre>\n\n\n\n<p>Different settings can be made in the code:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Running light speed in milliseconds<\/li><li>Stroboscope pulse duration in milliseconds<\/li><li>Stroboscope pause duration in milliseconds<\/li><li>Ferris wheel pause duration in seconds<\/li><li>Carousel pause duration in seconds<\/li><li>Street light on time in milliseconds<\/li><li>Volume of the DFPlayer (0 &#8211; 30)<\/li><li>Amount of MP3 files on the SD card<\/li><li>Duration of MP3 files in seconds (can be shorter than MP3s)<\/li><li>Likelihood with which MP3s are played: 10 often, 100 rarely<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Code for the RaylFX Fair Module<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/*\n     Rayl-FX Fair Module\n     StartHardware.org\/en\n*\/\n\n#include &lt;CheapStepper.h&gt;\n#include \"SoftwareSerial.h\"              \/\/ required for the DFPlayer\n#include \"DFRobotDFPlayerMini.h\"         \/\/ required for the DFPlayer\n\n\/* ***** ***** Settings ***** ***** ***** *****  ***** ***** ***** *****  ***** ***** ***** ***** *\/\n\nint myAddress = 2;                    \/\/ must be unique in the system! Must therefore exist only once.\n\nint runningLightTimeout = 100;        \/\/ running light speed (ms)\nint strobeFlashTimeout = 100;         \/\/ strobe impulse duration (ms)\nint strobePauseTimeout = 1000;              \/\/ strobe pause duration (ms)\nint ferrisWheelPauseTimeout = 3;            \/\/ ferris wheel pause duration (s)\nint carouselPauseTimeout = 2;               \/\/ carousel pause duration (s)\nint streetLightsTimeout = 100;              \/\/ switch-on time of the street lights (ms)\nint volumeDFPlayer = 10;                    \/\/ volume of the DFPlayer (0 \u2013 30)\n\nint mp3Count = 7;                               \/\/ amount of MP3 files on the SD-card\nint mp3Duration&#091;] = {28, 9, 20, 2, 4, 17, 23};  \/\/ duration of the MP3 files in seconds\nint mp3Likelihood = 10;                         \/\/ likelihood with which MP3s are played, 10 often, 100 rarely\n\n\/* ***** ***** From here begins the program code, which does not need to be adjusted ***** ***** ***** ***** *\/\n\nint streetLightsPin = 9;                    \/\/ this pin connects to the street lights\nint runningLight1Pin = 8;                   \/\/ this pin connects to the running light A lamps 2\nint runningLight2Pin = 7;                   \/\/ this pin connects to the running light A lamps 3\nint runningLight3Pin = 6;                   \/\/ this pin connects to the running light B lamps 1\nint runningLight4Pin = 5;                   \/\/ this pin connects to the running light B lamps 2\nint strobePin = 4;                          \/\/ this pin connects to the stroboscope (white LED?)\n\n\/\/int motorPins1&#091;4] = {10, 11, 12, 13};     \/\/ pins for stepper-motor 1\n\/\/int motorPins2&#091;4] = {14, 15, 16, 17};     \/\/ pins for stepper-motor 2\n\n\/* Storage Variables *\/\nint runningLightPosition = 0;               \/\/ stores the position of running light A\nint streetLightsBrightness = 0;             \/\/ stores street light brightness\n\n\/* Timer Variables *\/\nlong streetLightsTimer = 0;                 \/\/ timer street lights\nlong runningLightTimer = 0;                 \/\/ timer running light\nlong strobeTimer = 0;                       \/\/ timer stroboscope\nlong ferrisWheelTimer = 0;                  \/\/ timer ferris wheel\nlong carouselTimer = 0;                     \/\/ timer carousel\nlong soundTimer = 0;                        \/\/ timer DFPlayer\nlong soundTimeout = 0;                      \/\/ stores the playing time of the current MP3\nlong moveStartTime1 = 0;            \/\/ this will save the time (millis()) when we started each new move\nlong moveStartTime2 = 0;            \/\/ this will save the time (millis()) when we started each new move\n\n\/* State Variables *\/\nint myState = 3;                            \/\/ state main-statemachine, starts at 3, since everything is switched off here\nint ferrisWheelState = 0;                   \/\/ state ferris wheel\nint carouselState = 0;                      \/\/ state carousel\nint strobeState = 0;                        \/\/ state stroboscope\nint soundState = 0;                         \/\/ state DFPlayer\nbool moveClockwise21 = true;\nbool moveClockwise22 = true;\nint stepsLeft1 = 0;\nint stepsLeft2 = 0;\n\nint soundRandom;\nint theSound;\nint soundPlaying = false;\n\nbool moveClockwise1 = true;\nbool moveClockwise2 = true;\n\nString stateName;\n\n\/* Variables from the control module to determine the time of day *\/\nboolean receive = false;\nboolean receiveStarted = false;\nint receiveTimeout = 10;\nlong receiveTimer = 0;\nint receivedTime = 0;\nint receivePulse = 0;\nint lastReceivePulse = 0;\nint receivePin = 18;\nint myTime = 0;\n\n\/* Create Objects *\/\nSoftwareSerial mySoftwareSerial(3, 2);   \/\/ RX, TX for DFPlayer\nDFRobotDFPlayerMini myDFPlayer;          \/\/ DFPlayer object\n\nCheapStepper stepper1 (14, 15, 16, 17);  \/\/ creating a stepper object for the ferris wheel\nCheapStepper stepper2 (10, 11, 12, 13);  \/\/ creating a stepper object for the carousel\n\n#define PAYLOAD_SIZE 2                   \/\/ mandatory for communication with master-module\nint timeOfDay = 0;                       \/\/ stores timeOfDay of master-module (0 and 255)\nbyte nodePayload&#091;PAYLOAD_SIZE];          \/\/ temporarily stores data of master-module\n\nvoid setup() {\n  Serial.begin(115200);                  \/\/ starts the serial communication\n  pinMode(receivePin, INPUT);            \/\/ receiving pin from control-module\n  mySoftwareSerial.begin(9600);          \/\/ starts the serial communication for DFPlayer\n  pinMode(runningLight1Pin, OUTPUT);        \/\/ set running light as output\n  pinMode(runningLight2Pin, OUTPUT);        \/\/ set running light as output\n  pinMode(runningLight3Pin, OUTPUT);        \/\/ set running light as output\n  pinMode(runningLight4Pin, OUTPUT);        \/\/ set running light as output\n  pinMode(strobePin, OUTPUT);            \/\/ set strobe as output\n  runningLightOff();\n  strobeOff();\n  streetLightsOff();\n  stepper1.setRpm(16);\n  stepper2.setRpm(12);\n\n\n  \/* DFPlayer Setup *\/\n  Serial.println(F(\"Initializing DFPlayer ... \"));\n  if (!myDFPlayer.begin(mySoftwareSerial)) {  \/\/ use softwareSerial to communicate with DFPlayer\n    Serial.println(F(\"Error: Check connection to DFPlayer and SD-card\"));\n    \/*while (true) {\n      delay(0); \/\/ Code to compatible with ESP8266 watch dog.\n      }*\/\n  }\n  Serial.println(F(\"DFPlayer Mini online.\"));\n  myDFPlayer.volume(volumeDFPlayer);       \/\/ volume is assigned\n}\n\/*\n  void receiveEvent(int bytes) {\n  while (Wire.available()) {\n    timeOfDay = Wire.read();                \/\/ stores received time data in the variable timeOfDay\n    if (timeOfDay &gt; 22) {\n      stateName = \"late evening\";\n      myState = 0; \/\/ late evening\n    } else if (timeOfDay &gt; 18) {\n      myState = 5; \/\/ evening\n      stateName = \"evening\";\n    } else if (timeOfDay &gt; 12) {\n      myState = 4; \/\/ noon\n      stateName = \"noon\";\n    } else if (timeOfDay &gt; 9) {\n      myState = 3; \/\/ forenoon\n      stateName = \"forenoon\";\n    } else if (timeOfDay &gt; 7) {\n      myState = 2;  \/\/ morning\n      stateName = \"morning\";\n    } else {\n      myState = 1;  \/\/ night\n      stateName = \"night\";\n    }\n\n    Serial.print(millis()); Serial.print(\"\\t timeOfDay: \\t\"); Serial.print(timeOfDay);\n    Serial.print(\"\\t myState: \\t\"); Serial.print(myState); Serial.print(\" \u2014 \"); Serial.println(stateName);\n  }\n  }*\/\n\nvoid loop() {\n\n  receiveFunction();                  \/\/ execute instructions for reception\n  if (receiveStarted == false) {\n    if (myTime &gt; 22) {                \/\/ ***** late evening *****\n      streetLightsOn();               \/\/ street lights on\n      runningLightOn();               \/\/ running light on\n      strobeOn();                     \/\/ strobe on\n      soundOn();                      \/\/ sound on\n      ferrisWheelMotorOn();           \/\/ ferris wheel motor on\n      carouselMotorOn();              \/\/ carousel motor on\n      \n    } else if (myTime &gt; 18) {         \/\/ ***** evening *****\n      streetLightsOn();               \/\/ street lights on\n      runningLightOn();               \/\/ running light on\n      strobeOn();                     \/\/ stroboscope on\n      soundOn();                      \/\/ sound on\n      ferrisWheelMotorOn();           \/\/ ferris wheel motor on\n      carouselMotorOn();              \/\/ carousel motor on\n      \n    } else if (myTime &gt; 12) {         \/\/ ***** noon *****\n      streetLightsOff();              \/\/ street lights off\n      runningLightOff();              \/\/ running light off\n      strobeOff();                    \/\/ stroboscope off\n      soundOff();                     \/\/ sound off\n      ferrisWheelMotorOn();           \/\/ ferris wheel motor on\n      carouselMotorOff();             \/\/ carousel motor off\n\n    } else if (myTime &gt; 9) {          \/\/ ***** forenoon *****\n      streetLightsOff();              \/\/ street lights off\n      runningLightOff();              \/\/ running light off\n      strobeOff();                    \/\/ stroboscope off\n      soundOff();                     \/\/ sound off\n      ferrisWheelMotorOff();          \/\/ ferris wheel motor off\n      carouselMotorOff();             \/\/ carousel motor off\n\n    } else if (myTime &gt; 7) {          \/\/ ***** morning *****\n      streetLightsOn();               \/\/ street lights on\n      runningLightOff();              \/\/ running light off\n      strobeOff();                    \/\/ stroboscope off\n      soundOff();                     \/\/ sound off\n      ferrisWheelMotorOff();          \/\/ ferris wheel motor off\n      carouselMotorOff();             \/\/ carousel motor off\n\n    } else {                          \/\/ ***** night *****\n      streetLightsOn();               \/\/ street lights on\n      runningLightOff();              \/\/ running light off\n      strobeOff();                    \/\/ stroboscope off\n      soundOff();                     \/\/ sound off\n      ferrisWheelMotorOff();          \/\/ ferris wheel motor off\n      carouselMotorOff();             \/\/ carousel motor off\n    }\n  }\n}\n\nvoid streetLightsOn() {\n  if (streetLightsTimer + streetLightsTimeout &lt; millis()) {\n    streetLightsBrightness++;\n    if (streetLightsBrightness &gt; 255) streetLightsBrightness = 255;\n    streetLightsTimer = millis();\n    analogWrite(streetLightsPin, streetLightsBrightness);\n  }\n}\n\nvoid streetLightsOff() {\n  streetLightsBrightness = 0;\n  analogWrite(streetLightsPin, 0);\n  streetLightsTimer = millis();\n}\n\nvoid runningLightOn() {\n  if (runningLightTimer + runningLightTimeout &lt; millis()) {\n    runningLightTimer = millis();\n    runningLightPosition++;\n    if (runningLightPosition &gt; 3) {\n      runningLightPosition = 0;\n    }\n    if (runningLightPosition == 0) {\n      digitalWrite(runningLight1Pin, HIGH);\n      digitalWrite(runningLight2Pin, HIGH);\n      digitalWrite(runningLight3Pin, HIGH);\n      digitalWrite(runningLight4Pin, LOW);\n    } else if (runningLightPosition == 1) {\n      digitalWrite(runningLight1Pin, HIGH);\n      digitalWrite(runningLight2Pin, HIGH);\n      digitalWrite(runningLight3Pin, LOW);\n      digitalWrite(runningLight4Pin, HIGH);\n    } else if (runningLightPosition == 2) {\n      digitalWrite(runningLight1Pin, HIGH);\n      digitalWrite(runningLight2Pin, LOW);\n      digitalWrite(runningLight3Pin, HIGH);\n      digitalWrite(runningLight4Pin, HIGH);\n    } else if (runningLightPosition == 3) {\n      digitalWrite(runningLight1Pin, LOW);\n      digitalWrite(runningLight2Pin, HIGH);\n      digitalWrite(runningLight3Pin, HIGH);\n      digitalWrite(runningLight4Pin, HIGH);\n    }\n  }\n}\n\nvoid runningLightOff() {\n  runningLightTimer = millis();\n  digitalWrite(runningLight1Pin, LOW);\n  digitalWrite(runningLight2Pin, LOW);\n  digitalWrite(runningLight3Pin, LOW);\n  digitalWrite(runningLight4Pin, LOW);\n}\n\nvoid strobeOn() {\n  switch (strobeState) {\n    case 0:\n      digitalWrite(strobePin, HIGH);\n      if (strobeTimer + strobeFlashTimeout &lt; millis()) {\n        strobeTimer = millis();\n        strobeState = 1;\n      }\n      break;\n    case 1:\n      digitalWrite(strobePin, LOW);\n      if (strobeTimer + strobePauseTimeout &lt; millis()) {\n        strobeState = 0;\n        strobeTimer = millis();\n      }\n      break;\n  }\n}\n\nvoid strobeOff() {\n  digitalWrite(strobePin, LOW);\n  strobeTimer = millis();\n}\n\nvoid ferrisWheelMotorOn() {\n  stepper1.run();\n\n  switch (ferrisWheelState) {\n    case 0: \/\/ fahren\n      stepsLeft1 = stepper1.getStepsLeft();\n      if (stepsLeft1 == 0) {\n        moveClockwise1 = !moveClockwise1;\n        if (random(3) &lt;= 1) {\n          ferrisWheelState = 1;\n          ferrisWheelTimer = millis();\n        } else {\n          stepper1.newMoveDegrees (moveClockwise1, 360 + random(360));\n        }\n      }\n      break;\n    case 1: \/\/ pause\n      if (ferrisWheelTimer + (ferrisWheelPauseTimeout * 1000) &lt; millis()) {\n        ferrisWheelState = 0;\n      }\n      break;\n  }\n}\n\nvoid ferrisWheelMotorOff() {\n  \/*stepsLeft1 = stepper1.getStepsLeft();\n    if (stepsLeft1&gt;0) stepper1.stop();*\/\n}\n\nvoid carouselMotorOn() {\n  stepper2.run();\n  switch (carouselState) {\n    case 0: \/\/ spin\n      stepsLeft2 = stepper2.getStepsLeft();\n      if (stepsLeft2 == 0) {\n        moveClockwise2 = !moveClockwise2;\n        if (random(5) &lt;= 1) {\n          carouselState = 1;\n          carouselTimer = millis();\n        } else {\n          stepper2.newMoveDegrees (moveClockwise2, 90 + random(360));\n        }\n      }\n      break;\n    case 1: \/\/ pause\n      if (carouselTimer + (carouselPauseTimeout * 1000) &lt; millis()) {\n        carouselState = 0;\n      }\n      break;\n  }\n}\n\nvoid carouselMotorOff() {\n  \/*stepsLeft2 = stepper2.getStepsLeft();\n    if (stepsLeft2&gt;0) stepper2.stop();*\/\n}\n\nvoid soundOn() {\n  switch (soundState) {\n    case 0:\n      Serial.println(\"soundTimer 0\");\n      soundRandom = random(mp3Likelihood);\n      if (soundRandom &lt; 1) {\n        soundState = 1;\n        theSound = random(mp3Count) + 1;\n        soundTimer = millis();\n        soundTimeout = mp3Duration&#091;theSound - 1] * 1000;\n        Serial.print(\"Playsound: \\t\\t\\t\"); Serial.print(theSound); Serial.print(\"\\t\\t\\t\"); Serial.println(soundTimeout);\n        myDFPlayer.playFolder(1, theSound); \/\/play specific mp3 in SD:\/15\/004.mp3; Folder Name(1~99); File Name(1~255)\n        soundPlaying = true;\n      } else {\n        soundTimer = millis();\n        soundTimeout = 500;\n        soundState = 1;\n      }\n      break;\n    case 1:\n      if (soundTimer + soundTimeout &lt; millis()) {\n        soundPlaying = false;\n        soundState = 0;\n      }\n      break;\n  }\n}\n\n\nvoid soundOff() {\n  if (soundPlaying == true) {\n    Serial.println(soundPlaying);\n    myDFPlayer.pause();\n    soundPlaying = false;\n  }\n}\n\n\nvoid printDetail(uint8_t type, int value) {     \/\/ DF Player errors\n  switch (type) {\n    case TimeOut:\n      Serial.println(F(\"Time Out!\"));\n      break;\n    case WrongStack:\n      Serial.println(F(\"Stack Wrong!\"));\n      break;\n    case DFPlayerCardInserted:\n      Serial.println(F(\"Card Inserted!\"));\n      break;\n    case DFPlayerCardRemoved:\n      Serial.println(F(\"Card Removed!\"));\n      break;\n    case DFPlayerCardOnline:\n      Serial.println(F(\"Card Online!\"));\n      break;\n    case DFPlayerUSBInserted:\n      Serial.println(\"USB Inserted!\");\n      break;\n    case DFPlayerUSBRemoved:\n      Serial.println(\"USB Removed!\");\n      break;\n    case DFPlayerPlayFinished:\n      Serial.print(F(\"Number:\"));\n      Serial.print(value);\n      Serial.println(F(\" Play Finished!\"));\n      break;\n    case DFPlayerError:\n      Serial.print(F(\"DFPlayerError:\"));\n      switch (value) {\n        case Busy:\n          Serial.println(F(\"Card not found\"));\n          break;\n        case Sleeping:\n          Serial.println(F(\"Sleeping\"));\n          break;\n        case SerialWrongStack:\n          Serial.println(F(\"Get Wrong Stack\"));\n          break;\n        case CheckSumNotMatch:\n          Serial.println(F(\"Check Sum Not Match\"));\n          break;\n        case FileIndexOut:\n          Serial.println(F(\"File Index Out of Bound\"));\n          break;\n        case FileMismatch:\n          Serial.println(F(\"Cannot Find File\"));\n          break;\n        case Advertise:\n          Serial.println(F(\"In Advertise\"));\n          break;\n        default:\n          break;\n      }\n      break;\n    default:\n      break;\n  }\n}\n\n\nvoid receiveFunction() {                      \/\/ receives time of day from control-module\n  receivePulse = digitalRead(receivePin);     \/\/ read out the receive pin\n  \n  if ((receiveTimer + receiveTimeout &lt; millis()) &amp;&amp; (receiveStarted == true)) {\n    \/\/ on timeout and active reception\n    receiveStarted = false;                   \/\/ end active reception\n    myTime = receivedTime - 1;                \/\/ store received time\n    receivedTime = 0;                         \/\/ reset the auxiliary variable for time reception\n    Serial.println(myTime);                   \/\/ serial output\n  }\n  \/\/ if a pulse is detected at the receive pin that was not there before\n  if ((receivePulse == 0) &amp;&amp; (lastReceivePulse == 1)) {\n    receiveTimer = millis();                  \/\/ restart timer\n    if (receiveStarted == false) receiveStarted = true;  \/\/ start active reception, if not already done\n    receivedTime++;                           \/\/ there was a pulse, so increase the auxiliary variable to receive time\n  }\n  lastReceivePulse = receivePulse;            \/\/ remember current state at pin for next pass\n}<\/code><\/pre>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link\" href=\"https:\/\/starthardware.org\/en\/category\/projects\/arduino-projects\/raylfx\/\" target=\"_blank\" rel=\"noreferrer noopener\">View all RaylFX modules \u00bb<\/a><\/div>\n<\/div>\n\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>The first module of the RaylFX series is the Fair module. These are various effects that you can expect to see at a fair: Ferris Wheel Carousel Running light Street lights Stroboscope Sound module Video \u2013 RaylFX Fair Module Components These are the components I used: Arduino Nano* Breadboard* Jumper wires* Ribbon jumper wires* to&hellip;&nbsp;<a href=\"https:\/\/starthardware.org\/en\/raylfx-fair-module\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">RaylFX \u2013 Fair Module<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":436,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[5,9],"tags":[],"class_list":["post-435","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino-projects","category-raylfx"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v18.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>RaylFX \u2013 Fair Module<\/title>\n<meta name=\"description\" content=\"RaylFX \u2013 How to create a Fair module for your model city with the RaylFX system and an Arduino Nano. Includes light, motion, sound and time.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/starthardware.org\/en\/raylfx-fair-module\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"RaylFX \u2013 Fair Module\" \/>\n<meta property=\"og:description\" content=\"RaylFX \u2013 How to create a Fair module for your model city with the RaylFX system and an Arduino Nano. Includes light, motion, sound and time.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/starthardware.org\/en\/raylfx-fair-module\/\" \/>\n<meta property=\"og:site_name\" content=\"StartHardware - Tutorials for Arduino\" \/>\n<meta property=\"article:published_time\" content=\"2021-02-23T10:55:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-03-27T14:25:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"David Hermann\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/starthardware.org\/en\/#website\",\"url\":\"https:\/\/starthardware.org\/en\/\",\"name\":\"StartHardware - Tutorials for Arduino\",\"description\":\"Arduino, Electronics, Fun\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/starthardware.org\/en\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/starthardware.org\/en\/raylfx-fair-module\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module.jpg\",\"contentUrl\":\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module.jpg\",\"width\":1200,\"height\":675,\"caption\":\"RaylFX effects for model railroad and model making with Arduino Nano fairground module title\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/starthardware.org\/en\/raylfx-fair-module\/#webpage\",\"url\":\"https:\/\/starthardware.org\/en\/raylfx-fair-module\/\",\"name\":\"RaylFX \u2013 Fair Module\",\"isPartOf\":{\"@id\":\"https:\/\/starthardware.org\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/starthardware.org\/en\/raylfx-fair-module\/#primaryimage\"},\"datePublished\":\"2021-02-23T10:55:55+00:00\",\"dateModified\":\"2021-03-27T14:25:03+00:00\",\"author\":{\"@id\":\"https:\/\/starthardware.org\/en\/#\/schema\/person\/37dd49804e351d0045589790d695d99c\"},\"description\":\"RaylFX \u2013 How to create a Fair module for your model city with the RaylFX system and an Arduino Nano. Includes light, motion, sound and time.\",\"breadcrumb\":{\"@id\":\"https:\/\/starthardware.org\/en\/raylfx-fair-module\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/starthardware.org\/en\/raylfx-fair-module\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/starthardware.org\/en\/raylfx-fair-module\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/starthardware.org\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"RaylFX \u2013 Fair Module\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/starthardware.org\/en\/#\/schema\/person\/37dd49804e351d0045589790d695d99c\",\"name\":\"David Hermann\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/starthardware.org\/en\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5c1f55f9c9addf2633dc5513f65e57c6b11de8c1d05cab7a65be1e402233d543?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5c1f55f9c9addf2633dc5513f65e57c6b11de8c1d05cab7a65be1e402233d543?s=96&d=mm&r=g\",\"caption\":\"David Hermann\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"RaylFX \u2013 Fair Module","description":"RaylFX \u2013 How to create a Fair module for your model city with the RaylFX system and an Arduino Nano. Includes light, motion, sound and time.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/starthardware.org\/en\/raylfx-fair-module\/","og_locale":"en_US","og_type":"article","og_title":"RaylFX \u2013 Fair Module","og_description":"RaylFX \u2013 How to create a Fair module for your model city with the RaylFX system and an Arduino Nano. Includes light, motion, sound and time.","og_url":"https:\/\/starthardware.org\/en\/raylfx-fair-module\/","og_site_name":"StartHardware - Tutorials for Arduino","article_published_time":"2021-02-23T10:55:55+00:00","article_modified_time":"2021-03-27T14:25:03+00:00","og_image":[{"width":1200,"height":675,"url":"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Written by":"David Hermann","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/starthardware.org\/en\/#website","url":"https:\/\/starthardware.org\/en\/","name":"StartHardware - Tutorials for Arduino","description":"Arduino, Electronics, Fun","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/starthardware.org\/en\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https:\/\/starthardware.org\/en\/raylfx-fair-module\/#primaryimage","inLanguage":"en-US","url":"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module.jpg","contentUrl":"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/02\/RaylFX-fair-module.jpg","width":1200,"height":675,"caption":"RaylFX effects for model railroad and model making with Arduino Nano fairground module title"},{"@type":"WebPage","@id":"https:\/\/starthardware.org\/en\/raylfx-fair-module\/#webpage","url":"https:\/\/starthardware.org\/en\/raylfx-fair-module\/","name":"RaylFX \u2013 Fair Module","isPartOf":{"@id":"https:\/\/starthardware.org\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/starthardware.org\/en\/raylfx-fair-module\/#primaryimage"},"datePublished":"2021-02-23T10:55:55+00:00","dateModified":"2021-03-27T14:25:03+00:00","author":{"@id":"https:\/\/starthardware.org\/en\/#\/schema\/person\/37dd49804e351d0045589790d695d99c"},"description":"RaylFX \u2013 How to create a Fair module for your model city with the RaylFX system and an Arduino Nano. Includes light, motion, sound and time.","breadcrumb":{"@id":"https:\/\/starthardware.org\/en\/raylfx-fair-module\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/starthardware.org\/en\/raylfx-fair-module\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/starthardware.org\/en\/raylfx-fair-module\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/starthardware.org\/en\/"},{"@type":"ListItem","position":2,"name":"RaylFX \u2013 Fair Module"}]},{"@type":"Person","@id":"https:\/\/starthardware.org\/en\/#\/schema\/person\/37dd49804e351d0045589790d695d99c","name":"David Hermann","image":{"@type":"ImageObject","@id":"https:\/\/starthardware.org\/en\/#personlogo","inLanguage":"en-US","url":"https:\/\/secure.gravatar.com\/avatar\/5c1f55f9c9addf2633dc5513f65e57c6b11de8c1d05cab7a65be1e402233d543?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5c1f55f9c9addf2633dc5513f65e57c6b11de8c1d05cab7a65be1e402233d543?s=96&d=mm&r=g","caption":"David Hermann"}}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/posts\/435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/comments?post=435"}],"version-history":[{"count":34,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/posts\/435\/revisions"}],"predecessor-version":[{"id":804,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/posts\/435\/revisions\/804"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/media\/436"}],"wp:attachment":[{"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/media?parent=435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/categories?post=435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/tags?post=435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}