Projects / Wardrobe light that turns on with the door

Wardrobe light that turns on with the door

Beginner1 hGuided buildReviewed

Build it step by step

0 of 6 done
  1. NANO

    Fix the reed switch

    Stick the switch on the door frame and the magnet on the door so they touch when closed.

  2. NANOIRLZ4417.4 mA

    Build the switch

    MOSFET gate to D9 with a 10 kΩ to GND, source to GND, drain to the strip negative.

  3. NANO12DC17.4 mA

    Wire the power

    Adapter + to the strip + and VIN, adapter - to the common ground.

  4. NANO17.4 mA

    Upload and test

    Open the door and the strip should fade up, close it and it fades off.

  5. NANO

    Test the time-out

    Change TIMEOUT_MS to 10 seconds, check, then set it back to 5 minutes.

  6. NANO

    Hide the wiring

    Run the thin wires along the frame with cable clips.

In short

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

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
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 sourceCommon ground
LED strip -MOSFET drainLow-side switching
MOSFET gateNano D9PWM from Nano
10 kΩ resistorBetween MOSFET gate and GNDKeeps the gate off while the Nano boots
Reed switchNano D2 and GNDClosed 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.

CheckExpected
Door closedStrip off, reed switch reads closed on the multimeter
Door openStrip fades up to full in about a second
Door open for the time-outStrip fades off
MOSFET temperature after 10 minutesBarely 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 →

Ask Lark AI

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.