Projects / Battery motion night light

Battery motion night light

Beginner1 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. motion

    Test the PIR

    Print its output on a serial test sketch.

  2. 131 lux

    Test the LDR

    Read it in light and dark.

  3. IRLZ44

    Wire the MOSFET

    Gate resistor and pull-down.

  4. Write the sleep code

    Wake on pin change.

  5. motion

    Add the 30 second hold

    Restart on each motion.

  6. Measure standby

    Use a multimeter in series.

  7. motion

    Fit it behind the wardrobe or hall wall

    Point the PIR along the path.

In short

How do you build a battery motion night light?

A mini PIR and LED strip run on AA batteries and light a hallway at night only when someone walks by. You need AM312 mini PIR motion sensor, ATtiny85-20PU microcontroller, LDR Photoresistor, MOSFET IRLZ44N, 12 V LED strip warm white (5 m, 2835), Battery holder 4 × AA with switch, AA alkaline battery × 3, Resistor 10 kΩ × 2 and Resistor 220 Ω. It takes 7 steps and about 60 minutes.

Level
Beginner
Time
About 60 min
Parts
9

Parts list

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

Wiring

FromToWhy
Battery holder plusATtiny85 pin 8, AM312 VCC and strip plus4.5 V from three AA cells (a shorting link in the fourth slot)
Battery holder minusATtiny85 pin 4, AM312 GND and MOSFET sourceGround
AM312 OUTATtiny85 PB2 (pin 7)Motion signal
LDR and 10 kΩ dividerATtiny85 PB3 (pin 2), top of the divider from PB4 (pin 3)Darkness sensing (powered only while reading)
ATtiny85 PB1 (pin 6)220 Ω to the IRLZ44N gate, with 10 kΩ gate to groundStrip switch
IRLZ44N drainStrip minusSwitched ground
Strip plusBattery plusLED supply

Code

The AM312 draws only about 12 microamps, and the ATtiny85 sleeps at a few microamps, so standby is tiny; the main drain is the strip while it is on. Four AA cells give 6 V, which is above the ATtiny85's limit, so use three cells and a shorting link in the fourth slot for 4.5 V; a 5 V strip then runs a little dim, which suits a night light. The LDR divider is powered from a pin only for the few milliseconds of each reading, so it does not leak current all day. Estimate battery life: 2000 mAh divided by the average of standby plus the strip's current times its on-time per day. A short strip of about 10 LEDs at 100 mA for 2 minutes a day uses only about 3 mAh a day.

Runs on a virtual ATtiny85 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).

// Battery motion light: sleeps in power-down, wakes on motion, lights the strip if it is dark for 30 s.
// Board: ATtiny85 (ATTinyCore, 1 MHz internal). Program with Arduino as ISP.
#include <avr/sleep.h>
#include <avr/interrupt.h>
#include <avr/power.h>
const int PIR = 2, LDR_ON = 4, LDR_IN = A3, STRIP = 1;
const int DARK = 600;                               // higher value = darker; tune for your room
ISR(PCINT0_vect) {}                                 // wake only
bool isDark() {
  pinMode(LDR_ON, OUTPUT); digitalWrite(LDR_ON, HIGH);
  delay(5);
  int v = analogRead(LDR_IN);
  digitalWrite(LDR_ON, LOW); pinMode(LDR_ON, INPUT);
  return v < DARK;                                  // LDR on the low side: less light = lower reading
}
void sleepNow() {
  GIMSK |= _BV(PCIE); PCMSK |= _BV(PCINT2);
  ADCSRA &= ~_BV(ADEN);                             // ADC off to save current
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable(); sei(); sleep_cpu(); sleep_disable();
  ADCSRA |= _BV(ADEN);
}
void setup() {
  pinMode(PIR, INPUT); pinMode(STRIP, OUTPUT); digitalWrite(STRIP, LOW);
}
void loop() {
  sleepNow();
  if (digitalRead(PIR) == HIGH && isDark()) {
    digitalWrite(STRIP, HIGH);
    unsigned long t = millis();
    while (millis() - t < 30000UL) { if (digitalRead(PIR) == HIGH) t = millis(); }
    digitalWrite(STRIP, LOW);
  }
}

Test checklist

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

CheckExpected
Daylight and motionStrip stays off
Dark and motionStrip lights for 30 s
Keep movingLight stays on
StandbyUnder 50 microamps

If it does not work

Never lights

Tune the DARK threshold.

Lights in daylight

Check the LDR divider side.

Flickers

Check the MOSFET is the logic-level IRLZ44N and the supply.

Short battery life

Measure standby for a leaking part.

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

Ask Lark AI

Common questions

What parts do I need for the battery motion night light?

AM312 mini PIR motion sensor, ATtiny85-20PU microcontroller, LDR Photoresistor, MOSFET IRLZ44N, 12 V LED strip warm white (5 m, 2835), Battery holder 4 × AA with switch, AA alkaline battery × 3, Resistor 10 kΩ × 2 and Resistor 220 Ω. 12 V LED strip warm white (5 m, 2835): Use a 5 V strip for battery use.

How long does the battery motion night light take to build?

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

How do I know the battery motion night light works?

Daylight and motion: Strip stays off. Dark and motion: Strip lights for 30 s. Keep moving: Light stays on.

Never lights: what should I check?

Tune the DARK threshold.

Lights in daylight: what should I check?

Check the LDR divider side.

Flickers: what should I check?

Check the MOSFET is the logic-level IRLZ44N and the supply.

Short battery life: what should I check?

Measure standby for a leaking part.