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.

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.
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.
- When dusk starts, LocoPilote switches a DCC accessory “on”, for example address 300.
- The Arduino listens to the track signal, like an accessory decoder, and receives that command.
- It dims the LED strip smoothly, along a curve that suits the eye.
- Below 25 %, it switches the street lamps on.
- 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.
| Part | Qty | Purpose | Where to find it |
|---|---|---|---|
| Arduino Nano (CH340 chip) | 1 | The brain of the build | Search “arduino nano” |
| Dual MOSFET module, 15 A, 5-36 V, with screw terminals | 1 (2 with street lamps) | The LED strip dimmer | Search “dual mosfet module” |
| 6N137 optocoupler + 8-pin socket | 1 | Reads the DCC signal without connecting the Arduino to the track | Search “6N137” |
| 1 kΩ resistor, 1/2 W | 1 | Limits the current from the track | Search “resistor kit” |
| 10 kΩ resistor, 1/4 W | 1 | Holds the 6N137 output at 5 V | (same kit) |
| 1N4148 diode | 1 | Protects the 6N137 input | Search “1N4148” |
| 100 nF capacitor (marked 104) | 1 | Steadies the 6N137 supply | Search “100nF” |
| Small perfboard + 2-way screw terminal | 1 | Holds the interface | Search “perfboard” |
| Closed 12 V power supply with jack plug | 1 | Powers the LED strip | Search “12V power supply LED strip” |
| Female jack adapter with screw terminals | 1 | Connects the supply without soldering | Search “female DC jack screw terminal” |
| Female-female Dupont wires | 1 pack | Connect the Arduino to the module | Search “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.

- 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.
- Interface → Nano: 5V to 5V, GND to GND, and the SIG output to D2.
- Nano → module: D9 to the module’s PWM input, Nano GND to module GND.
- 12 V supply → module DC+ and DC−.
- LED strip → module OUT+ and OUT−: the strip’s + on OUT+.
- 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
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:

- Solder an 8-pin socket, then fit the 6N137, notch at the top.
- J (track) → 1 kΩ resistor → pin 2. K (track) → pin 3.
- 1N4148 diode between pins 2 and 3, band on the pin 2 side.
- Pins 7 and 8 together to the Nano 5V. Pin 5 → Nano GND.
- 100 nF capacitor between 5V and ground, right next to the chip.
- 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.
- Install Arduino IDE 2 from arduino.cc/en/software.
- Tools → Manage Libraries, search for NmraDcc and install it.
- 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.
- Tools → Board → Arduino Nano. For a Nano with a CH340 chip, choose Tools → Processor → ATmega328P (Old Bootloader) if the upload fails.
- Check the settings at the top of the file, then click Upload.
- Open Tools → Serial Monitor at 115200 baud. Type
nthenj: 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 %| Setting | Default | Effect |
|---|---|---|
ADRESSE | 300 | The accessory address entered in LocoPilote |
DUREE_VERS_NUIT_MS | 120000 (2 min) | How long the strip takes to dim at dusk, in milliseconds |
DUREE_VERS_JOUR_MS | 60000 (1 min) | How long it takes to brighten at dawn |
NIVEAU_NUIT | 0.08 | The night glow; 0 = fully dark. Keep it below 0.25, or the street lamps will not come on |
SEUIL_ALLUMAGE | 0.25 | The strip level at which the street lamps come on |
INVERSER | false | Set 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
- Open Settings → Operation, section Day and night, and tick Enable the day and night cycle.
- Under Accessories, click + Add, then Command station and address. Choose your command station, enter address 300 and a name, for example “Ceiling”.
- In the list, set the Night column to on and the Day column to off.
- 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. - 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 see | What to do |
|---|---|
n and j do nothing | Check the D9 → PWM wire, the common GND and the module’s 12 V supply |
| No “DCC adresse” line when LocoPilote sends the command | The 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 300 | Some command stations shift addresses by 4: put the value shown into ADRESSE |
| The strip lights up at night and dims during the day | Set INVERSER to true |
| The strip flickers to the eye or on camera | Module too slow (PC817 optocoupler): use a MOSFET module without a PC817 |
| Small visible steps at the end of the dimming | Raise NIVEAU_NUIT to 0.12, or set 0 for full darkness |
| The module gets hot | Too 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

Frédéric
Creator of LocoPilote
Developer and railway modeller, creator of LocoPilote. Passionate about automating model railway layouts.
Related articles
An ESP32-CAM camera in my loco: the step-by-step guide
An ESP32-CAM board films the track from the loco and sends the picture over Wi-Fi; LocoPilote shows it in the Cab. The full guide, from installing Arduino to the first test, without writing any code.

Getting started with LocoPilote: your first train, no hardware needed
From creating your account to a first train stopping at the station: LocoPilote's welcome steps one by one, with no command station or layout connected.

Blocks and detection: stopping a train in the right place with a single detector
One block, one detector, and the train still stops in the middle of the platform: how LocoPilote computes the stop, and what makes it accurate.