First we slowed down the turnout points, then we control frog power with a relay, all with an Arduino. Now, if we have multiple turnouts to control, a relay module comes into play. Here we show how easy it is to set up and explain where your feeder wires should go and why.

The relay modules are a versatile board that switches the frog power to the correct value when the switch points are thrown. The relay modules with more than one relay use an external power supply to drive the relay coil. This protects the Uno or other microcontroller from overtaxing itself and damage. The external power is attached at JD-Vcc after removing the jumper between this pin and Vcc.

Relay modules are activated LOW, so they need a LOW command to be thrown. This is just the opposite of how most relays operate. There are some modules that have the capability to change the value of what triggers it. None of the modules shown here have that option. This type of module will be discussed on another page.  In my demonstrations of my layout, I power up the relays as HIGH. In this way, the straight track will be on the Normally Closed Contact. In the Arduino sketch, I start out the relays with a HIGH command to keep them de-energized. You can refer to the Arduino Turnout Control page for further information and the sketch that runs the turnouts.

These relays can also be used with the PCA9685 which is an alternate method of driving the servos through serial communication. This method is a bit more advanced than these examples and can be used with JMRI easily.

Module Pins

Module Pins

Relay Module with Hi Low Level Trigger at Amazon

Output Pins

Output Pins

Four Relay Board at Amazon

In the video “Control Relay Modules With Arduino” a more in depth explanation is given of the wiring involved when connecting to a turnout. There are different ways to approach the wiwing based on the manufacturer of the turnout.

As in a Peco Turnout, the frog is isolated on one side and the two rails exiting the frog are common, so there needs to be insulators at the end of the turnout. Atlas and Shinahara, now Walthers Turnouts are basically the same with all the rails powered from one end to the other. The frog is isolated on both ends. There is one exception to this, which I cover in the video.

 

YouTube player

I found a Shinahara Wye Turnout that is insulated at the end of the point rails, and the entirety of the center rails along with the frog are connected together, which makes all the rails the same potential. These Wye Turnouts will also need to have insulators installed at the end of the turnout to operate properly.

Gap On Wye

Wye Gap

Note the location of the gap on the wye turnout. It is located at the end of the point rails. All the inside rails including the frog are at the same potential. This is different than other Shinahara turnouts. This may be a better design feature, since it is unlikely the wheels will short on anything while going through the frog.

Test Code For Relay Demo

/* Use to test LEDs, Servo position & Relay
    Tom Kvichak April 6, 2018
    Reviised with new library 10/21/2021
    Modified to test relay outputs 10/27/2021
*/
 #include <VarSpeedServo.h> 
 VarSpeedServo servo1;
int myLED1 = 7;       //Declare myLED1 as the first LED
int myLED2 = 8;       //Declare myLED1 as the second LED (PWM)
const int servo1Pin = 3;
int relay1 = 4;

void setup() {
  pinMode(myLED1, OUTPUT); //Assign Pin 7 as Output
  pinMode(myLED2, OUTPUT); //Assign Pin 8 as Output
  servo1.attach(servo1Pin);
  pinMode(relay1, OUTPUT);
//  servo1.write(90,3,true);
//  digitalWrite(relay1, HIGH);
}

void loop() {

  
//  digitalWrite(myLED1, HIGH);  //Set LED1 To On
//  digitalWrite(myLED2, LOW);   //Set LED2 To Off
//  servo1.write(90,3,false);      // 90 = Straight
  digitalWrite(relay1, HIGH);
  delay(5000);
  digitalWrite(relay1, LOW);
  delay(5000);
  
}

Another video you may enjoy watching for more insight on how this started.

YouTube player

Check the Playlists on my channel for more interesting video projects for model railroading and with Arduino.

Don’t forget the Monday Night Live Streams at 8 PM eastern. Train show schedules in Florida, Arduino discussion, train room projects, and a RANT or two.