Projects / Under-bed night light

Under-bed night light

Beginner1 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANOmotion

    Test the PIR

    Print its output when you move.

  2. NANO525 lux

    Test the LDR

    Print its reading in light and dark.

  3. NANOIRLZ4414.1 mA

    Wire the MOSFET

    Dim the strip with PWM.

  4. NANO

    Add the dark rule

    React only in the dark.

  5. NANO

    Add the soft fade

    Move one step each 15 ms.

  6. NANO

    Add the hold time

    Fade out after 60 seconds.

  7. NANOmotion

    Mount under the bed

    PIR facing the floor, strip hidden.

In short

How do you build an under-bed night light?

A PIR under the bed turns on a dim warm LED strip when your feet touch the floor at night, so you do not wake everyone. You need Arduino Nano, AM312 mini PIR motion sensor, LDR Photoresistor, Resistor 10 kΩ × 2, MOSFET IRLZ44N, 12 V LED strip warm white (5 m, 2835) and 12 V 2 A DC adapter. It takes 7 steps and about 60 minutes.

Level
Beginner
Time
About 60 min
Parts
7

Parts list

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

Wiring

FromToWhy
AM312 VCC and GNDNano 5V and GNDPower
AM312 OUTNano D2Motion signal
LDR one legNano 5VTop of the divider
LDR other leg and 10 kΩNano A0, 10 kΩ to GNDLight level
Nano D5MOSFET gatePWM dimming
10 kΩ resistorMOSFET gate to sourceKeeps the strip off at power-up
MOSFET sourceNano GND and 12 V adapter minusCommon ground
MOSFET drainLED strip minusSwitched return
12 V adapter plusLED strip plus and Nano VINPower

Code

The small PIR under the bed frame faces the floor, so it sees your feet and not the whole room. The light only reacts when the LDR says it is dark, so it stays off in the day. The strip fades up to 20 percent and fades out after a minute without movement, which is gentle on sleepy eyes. The MOSFET turns the 12 V strip on and off quickly (PWM) to dim it; its gate resistor to ground keeps the strip off when the Nano starts. Mount the strip below eye level and use warm white. Keep the 12 V adapter, wires and the Nano out of reach and away from bedding, and use a fuse on the 12 V lead. A PIR can be set off by a pet; that is fine here. Arduino IDE, board "Arduino Nano" (try the Old Bootloader option if the upload fails).

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).

// Under-bed night light. Board: Arduino Nano. No libraries.
const int PIR = 2, LDR = A0, GATE = 5;
const int DARK = 250;                          // below this the room is dark (0 to 1023), tune it
const int LEVEL = 51;                          // 20 percent of 255
const unsigned long HOLD_MS = 60000;           // stay on for 60 s after the last movement
int bright = 0; unsigned long lastMotion = 0; bool on = false;

void setup() { pinMode(PIR, INPUT); pinMode(GATE, OUTPUT); analogWrite(GATE, 0); }

void loop() {
  bool dark = analogRead(LDR) < DARK;
  if (digitalRead(PIR) && dark) { lastMotion = millis(); on = true; }          // movement in a dark room
  if (on && millis() - lastMotion > HOLD_MS) on = false;                        // fade out after a minute of stillness
  int target = on ? LEVEL : 0;
  if (bright < target) bright++; else if (bright > target) bright--;           // one step every 15 ms for a soft fade
  analogWrite(GATE, bright);
  delay(15);
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Bright room, moveLight stays off
Dark room, moveStrip fades up to dim
Stand still for a minuteFades out
Power onStrip is off

If it does not work

Strip flickers

Check the grounds and the gate resistor.

Never turns on

Raise DARK or check the PIR output pin.

Always on

Lower DARK or aim the PIR away from heat.

Strip glows when off

Check the gate pull-down resistor.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the under-bed night light?

Arduino Nano, AM312 mini PIR motion sensor, LDR Photoresistor, Resistor 10 kΩ × 2, MOSFET IRLZ44N, 12 V LED strip warm white (5 m, 2835) and 12 V 2 A DC adapter.

How long does the under-bed night light take to build?

About 60 minutes for a beginner maker, in 7 steps.

How do I know the under-bed night light works?

Bright room, move: Light stays off. Dark room, move: Strip fades up to dim. Stand still for a minute: Fades out.

Strip flickers: what should I check?

Check the grounds and the gate resistor.

Never turns on: what should I check?

Raise DARK or check the PIR output pin.

Always on: what should I check?

Lower DARK or aim the PIR away from heat.

Strip glows when off: what should I check?

Check the gate pull-down resistor.