Light sensor switches

At the time of writing , I have made 3 versions of a light sensor switch:

A. An analogue version with a LDR , a NE555 to provide an ON/OFF threshold and an output transistor.

B. A modified Sonoff S26 Smart plug with a digital BH1750 light sensor and with Arduino software.

C. A modified Arduino Nano with a digital BH1750 light sensor, MOS-FET output and with Arduino software.

A. The simple analogue light sensor switch.

Made a simple light sensor to control an USB outlet to work at day light only. Power source is a small 60 W solar cell system:

The light sensor controls the power to the USB socket that provides power to the 12 V USB socket. The schematic for the light sensor switch with pot.meter to adjust the LDR threshold levels:

The LDR 5K Light Dependent Resistor and the 50K pot.meter sets the trig and threshold levels for the bright/dark relation for the SE555N comparator inputs. The BC639 transistor is able to sink 1 A to source the 12 V / 1A USB socket.

B. The smart plug with light sensor.

Made a light sensor using a modified Sonoff S26 smart plug with a BH1750 light sensor.

Inside the Sonoff S26 smart plug the I/O pins GPIO4 and GPIO5 are available for the I2C communication with the BH1750 light sensor, and is wired as shown above. A small Ø3.5 mm hole was made in the smart plug front cover part to let the light reach the BH1750 sensor chip.

The GY-302 PCB with the BH1750 light sensor was clued on the rear side of the front cover. The initial flashing of the ESP8266 went on as for the adaptive smart plug project.

I added a small web side to set the light levels for turning the smart plug output on and off:

The HTML slider scales has 240 steps, but the Lux values are power 2 of the step values:

The maximum  light level of 57600 lux is chosen ( max step value 240*240 ), because the highest value I could measure was 54613 lux using a Klarus A1 pocket light.  The light levels settings are saved in the ESP8266 internal flash memory. The Arduino source can be found here: Smart light plug .

C. The light sensor using a modified Arduino Nano and the BH1750.

This version controls the 5 V power via an USB cable depending on the light intensity. The light lux levels for switching the 5 V power ON/OFF are hard-coded in the Arduino Nano ATmega328p microcontroller. The lux levels are read with a GY-302 module with the BH1750 light sensor. To keep the power consumption low the following is made:

  1.  All active parts, except the microcontroller are removed from the Arduino Nano PCB, in this case I reused the Nano board from the Oldphone-4G project.
  2.  The microcontroller X-tal is replaced with a 12 MHz version .
  3. The ATmega328p DIV8 fuse is set to divide the clock with 8, thus providing a CPU clock frequency of 1.5 MHz.
  4.  The microcontroller wakes up from idle sleep every 8 sec. to read the current light lux level.
  5.  An AVR MKII programmer is used to flash the microcontroller via the Nano ISP connector and the Arduino IDE.
  6.  During idle sleep is the current consumption 2 mA.

The block diagram:

A simple schematic for the hardware setup, the parts in red frames are removed:

The Arduino IDE source is to be seen here: Nano_BH1750