Build it step by step
0 of 7 doneTest the PIR
Print its output when you move.
Test the LDR
Print its reading in light and dark.
Wire the MOSFET
Dim the strip with PWM.
Add the dark rule
React only in the dark.
Add the soft fade
Move one step each 15 ms.
Add the hold time
Fade out after 60 seconds.
Mount under the bed
PIR facing the floor, strip hidden.
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
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- SensorsBuy
- PassivesBuyResistor 10 kΩ × 2
- SemiconductorsBuyMOSFET IRLZ44N × 1
- OptoelectronicsBuy
- PowerBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| AM312 VCC and GND | Nano 5V and GND | Power |
| AM312 OUT | Nano D2 | Motion signal |
| LDR one leg | Nano 5V | Top of the divider |
| LDR other leg and 10 kΩ | Nano A0, 10 kΩ to GND | Light level |
| Nano D5 | MOSFET gate | PWM dimming |
| 10 kΩ resistor | MOSFET gate to source | Keeps the strip off at power-up |
| MOSFET source | Nano GND and 12 V adapter minus | Common ground |
| MOSFET drain | LED strip minus | Switched return |
| 12 V adapter plus | LED strip plus and Nano VIN | Power |
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.
| Check | Expected |
|---|---|
| Bright room, move | Light stays off |
| Dark room, move | Strip fades up to dim |
| Stand still for a minute | Fades out |
| Power on | Strip 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 →
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.
