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.
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.
Next Place the 1N4148 diode, Make sure you have it the correct way round.
Next add the 1K Ohm resistor. Note that it is it connects to the same pin as the diode.
Now add the blue jumper wire.
Now add the first 10K Ohm resistor
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
Now add the Orange jumper. This connects the end pin of the optoisolator to the same row of pins as the 10K Ohm resistors
Now connect the 2 green jumpers that will cponnect to the DCC output, either from the track or directly from your DCC Base station.
This image shows the two green wires connected to my DCC controller outputs.
Next connect the black Gnd jumper
This will connect to the Arduino/ESP32 Gnd
Next connect the Yellow jumpr to the pin next to the Gnd jumper.
This connects to pin 2 on the Arduino Uno and by defauklt I use pin 4 on my ESP32 boards.
Finally install the Red jumper.
This connects to the Arduino 5v or the ESP32 3.3v
The final set up should look like this.
Once you have a working version it's best to solder the components onto sopme veroboard or an Arduino Shield depending on your application.
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.
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.