30 days of Pro free, no card →
Blog/Tutorial/Day and night lighting: an LED strip that dims slowly at dusk (Arduino + DCC)
Tutorial

Day and night lighting: an LED strip that dims slowly at dusk (Arduino + DCC)

At dusk, the ceiling LED strip dims slowly, then the street lamps come on. An Arduino Nano, a ready-made dimmer module and one DCC accessory command sent by LocoPilote: the full guide, with wiring diagrams.

Frédéric
Frédéric

Creator of LocoPilote

25 November 2026

📖 10 min read

Wiring diagram: the DCC track, the small interface, the Arduino Nano, the MOSFET module and the LED strip

At dusk, the ceiling LED strip dims slowly over two minutes. When it drops below a quarter of its brightness, the street lamps come on. At dawn, everything goes the other way. This guide shows how to do it with an Arduino Nano and a ready-made dimmer module.

ℹ️ LocoPilote 0.1.57, Pro plan

The day and night cycle is available from LocoPilote 0.1.57, in the Pro plan. This build works with any DCC command station.

How it works

LocoPilote sends a single command, and the Arduino does the fading.

  1. When dusk starts, LocoPilote switches a DCC accessory “on”, for example address 300.
  2. The Arduino listens to the track signal, like an accessory decoder, and receives that command.
  3. It dims the LED strip smoothly, along a curve that suits the eye.
  4. Below 25 %, it switches the street lamps on.
  5. At dawn, LocoPilote switches the same address “off”: the light comes back up.

There is nothing to program in LocoPilote: it is just one more accessory in the day and night cycle list.

Parts

The links are Amazon searches, not specific products: pick a well-rated offer.

PartQtyPurposeWhere to find it
Arduino Nano (CH340 chip)1The brain of the buildSearch “arduino nano”
Dual MOSFET module, 15 A, 5-36 V, with screw terminals1 (2 with street lamps)The LED strip dimmerSearch “dual mosfet module”
6N137 optocoupler + 8-pin socket1Reads the DCC signal without connecting the Arduino to the trackSearch “6N137”
1 kΩ resistor, 1/2 W1Limits the current from the trackSearch “resistor kit”
10 kΩ resistor, 1/4 W1Holds the 6N137 output at 5 V(same kit)
1N4148 diode1Protects the 6N137 inputSearch “1N4148”
100 nF capacitor (marked 104)1Steadies the 6N137 supplySearch “100nF”
Small perfboard + 2-way screw terminal1Holds the interfaceSearch “perfboard”
Closed 12 V power supply with jack plug1Powers the LED stripSearch “12V power supply LED strip”
Female jack adapter with screw terminals1Connects the supply without solderingSearch “female DC jack screw terminal”
Female-female Dupont wires1 packConnect the Arduino to the moduleSearch “dupont wires”

Choosing the power supply. Power = strip power per metre × length + 20 %. For example, 5 m of a 14.4 W/m strip make 72 W: take a 12 V supply of about 100 W. The power per metre is printed on the strip reel.

Choosing the module. Take a MOSFET module that accepts a 5 V control signal and a frequency of at least 16 kHz (the program works at 15.6 kHz), such as a dual MOSFET module rated 3.3 to 20 V signal, up to 20 kHz. Avoid modules with a PC817 optocoupler: too slow at that frequency.

The full wiring diagram

There are 6 connections. Only the first two, on the track and on the small board, need soldering. The rest uses Dupont wires and screw terminals.

Illustrated wiring diagram: the track, the DCC interface, the Arduino Nano, the MOSFET module, the 12 V supply and the LED strip
Red = plus, black = ground, yellow = DCC signal to the Arduino, green = strip control.
  1. Track: solder two wires to the rails (or to the command station’s track output), J and K, and run them to the interface terminal.
  2. Interface → Nano: 5V to 5V, GND to GND, and the SIG output to D2.
  3. Nano → module: D9 to the module’s PWM input, Nano GND to module GND.
  4. 12 V supply → module DC+ and DC−.
  5. LED strip → module OUT+ and OUT−: the strip’s + on OUT+.
  6. The Nano is powered by its USB cable, plugged into the PC or a 5 V charger.

For the street lamps, connect a second identical module to D10. If your street lamps already have a DCC decoder, keep it: just add its address to the day and night cycle list.

The DCC interface: the only part to solder

⚠️ Never connect the Arduino directly to the rails

The track voltage reaches 15-18 V and keeps reversing. An Arduino input takes 5 V at most: the board would be destroyed, and its ground would end up on the rails. The 6N137 optocoupler passes the signal through light, with no electrical contact between the track and the Arduino.

The interface fits on a small perfboard, with 5 components:

DCC interface wiring on a perfboard: J and K terminal, 1 kΩ resistor, 1N4148 diode, 6N137 optocoupler, 10 kΩ resistor, 100 nF capacitor and the 5V, SIG and GND outputs
Top view, the 6N137 notch at the top. Pins 1 and 4 are not used.
  1. Solder an 8-pin socket, then fit the 6N137, notch at the top.
  2. J (track) → 1 kΩ resistor → pin 2. K (track) → pin 3.
  3. 1N4148 diode between pins 2 and 3, band on the pin 2 side.
  4. Pins 7 and 8 together to the Nano 5V. Pin 5 → Nano GND.
  5. 100 nF capacitor between 5V and ground, right next to the chip.
  6. Pin 6 → Nano D2, and a 10 kΩ resistor between pin 6 and 5V.

