I recently dismantled a small Arduino Nano project I did for our little Christmas tree; an Arduino controlled string of USB lights. The new project is a motion-activated nightlight in a mason jar. Basically the same string of lights that fades on when motion is detected and stays on for a brief time, then fades off. I also added an LM393 light sensor to prevent the nightlight from turning on in the presence of other light, to save battery and because I can. Anything worth doing is worth over-doing, right?
In my testing, I got everything working fine while plugged into my laptop but as soon as I went to battery power, the circuit just bounced; the lights faded on, then faded off and right back on in a ceaseless loop. When I measured the voltage reaching the sensor while on battery power, I found it to be 3.2v, which turns out to be below the 4.5v minimum-threshold for the HC-SR505 Mini PIR Motion Sensor. So I suspect when it’s underpowered, it sends botched signals—or basically always high or positive for motion.
In checking the voltage provided by the 5v pin of the Nano-knockoff, I found it to be 4.2v when plugged into my laptop and 3.8v when plugged into the battery. I found the same results when running an arbitrary pin as output/high.
I guess that’s the price you pay for using cheap knock-offs!
The code for the jarlight: