This project builds upon the excellent work done by Wolfgang Kufer who has kindly contributed his existing source code to this project, making it much easier for others to develop their own devices, which hopefully they too will share with the MRR community. Over the years things have changed and with the rise in popularity of the Arduino platform, I decided it was time to merge the on-going development of the EmbeddedLocoNet Arduino library and the OpenDCC Arduino library into a new project called Model Railroading with Arduino.

It has it's own SourceForge project and you can download the latest version of the libraries from here. There is also quite a wide choice of Arduino boards, including some with Model Railroading interfaces.

DCC Projects

As these two projects share the common Arduino platform and I was getting tired of maintaining each Arduino library directory in separate SVN archives, I thought it was about time I just merged them into one Arduino centric project. This project builds upon the excellent work done by Wolfgang Kufer who has kindly contributed his existing source code to this project, making it much easier for others to develop their own devices, which hopefully they too will share with the MRR community The hardware designs and firmware source code are licensed under the GNU Public License Version 2 The OpenDCC Arduino Library has movedJust an update, now Rocrail also supports this command station with protocol "dccpp"!!!!

diy dcc decoder arduino

Hi Dani, Brilliant article. I have a question; Do you need a separate programming track or can you use the main track as a programming track. You have both options: using the main track you can only set values for CV not possible to read CV as usual.

It has and independent programming track where you can read and write CV in different modes byte, register, Everything like a "real" command station. I have just purchased the Arduino Mega and Motor shield. I am in the process of building my Layout so it might be a while before I fire up the Command station. I know you mentioned the REED relay in one of your articles.

Hi, I use current sensors for track as they don't need any modification in rolling stock like reed. GCA93 from Peter Giling is the best option in my opinion. Those boards manage the servo motor, feed the turnout frog, and also send a signal to the software like a sensor to indicate the position and when is the turnout in movement.

I have been reading about Loconet and it seems quite interesting. Any idea how much the Peter Gilling boards costs. Also, how can you control the turnout even though you have a train on the track Thanks in advance. Hello, no, they aren't.

Model Railroading with Arduino

But I'm changing it to make it compatible with Loconet, so you can add a Loconet Shield GCA and becomes a command station compatible with any software. I'm still working on it, but I have an operative version that allow to move trains and manage functions, just the programming of CV is still missing. Dani, How much are the Peter Gilling boards.

I was reading about the boards last night and it was not clear whether the boards can be purchased ready assembled? Also, regarding current sensing, how do you control the turn out to open or close if you have a train on the track. Sometimes you would want the train to move in a different direction. It's not possible to buy it already mounted, but soldering of components is extremely easy. You don't directly need it. But if you add a Loconet Shield with the software I'm currently developing for Arduino, you can connect it to the Loconet Network and manage it through your current PC interface, being compatible with any soft.

But this software is not yet finished, in some months I'll have Loconet shields and software ready.

diy dcc decoder arduino

One correction: 12Vdc seems too low current for N scale, currently I'm using 15Vdc. With less voltage some sound decoders seem not to work. So am I to assume that these loconet boards, digitrax, canbus etc.It must have a very sensitive shutdown circuit that detected too much power being drawn. Introduction Recently I have been experimenting with building DCC controllers and decoders based on Arduino microcontrollers.

After hand wiring several of the DCC decoders I decided that a circuit board would make things much more convenient for me and other hobbyists. I designed a board that would provide these features:. There is an "X" on the back of the circuit board shown below. If you want to provide a supplementary soruce of 5 volts to operate the servos cut the trace and supply the power to the two pins marked "alt 5v".

I have had problems with the unit resetting itself when I ran two or three servos from the on-board power supply. Cutting the trace and adding an external power connection cleared everything up. The relay is a DPDT, 5 volt relay. It is turned on and off through pin A0.

The three servos are connected to pins A1, A2 and A3 on the Arduino. The top of the circuit board is silk screened to show where to install components. You can install either of two bridge rectifier styles - this photo shows both on the board - you only need ONE of them, either the small through hole unit in the lower left or the round one with long leads above it.

If you don't have either of the suggested bridge rectifiers you can easily make your own with four 1 amp diodes 1N or similar as shown here. Take care to align the bands as shown. The servos are normally powered from the voltage regulator on the board. If you are using large servos more power may be needed for them. To use an external source of 5 volts cut the trace shown here.

External power for the servos 5 volts, only! Positive on the right and negative on the left. There is also a set of holes under the Arduino that can be used for additional filtering. An electrolytic or non-electrolytic cap can be added there if needed.

The holes are circled in yellow in this photo. Note that the hole on the right is positive should you use an electrolytic cap. You may have noted that I used a source of external power a cell phone battery to power the servos in the video. I did that as the system was shutting down when I tried to operate two or three servos.

