Arduino and servo's to control turnouts with DCC

Affiliate Disclosure: We may receive a commision from some of the links and ads shown on this website (Learn More Here)

RailroadBookstore.com - An online railroad bookstore featuring a curated selection of new and used railroad books. Railroad pictorials, railroad history, steam locomotives, passenger trains, modern railroading. Hundreds of titles available, most at discount prices! We also have a video and children's book section.

ModelRailroadBookstore.com - An online model railroad bookstore featuring a curated selection of new and used books. Layout design, track plans, scenery and structure building, wiring, DCC, Tinplate, Toy Trains, Price Guides and more.

#1
So I'm starting on the mission of controlling my turnouts with a servo motor controlled by an Arduino. I want to be able to use my DCC (Digitrax) network along with buttons on the layout near the turnouts to control from there as well. I will be doing my best to not have this based on one DCC system but please understand I only have the one to work with so at times it will have to be based on my limited resources. I'm not about to buy other DCC systems to wok with, but we all know that. :D

Here is what I figure I'll need to start. An Arduino board, a servo for each turnout and my DCC layout. Along with that I will need the power supply and a switch on the layout to control the turnout as well. There will be wires and whatever else I learn as I go. From here we start this mission to document the process from this early concept and low level of knowledge to completion.

I figure there are multiple phases of this project from programming to installation. There are many questions I have and I hope to get input from here as this project moves.

I now have Arduino boards, servos DCC controller and of coarse I have the train turnouts.

First step, can this be done?
I know I can get the Arduino to control the servo and that in turn can control the turnout. I'm sure this can be done from a button but my first lack of knowledge is how can I get the signal from my DCC network to the Arduino? Will the signal be sent from the LocoNet or will this be sent on the rails? I figure it's the LocoNet. How do I make the connection from the LocoNet (DCC Network) to the Arduino?

I guess that's a good question to start this discussion off with. Please get involved and lets see if we can't all learn a little.

Dave
 
#2
First step, can this be done?
Yes.

As you get started on the journey, I recommend you slog through the following. If you haven't already subscribed to MRH, DO SO. Its free and well worth it weekly email. As you go through, there will be some things you won't understand. Ask here and I'll help best I can. I'm sure others will fill in any gaps I miss. So here goes:

SMA10 The first in a series of Arduino / DCC topics. http://model-railroad-hobbyist.com/node/19070

SMA12 The second in a series of Arduino / DCC topics. http://model-railroad-hobbyist.com/node/19446

SMA13 An update to SMA12. http://model-railroad-hobbyist.com/node/19775

SMA15 The next generation. http://model-railroad-hobbyist.com/node/20739

SMA20 The next evolution, expanded functionality. http://model-railroad-hobbyist.com/node/24316

Beyond those, there are several other threads by Dr. Geoff Bunza on using Arduino's and DCC for other than train (locomotive) control. He also has a YouTube channel: https://www.youtube.com/user/DrGeoffB
 
#3
I know I can get the Arduino to control the servo and that in turn can control the turnout. I'm sure this can be done from a button but my first lack of knowledge is how can I get the signal from my DCC network to the Arduino? Will the signal be sent from the LocoNet or will this be sent on the rails? I figure it's the LocoNet. How do I make the connection from the LocoNet (DCC Network) to the Arduino?
Take the time to review the above referenced forum topics. In the first (SMA10), you'll see that the Arduino gets its signals direct from the rails.
 
#4
Hi Dave
I have been looking at similar systems for driving accessories but with much higher capacity. (16 servos, 16 LEDs and 16 sensor inputs all driven by a simple At mega88 Atmel processor). I managed to link this to RocRail and DCC++ with Xpressnet via an RS232 serial link and since the LocoNet protocol is readily available, I cannot see why this cannot be implemented as well. I am now looking at the DCC++ Command station and I hope to link it to my Accessory Module using the DCC++ protocol.

The number of servos used can be quite high when turnouts, signals and animations are considered. I found the power source for the servos had to be a 5v power supply since 12v dc regulated to 5v was very unstable with more than a couple of servos operating. (5v dropped to below 2v on occasions). Also be wary of using 'Digital' servos. These are designed for heavily loaded RC aircraft flying surfaces and can draw highish currents even when stationary (they can also buzz quite loudly). Ten, twenty or even thirty servos connected would demand an unacceptably high current.

For information, my servo encoder, (per 16 servos) is a 16bit timer counter output + 2 digital outputs. The decoder is 2 x decade counters type CD4017. (8 servos per device).
My digital Inputs and Outputs use PCF8574 devices via a TWI interface. 8 I/O per device.

hope this helps

Ron
 
