Attention

The Library in this code (VarSpeedServo) is no longer available on GitHub and is not supported by the creator, therefore the referenced code will not work. I’ll be updating this project with new code shortly. Sorry for the inconvenience

 

This project is a turnout control using Arduino in a simple configuration using push buttons, servos, LEDs, and relays. If you do not want a completely automated system, this may be the tools you will need for your model railroad.

Designed for any sized model railroad where you want to operate the turnouts on your own with push buttons. This can also be used with toggle switches with a slight modification to the code.

All components used in this project can be purchased through Amazon with the exception of the push button module which is a DFRobot product. A stand alone push button can also be used with the addition of a resistor. More information on this can be seen on another project in the Fritzing diagram for the PCA9685

Items Can be purchased through the Amazon Store page from the link at the bottom of the Page

A Test Sketch is provided to test all components individually before assembling the entire project. This is especially important for the Servos and The Relays.

With the Servo, you want to make sure your settings for the travel is correct and know weather you are driving the Hi or Low range for your straight position. In my example, I set all turnouts straight.

With the Relays, you want to insure you route the power for your frog correctly. Remember, the Relays are actuated with a LOW signal from the microcontroller. This is important, if you are aligning your turnout straight at startup, you’ll want to connect your frog lead to the common terminal and your feed wire to the NC terminal that is aligned with the straight section of your points. The NO terminal will go to the curved point feeder. Double check these connections for each relay individually before applying power to your track. You can use a multi meter or continuity checker for this test.

Arduino Turnout Control

Click For Video
Click For Video

Multiple devices can be set up throughout a layout to accommodate any number of control panels and turnouts.

When using a sensor shield like the one shown, it’s suggested to use a Nano and attach an external power supply through the barrel jack to handle the current of multiple servos if more than a few are in operation like when selecting a route. External power is also suggested if using more than 2 relays, this can be done on the relay module by removing the jumper between Vcc & JD-Vcc and applying power to JD-Vcc from your external power supply. A jumper can be used from the sensor shield’s 5v pin toe the modules JD-Vcc pin.

Also on the relay module the signal connections from your microcontroller are connected to the appropriate pins on the relay module. Such as IN1 IN2… You will need to connect the microcontrollers 5v pin to the modules Vcc adjacent top the signal pins with a jumper wire.

Devises attached to pins as follows:

turnout0Pin = 2;     Single Turnout
turnout1Pin = 3;     Xover
turnout2Pin = 4;     Xover
buttonPin0 = 5;      PB Modules
buttonPin1 = 6;
led0C = 7;             C designates Closed position of turnout
led0T = 8;              T designates Thrown position of turnout
led1C = 9;
led1T = 10;
relay0 = 11;           Relays used to route power to turnout frog
relay1 = 12;
relay2 = 13;

Relay Module Connections

Relay Module Connections

Sensor Module Connections

Sensor Board Connections

The Uno/Nano board does not have headers installed to be used as a shield for the Uno. Headers will need to be soldered to the underside of the board (not included).

A Nano has 2 additional analog input pins. All the other pins are identical to the Uno. A0 through A5 on both the Uno & Nano can also be designated as OUTPUT. This could give you additional pins for more outputs if needed, You can also leave these as analog inputs and use sensors for additional functionality.

JD_Vcc Connection

JD-Vcc

LEDs On Breadboard

LEDs On Breadboard

If the push button module is not being used, and you prefer to use a stand alone PB, you will need a PULLDOWN resistor attached to Ground for this to operate properly. The Module has the necessary components already installed.

Power From Sensor Board

Power From Sensor Board

DF Robot PB Module

DF Robot PB Module

More Videos Related To This Project

DF Robot Shield