It turns out that the problem was not with the circuit or the servos but with the DCC system that I was using for testing. I designed a board that would provide these features: The decoder would connect to up to three servos The servos can be powered by DCC power or by an external 5 volt power source A 5 volt Double Pole Double Throw relay can be mounted on the board Two small breadboard areas are on the board Two different bridge rectifier styles can be used All of the Arduino pins are brought out onto the board accommodations are made for more filtering than may be needed Schematic The DCC power goes to the optocoupler via a 1K resistor and to the voltage regulator.

The 5 volt output from the if filtered before it goes to the optocoupler and Arduino. More filtration options than may be necessary are provided. My tests have had the board working reliably with D2 and C5 omitted. I also used 4. The back of the board is shown here: You can install either of two bridge rectifier styles - this photo shows both on the board - you only need ONE of them, either the small through hole unit in the lower left or the round one with long leads above it.

Cut off every other lead. Insert in the circuit board as shown. I designed a board that would provide these features: The decoder would connect to up to three servos The servos can be powered by DCC power or by an external 5 volt power source A 5 volt Double Pole Double Throw relay can be mounted on the board Two small breadboard areas are on the board Two different bridge rectifier styles can be used All of the Arduino pins are brought out onto the board accommodations are made for more filtering than may be needed.

A view of the DCC waveform as it enters the Arduino.It would have to be home brewed just like this HO board is. I find the LokSound decoders more then configurable for me I haven't bothered looking into others. Why would you want Arduino with a decoder? And reading the page on this HO one, it's not Arduino based, he was just saying it can function with the 'Pro Mini' like a shield does for Arduino.

Strictly arudino based would limit you to DCC plus. Google that and you get the github page. The project has probably been abandoned as it hasn't had any activity in a long time.

It does work, I see posts elsewhere of people using it, but you are going to have trouble getting help for getting running. Both take some significant amount of work to get going, and are very HW specific. Those are the only two that I'm aware of that are micro based and in shape to use. Hope that helps.

You don't need any additional device. If you want to use JMRI software on your computer to run DecoderPro and do the programming with windows screens, then you need an interface device such as a Sprog, PR3 etc.

Some of the newer released versions of some systems do connect directly to computers too without the extra device.

I have no idea if it Ardino based or not. I had not heard that it was. The basic CVs such as address, lights, and basic speed controls are very easy to program with the master throttle. This decoder has a rating of 4 amps continous and the latest releases have at least 10 amp stall ratings.

They are really hard to burn up! I have used some small sound decoders for sound only as a second decoder in a loco. It is not rated at quite as high current as the but still good. What's the goal here? There are lots of ways to do what you want. I went down the Arduino path, but am moving to a system that uses more expensive, but off the shelf to reduce the effort.

I do have a lot of experience with some of this though, and would be interested in why you are going this route?

I'm not sure what the attraction is for Arduino. You still have to come up with an additional circuit for motor drive and function outputs.

The basic difference between mobile decoders as a function of gauge is the ampacity of the full wave bridge and the motor driver output. Since space was basically irrelevant for O gauge I built it thru hole instead of surface mount. Good for well over 10 amps. And as far as sound goes, I have coded up sound ICs for chuff, prime mover, horn, whistle, and bell. I don't see the need for a full audio menu. Personally I've got a 15 minute tolerance of prime mover sounds before they become irritating.

Original Post. S sinclair Member.The decoders posted so far are what I should have called accessory decoders. An accessory decoder listens to a DCC accessory address and switches an output or drives a servo. A function decoder listens to one address a locomotive address, or as the NMRA calls it, a multi-function decoder and it switches locomotive functions, which are called F1, F2, etc.

For more info on how to get the ATtiny working, see this post. For that I use this opto coupler circuit. If it needs to be smaller to fit inside a wagon, it is also possible to use a Zener diode and a resistor.

Configuration is really easy. In line 1 of the code state the loc address you want it to listen to. In the lines that follow, define the output pins of F0, F1, F2 … up to F Not all need to be defined, just the ones that you want to use. Place the other folders in your Arduino Sketches folder.

The zip includes the function decoder as well as the accessory decoder software. Alternatively you can download the overall zip file from the Software pageit includes all software published so far. Hoi Ruud. Met veel intresse de DCC functie decoder gedownload. Ik krijg alle f1 tot fx werkend, maar F0 wil maar niet lukken. Is daar de F0 anders dan de standaard? Dit omdat alles lijkt te werken, alleen de F0 aan uit niet. Daardoor weet ik ook niet of de richtingsafhankelijkheid werkt, maar das secundair.

Weet jij wat hier de oorzaak kan zijn? In ieder geval bedankt voor de software, ik ben er blij mee! Groetjes, Hans. Like Like. Hans, ik heb geeb idee. Zodra ik tijd en zin heb zal ik er eens naar kijken of te achterhalen is waarom F0 niet meer uit te schakelen is met de MM.

Met de ECoS nooit gezien. Kan ook qua logica niet verzinnen waarom het zou gebeuren … het blijft toch een bit binnen een data byte dat aan of uit staat. Hoi Ruud, wonderlijk, ik zie bij het drukken van F0 geen verandering….