#5
First step, can this be done?
I know I can get the Arduino to control the servo and that in turn can control the turnout. I'm sure this can be done from a button but my first lack of knowledge is how can I get the signal from my DCC network to the Arduino? Will the signal be sent from the LocoNet or will this be sent on the rails? I figure it's the LocoNet. How do I make the connection from the LocoNet (DCC Network) to the Arduino?
Dave
It will probably be easiest to pull the DCC signal directly off the track, that way it would be system independant
In image below tracks go to bottom left ... on top right one side to +5V, other to digital input of your choice, normally D2 .. there's your DCC signal into the 'duino
 

Attachments

#6
Take the time to review the above referenced forum topics. In the first (SMA10), you'll see that the Arduino gets its signals direct from the rails.
Hi Kevin,

I have not replied because I have been doing some reading on my free time. The links you shared have a vast amount of information and should be a first step for anyone wanting to get into Arduino and model railroading.

AWSOME!

Dave
 
#7
Hi Dave
I have been looking at similar systems for driving accessories but with much higher capacity. (16 servos, 16 LEDs and 16 sensor inputs all driven by a simple At mega88 Atmel processor). I managed to link this to RocRail and DCC++ with Xpressnet via an RS232 serial link and since the LocoNet protocol is readily available, I cannot see why this cannot be implemented as well. I am now looking at the DCC++ Command station and I hope to link it to my Accessory Module using the DCC++ protocol.

The number of servos used can be quite high when turnouts, signals and animations are considered. I found the power source for the servos had to be a 5v power supply since 12v dc regulated to 5v was very unstable with more than a couple of servos operating. (5v dropped to below 2v on occasions). Also be wary of using 'Digital' servos. These are designed for heavily loaded RC aircraft flying surfaces and can draw highish currents even when stationary (they can also buzz quite loudly). Ten, twenty or even thirty servos connected would demand an unacceptably high current.

For information, my servo encoder, (per 16 servos) is a 16bit timer counter output + 2 digital outputs. The decoder is 2 x decade counters type CD4017. (8 servos per device).
My digital Inputs and Outputs use PCF8574 devices via a TWI interface. 8 I/O per device.

hope this helps

Ron

Hi Ron,

I would love to get into the details of what you have done sometime. Seems you have a good grasp with electronics and DCC. There was one thought I had was to use a rely to run multiple servos. Since my knowledge is so limited I'm not sure what all can be done. I to would like to include the LED controls so I can have a display on the layout of what state the turnout is currently set. Make it easy to see from across the layout and not need to run near a turnout to see if it's set correctly.

Dave
 
#8
It will probably be easiest to pull the DCC signal directly off the track, that way it would be system independant
In image below tracks go to bottom left ... on top right one side to +5V, other to digital input of your choice, normally D2 .. there's your DCC signal into the 'duino
WVG_CA,

Thanks for the diagram, I'm sure this is common to electronics but I'm still stumbling with the first mark "R1 1K". I'm sure I'll be clear of this entire thing before I'm done but now you all have an idea of how GREEN this boy is starting from. I think you already know, Kevin and others.

Dave
 
#9
Hi Dave -

R1, R2, and R3 are resistors. The numbers near them are the value of each resistor.

R1 = 1K = 1 kilohms = 1,000 ohms
R2 = 10K = 10 kilohms = 10,000 ohms
R3 = 4.7K = 4.7 kilohms = 4,700 ohms

- Jeff
 
#10
Hi Dave

I have attached schematics for the sensor input system, the LED output driver and the Servo driver. They are not finalised yet but they should give the flavour of the complexity, (or lack of it). Since the resources required are minimal it would take very little extra to expand them from 16 way to 32 way.

Each servo requires a pulse width of between 1mS and 2mS giving a frame period of up to 32mS. A 16 bit processor timer, counting 1uS clock cycles, very conveniently gives a maximum period of 65mS which can contain a complete frame of 16 servos without overflow. The normal frame period is approx 20mS - 25ms so 32mS will only slow the response down slightly. The servos I tested worked fine.
The timer compare output is used to clock the 4017 counter onto the next channel. When channel 8 is completed the reset line for the first device is made active and the reset line of the next 4017 counter is released.
The 4017 counters could give 9 channels per device but 8 was more convenient for the software.

The time values for each servo, (maximum and minimum), are stored in EEPROM. Nominally 1000 and 2000, these can be changed to adjust the servo end points.

I used an Atmel AtMega88 running at 8Mhz to test this and each servo was rock steady without any signs of glitching. (Unlike my first attempt which used an Interrupt Service Routine to change the outputs).

I hope this whets your appetite enough - feel free to use these ideas as you want - they are not original.

Ron
 

Attachments






ModelRailroadForums.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com

Top