The 1 kΩ resistor gets a little warm: use a 1/2 W one.

The program

The program is ready: you only set a few values at the top of the file. Its names and comments are in French; the table below explains them.

  1. Install Arduino IDE 2 from arduino.cc/en/software.
  2. Tools → Manage Libraries, search for NmraDcc and install it.
  3. Download the program: eclairage_jour_nuit.ino. Open it with the Arduino IDE; if it offers to create a folder of the same name, accept.
  4. Tools → Board → Arduino Nano. For a Nano with a CH340 chip, choose Tools → Processor → ATmega328P (Old Bootloader) if the upload fails.
  5. Check the settings at the top of the file, then click Upload.
  6. Open Tools → Serial Monitor at 115200 baud. Type n then j: the strip should dim then brighten, even with no DCC connected.
// ------------------------- REGLAGES ----------------------------------
const uint16_t ADRESSE = 300;              // adresse d'accessoire choisie dans LocoPilote
const bool     INVERSER = false;           // true si "allume" doit donner le jour
 
const unsigned long DUREE_VERS_NUIT_MS = 120000UL;  // crepuscule : 2 min
const unsigned long DUREE_VERS_JOUR_MS = 60000UL;   // aube : 1 min
 
const float NIVEAU_JOUR = 1.00;            // luminosite de jour (1.00 = 100 %)
const float NIVEAU_NUIT = 0.08;            // "clair de lune" (0 = noir complet)
 
const float SEUIL_ALLUMAGE   = 0.25;       // lampadaires allumes sous 25 %
const float SEUIL_EXTINCTION = 0.35;       // et eteints au-dessus de 35 %
SettingDefaultEffect
ADRESSE300The accessory address entered in LocoPilote
DUREE_VERS_NUIT_MS120000 (2 min)How long the strip takes to dim at dusk, in milliseconds
DUREE_VERS_JOUR_MS60000 (1 min)How long it takes to brighten at dawn
NIVEAU_NUIT0.08The night glow; 0 = fully dark. Keep it below 0.25, or the street lamps will not come on
SEUIL_ALLUMAGE0.25The strip level at which the street lamps come on
INVERSERfalseSet to true if day and night are swapped

After a power cut, the Arduino goes back to the last state it received.

Settings in LocoPilote

  1. Open Settings → Operation, section Day and night, and tick Enable the day and night cycle.
  2. Under Accessories, click + Add, then Command station and address. Choose your command station, enter address 300 and a name, for example “Ceiling”.
  3. In the list, set the Night column to on and the Day column to off.
  4. Match the durations: LocoPilote’s Dusk duration and the program’s DUREE_VERS_NUIT_MS. With the With the layout clock rhythm, the real duration is the transition divided by the clock factor: 60 minutes at ×30 make 2 minutes.
  5. Set the layout to Run and click ▶ Test the night now (30 s). The strip should start dimming.

The accessories in the list are sent one after the other, one every few seconds (the Switch on in cascade setting). With many accessories, the strip may therefore start a few seconds after dusk begins.

Troubleshooting

Keep the Arduino connected by USB with the serial monitor open: every DCC command it receives is shown with its address.

What you seeWhat to do
n and j do nothingCheck the D9 → PWM wire, the common GND and the module’s 12 V supply
No “DCC adresse” line when LocoPilote sends the commandThe interface does not see the signal: diode direction, 1 kΩ resistor, pins 7 and 8 to 5V, 10 kΩ to 5V
“DCC adresse 296” or “304” instead of 300Some command stations shift addresses by 4: put the value shown into ADRESSE
The strip lights up at night and dims during the daySet INVERSER to true
The strip flickers to the eye or on cameraModule too slow (PC817 optocoupler): use a MOSFET module without a PC817
Small visible steps at the end of the dimmingRaise NIVEAU_NUIT to 0.12, or set 0 for full darkness
The module gets hotToo much current: check the strip power, or share it between two modules driven by D9

Safety

  • Use a closed, CE-marked power supply with a jack plug: you never touch mains voltage.
  • Use wire of at least 0.75 mm² for a 5 m strip. If the far end of the strip is dimmer, feed it from the other end as well.
  • Leave some air around the power supply and the module.
  • Only the 6N137 interface touches the track: never a direct wire between the rails and the Arduino.

What’s next?

A solder-free version, with a ready-made Wi-Fi module, is in preparation: this guide will be updated. If you build this, send us a photo with the “?” button in the software: your feedback helps us improve these guides.

Haven't tried LocoPilote yet? Getting started with LocoPilote takes you from installation to your first running train, even without a command station.

Arduino and the other brands mentioned belong to their respective owners.

© 2026 LocoPilote — text and screenshots: reproduction prohibited without permission. Short quotes allowed with a link to this article. Legal notice

Share:
Frédéric

Frédéric

Creator of LocoPilote

Developer and railway modeller, creator of LocoPilote. Passionate about automating model railway layouts.

Related articles