Ik heb een aantal keren de stop knop bedient, afwisselend met F0 aan of niet. Aan het einde nog een keer de snelheid van de lok gestuurd, een zijde op. De log van de sniffer:. Tsja, dan lijkt het er op dat de F0 niet doorkomt, als de sniffer hem niet ziet, dan zou je zeggen day ie niet op de rails terecht komt.

Maar als je loc hem wel ziet … dan is dat een interessant mysterie. Hi Ruud, ondertussen weer aan het spelen geweest en ondertussen komt de F0 door. Geen idee wat het geweest is, maar de sniffer ziet hem en de Arduino reageert ook. Ik krijg voor instrByte1 nergens een 2 of 3, alleen 1, 4 en 5.When constructing my dcc based train model, I looked for dcc decoder to pilot light SMDor standard ledbut had difficulty to program them for custom scenario blinking, road works style, ….

So I decided to create my own stationary dcc decoder based on Arduino nanoto be able to reprogram it at wish. This decoder is designed to be powered by a 16V AC power source. To assign a dcc address, you have to use the learning switch opposite to the Arduino.

In that position, each time it see a stationary decoder command coming on, it will store it as its new address and will acknowledge that by blinking the status led. So to assign a dcc address you just have to. On the bottom of the card, you have 3 slots for leds. Normaly you can connect only one led per slot due to the nominal tension that each led has, 2 different led don't have the exact same nominal tension.

You just has to use the push button to cycle between the 3 modes. The little status led, will tell you in which mode you are. Close to the lights there is a block of 3 pins for the relay if you decide to build itwhich are in this order: low ouput, input, high output. So the one on the middle is your input whatever your input isand the relay will connect it either to the left pin or to the right pin. If you prefer to fully assemble it, you will need to get the PCB, and of course the components.

The PCB gerber files are here: arduinov1.

diy dcc decoder arduino

If you are familiar with Arduino programming, you can re-program it to whatever needs you have. That the beauty of it. Here are the arduino sources: dccduino.

If you want to develop your own dcc decoder, I provide you the eagle source: arduinoDcc1. Feel free to adapt it to your needs, but I provide it as is, i. I can answer some question but if you decide to change the layout, you are on your own.

This decoder is pretty simple, you can assign it a dcc address via a learning switch button connect LED lights, or a relay choose the light mode if you connected lights. There are 3 different modes you can choose via a push button: constant light on or offflicker mode, or 3 way road work lights mode It has been designed to be powered by a 16V AC, but can be as well be powered via DCC signal 15v or 18vor a DC signal.

This is why there are 2 set of cables: one for the 16V AC one for the DCC signal Assign a dcc address To assign a dcc address, you have to use the learning switch opposite to the Arduino.Modern model railroads are digital controlled, using the Digital Command Control DCC protocol, whereby data is embedded in the AC voltage that is put on the track to drive the trains. DCC accessory- and servo decoders are available on the market to decode the DCC data and to act on it if the command was meant for their address.

If we can use an Arduino to control our accessories and servos via DCC we can reduce cost by a factor The good news is … we can! We use a small electronic circuit to translate this to 5V, to safely connect it to our Arduino. In that case use 2x2k2 in parallel.

How to build your own DCC system (DCC++)

A slow opto-coupler could distort this timing. The output of the opto-coupler is connected to Arduino pin 2. This pin provides the hardware interrupt mechanism that is used with the Arduino DCC data decoding library. The software for a DCC accessory decoder is remarkably simple. The DCC library can be downloaded here. We need to configure our accessories. We fill in how many accessories are connected to this Arduino:. Then in void setup we fill in their Arduino pin numbers and the DCC addresses we want them to react to:.

In this example only 2 accessories are configured. The code for a complete DCC accessory decoder. This function switches our accessories on or off, based on DCC data read via the library. The video shows it under test with my DR Yes … that works perfect! Als ik je voorbeeldbestand compileer, dan krijg ik de onderstaande melding. Wat gaat er fout? Like Like. Als je typedef in die regel weghaalt zodat ie begint met struct … dan denk ik dat die warming verdwijnt. Hi Rudy, This is a great code and circuit, thank you.

When trying to use it to control 16 outputs through 2 sets of 8 x relays, the digital ports 3 to 12 work fine but with the analog pins A0 to A5 the reaction is terribly slow, useless in practice. Any clue?

Thank you. Well, that is strange, I never noticed any delay on A0-A5. Could it have anything to do with A0-A5 having pin numbersand not like you mentioned? Thank you for your reply. Yes, the analog pins aresorry, was a mistake. I begin to think this is not a problem with the analog pins. It is some kind of saturation optocoupler? I have tried with a Mega so with lots of digital pins and everything goes well until I increase the number of pins connected to the relay array.

The connectivity is fast until 8 relays are connected but when I index more accesories the control progressively slows down. Everything above 11 is impossible.