[DIY] Auto-Sensing Night Light——No More Stumbling in the Dark at Night

——Yhue

Preface

It all started with a simple idea: Wouldn’t it be great to have an automatic night light when getting up at night—one that isn’t too bright to hurt your eyes, but soft enough to light up the room?

So I ordered a few USB night lights and USB female sockets online. The sockets didn’t come with pins, so I soldered them myself—problem one solved: the light source.

For motion detection, I used a PIR (Passive Infrared) sensor. The sensitivity and delay time can be adjusted. Since it couldn’t be fixed directly to the breadboard, I just aimed it toward the desired direction. There are smaller versions suitable for breadboards, but they continuously output a high signal, so I went with the larger one for now.

Hardware Preparation

  • Ai-M61-32S Development Board
  • USB Female Port
  • PIR sensor / Rd-03 Radar Module
  • One USB Night Light Bulb
  • Breadboard
  • Several Jumper Wires
  • Power Source (a power bank was used here for portability) 

Implementation

Connect the 5V and GND pins on the board to the PIR sensor. The sensor's output pin connects to IO0. Plug the USB light into the female socket and mount it on the breadboard. Connect the positive terminal to IO33 and the negative to GND. Now the circuit is complete.

 

Code Logic: 

 Monitor the input from IO0. When a high signal is detected (indicating motion), turn on the USB light by setting IO33 high. Keep it on for 3 minutes, then turn it off. This loop repeats continuously.

After one night of testing, it triggered correctly once, and another time there was a delay. The detection success rate was not entirely satisfying.

 

Improvements

In cold winter environments, and when wearing thick clothes, PIR sensors often perform poorly. I happened to discover the Rd-03 radar module from Ai-Thinker, which uses active radar detection rather than passive infrared—making it more robust, less sensitive to environmental temperature, and more resistant to interference.

So I quickly ordered one Rd-03 module and a radar debugging board.

The Rd-03 also comes with a visual configuration tool, allowing you to set detection range and delay time. This simplifies the MCU logic, as the radar module can now handle timing for how long the light stays on.

     

After the upgrade: The PIR sensor was replaced with the Rd-03 radar. Human detection is now highly responsive—the light turns on instantly when someone approaches. The IO wiring required minimal changes.

Future Plans

I'd like to explore the Wi-Fi and MQTT capabilities of the board, and add a feature to log the number of triggers to analyze areas for improvement.