Last Updated: 03/04/2024

#79 DCC Decoder Circuit

Components >> #79 DCC Decoder Circuit

DCC Decoder Circuit


DCC tends to run at 12-18v using a square wave signal. Arduino's, ESP32's and other microprocessors tend to run at 3.3v to 5v so to read the DCC signal a circuit needs to be able to pass on the DCC signal without passing on the voltage.

One of the safest ways to do this is with an optoisolator. This seperate the high voltage and low voltage sides of the circuit and passes the data signal between them using light.

The circuit we will be building is credited to Dave Falkenburg.

The components are:

1 x 6N137 Optoisolator
2 x 10K Ohm resistors
1 x 1k Ohm resistor
1 x 1N4148 Diode

Although the circuits themselves are identical, I have done an ESP32 and Arduino Uno example.

The UNO must connect the interrupt pin to Pin 2 or 3. I always default to pin 2 (see https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/ for details on interrupt pins).

On the ESP32 most pins can be used as an interrupt. I use pin 4 by default on my projects.

DCC Decoder Circuit

Building The Circuit

First place the 6N137 on the breadboard. Make sure you know the position of the dimple.

On the circuit diagram above the dimple is marked by a RED dot. 6N137 DCC Decoder Circuit

Next Place the 1N4148 diode, Make sure you have it the correct way round.

DCC Decoder Circuit

Next add the 1K Ohm resistor. Note that it is it connects to the same pin as the diode.

DCC Decoder Circuit

Now add the blue jumper wire.

DCC Decoder Circuit 3

Now add the first 10K Ohm resistor

DCC Decoder Circuit 4

Now add the 2nd 10k Ohm resistor. This connects to a different pin on the optoisolator but ends on the same row of pins as the other 10k Ohm resistor

DCC Decoder Circuit 5

Now add the Orange jumper. This connects the end pin of the optoisolator to the same row of pins as the 10K Ohm resistors

DCC Decoder Circuit 6

Now connect the 2 green jumpers that will cponnect to the DCC output, either from the track or directly from your DCC Base station.

DCC Decoder Circuit 7

This image shows the two green wires connected to my DCC controller outputs.

DCC Decoder Circuit 8

Next connect the black Gnd jumper

DCC Decoder Circuit 9

This will connect to the Arduino/ESP32 Gnd

DCC Decoder Circuit 10

Next connect the Yellow jumpr to the pin next to the Gnd jumper.

DCC Decoder Circuit 10

This connects to pin 2 on the Arduino Uno and by defauklt I use pin 4 on my ESP32 boards.

DCC Decoder Circuit 12

Finally install the Red jumper.

DCC Decoder Circuit 13

This connects to the Arduino 5v or the ESP32 3.3v

DCC Decoder Circuit 14

The final set up should look like this.

DCC Decoder Circuit 15

Once you have a working version it's best to solder the components onto sopme veroboard or an Arduino Shield depending on your application.

Arduino DCC Decoder Circuit

These are a couple of shield versions.The top one controls 4 servos, the lower one has a stepper motor driver for DCC control of a turntable.

Arduino DCC Decoder Shield

Additional Resource Links

ESP32 DCC Accessory Decoder 27/10/2021

#62 DCC decoder controlling servos and LED's 23/01/2024

Comments


This site has been designed to be child friendly, this means that comments cannot be added to directly to the site.
To add a comment or ask a question please email the address in this image: and use #79 DCC Decoder Circuit as a reference.