Wardrobe light that turns on with the door
Build it step by step
0 of 6 doneFix the reed switch
Stick the switch on the door frame and the magnet on the door so they touch when closed.
Build the switch
MOSFET gate to D9 with a 10 kΩ to GND, source to GND, drain to the strip negative.
Wire the power
Adapter + to the strip + and VIN, adapter - to the common ground.
Upload and test
Open the door and the strip should fade up, close it and it fades off.
Test the time-out
Change TIMEOUT_MS to 10 seconds, check, then set it back to 5 minutes.
Hide the wiring
Run the thin wires along the frame with cable clips.
How do you build a wardrobe light that turns on with the door?
A reed switch turns on an LED strip when a wardrobe door opens and turns it off when it closes, with a time-out if the door is left open. You need Arduino Nano, Door reed switch MC-38, MOSFET IRLZ44N, Resistor 10 kΩ, 12 V LED strip warm white (5 m, 2835), 12 V 2 A DC adapter, DC barrel to screw terminal adapter (female) and Jumper wires male to male (40 pcs, 20 cm). It takes 6 steps and about 60 minutes.
- Level
- Beginner
- Time
- About 60 min
- Parts
- 8
Parts list
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- SemiconductorsBuyMOSFET IRLZ44N × 1
- PassivesBuyResistor 10 kΩ × 1
- OptoelectronicsBuy
- PowerBuy
- PowerBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| 12 V adapter + | LED strip + and Nano VIN (through the screw-terminal adapter) | Both run from 12 V |
| 12 V adapter - | Nano GND and the MOSFET source | Common ground |
| LED strip - | MOSFET drain | Low-side switching |
| MOSFET gate | Nano D9 | PWM from Nano |
| 10 kΩ resistor | Between MOSFET gate and GND | Keeps the gate off while the Nano boots |
| Reed switch | Nano D2 and GND | Closed when the magnet is next to it |
Code
Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones). No libraries. The Nano's VIN pin accepts 7 to 12 V, but at 12 V its regulator runs warm, so keep it ventilated. A 9 V supply for both the Nano and strip also works if the strip is 12 V rated.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
const byte REED = 2, GATE = 9;
const unsigned long TIMEOUT_MS = 5UL * 60UL * 1000UL;
byte level = 0;
unsigned long openedAt = 0;
void fadeTo(byte target) {
while (level != target) {
level += (level < target) ? 1 : -1;
analogWrite(GATE, level);
delay(4);
}
}
void setup() {
pinMode(REED, INPUT_PULLUP);
pinMode(GATE, OUTPUT);
analogWrite(GATE, 0);
}
void loop() {
bool doorOpen = digitalRead(REED) == HIGH; // magnet away means the switch is open
if (doorOpen) {
if (openedAt == 0) { openedAt = millis(); fadeTo(255); }
if (millis() - openedAt > TIMEOUT_MS) fadeTo(0); // stay off until the door closes and opens again
} else {
openedAt = 0;
fadeTo(0);
}
delay(20);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Door closed | Strip off, reed switch reads closed on the multimeter |
| Door open | Strip fades up to full in about a second |
| Door open for the time-out | Strip fades off |
| MOSFET temperature after 10 minutes | Barely warm, which means the gate is fully on |
If it does not work
Strip is on all the time
The MOSFET is wired backwards or has a short. Check gate, drain and source pins.
Strip is dim
The gate is not driven fully. Use a logic-level MOSFET like IRLZ44N and check ground is shared.
Strip flashes when the door moves
The magnet gap is too large. Move the magnet closer.
Nano resets
The 12 V supply is too weak or the wires are too thin for the strip's current.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the wardrobe light that turns on with the door?
Arduino Nano, Door reed switch MC-38, MOSFET IRLZ44N, Resistor 10 kΩ, 12 V LED strip warm white (5 m, 2835), 12 V 2 A DC adapter, DC barrel to screw terminal adapter (female) and Jumper wires male to male (40 pcs, 20 cm).
How long does the wardrobe light that turns on with the door take to build?
About 60 minutes for a beginner maker, in 6 steps.
How do I know the wardrobe light that turns on with the door works?
Door closed: Strip off, reed switch reads closed on the multimeter. Door open: Strip fades up to full in about a second. Door open for the time-out: Strip fades off.
Strip is on all the time: what should I check?
The MOSFET is wired backwards or has a short. Check gate, drain and source pins.
Strip is dim: what should I check?
The gate is not driven fully. Use a logic-level MOSFET like IRLZ44N and check ground is shared.
Strip flashes when the door moves: what should I check?
The magnet gap is too large. Move the magnet closer.
Nano resets: what should I check?
The 12 V supply is too weak or the wires are too thin for the strip's current.
