“Modern model railroads are digitally controlled using a Digital Command Control (DCC) protocol similar to network packets. These data packets contain device address and instruction set that is embedded in the form of AC voltage and fed to train track to control locomotives. The great advantage of DCC over analog DC control is that you can independently control the speed and direction of many locomotives on the same train track as well as control many other lights and accessories using that same signal and voltage. Commercial DCC decoders are available on the market however their cost can add up pretty quickly if you have a lot of devices to control. Luckily you can build a simple Arduino DCC decoder yourself to decode DCC signal and control up to 17 LEDs / accessories per each DCC decoder.
The DCC signal is an alternating voltage (AC) usually 16V, depending on your DCC controller. We use rectifier and LM7805 regulator to convert it to 5V (DC) that can safely power Arduino DCC decoder.
The 6N137 is a fast opto-coupler that is necessary because DCC decoding relies on measuring pulse width where 50µs represents 1 and 100µs represents 0. 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 bye Arduino DCC data decoding library. Do not change this pin or your DCC decoder will not work.”