Simple lighting controller

Oddly enough, laziness and discomfort pushed me to develop this device. Each time driving a car into the garage, in the dark, I constantly had to look for the treasured key to turn off the light to navigate when exiting. As a result, he began to ponder the methods of eliminating this problem. The first thing that came to mind, a ready-made motion sensor that is used for street lighting. But I did not want an easy way, I decided to make it myself. I started to scroll through various decisions in my head like a field meter on a field effect transistor and an antenna, IR transceivers in the doorway, and as a result, the bumpy path led me to the well-known HC-SR50 PIR sensor.
image

It is not expensive, its own power supply stabilizer (can be supplied from 5 to 20V), sensitivity adjustment of the detection radius (from 3x to 7 meters), detection angle (120-140, depends on the specific lens and type of sensor), adjustment of the release time, and there are two operating modes:

1. Single capture - in this mode, when the sensor is triggered several times in a row, a high logical level remains at its output.
2. Pulse capture - in this mode, a separate pulse appears at the output each time the sensor is triggered.

image

Having equipped such a sensor with a direct current source and a small board with a transistor switch, a pair of resistors, a diode and a relay, we get a finished device that can turn on and off our load when an object is in the sensor field.

image
After thinking further, I nevertheless decided to use a simple Attiny13 microcontroller and connect everything into one interconnected bundle: a key switch, a PIR sensor and also added a light level sensor (we will talk about it below).

The logic of the device:

  • The priority switch is always on the key switch, regardless of the level of illumination and the location of the object in the field of the PIR sensor.

  • After about 5 hours, when the key switch is on, the light will automatically turn off. Sometimes household members, and sometimes I myself forget to turn off the lights.

  • If the key switch is turned off, the object is in the PIR sensor field and it is dark outside (the photo sensor comes to the rescue), the light turns on and remains on until the object leaves the PIR sensor field.

  • If the key switch is turned off, the object is in the PIR sensor field and it is dark outside, the light turns on, and if the object leaves the PIR sensor field, the lighting continues to work for a period of time specified by the adjustment potentiometer on the PIR sensor from 5 seconds to 300 seconds.

  • If the key switch is turned off, the object is in the PIR sensor field and it is light outside, the light will not turn on until the light level falls to a predetermined threshold or the key switch turns on.

Next, an electrical circuit diagram was developed containing inexpensive and affordable components:

image

To power the circuit, a transformer with two 9V output windings (TPG-2) is used, the first winding is used to power the microprocessor part of the device and an external light level sensor. The second winding for powering the PIR sensor and relay coil. For 12V, a half-wave rectifier and an integrated voltage stabilizer were used, in this case I think this circuit is justified because the PIR sensor has its own voltage regulator. Transistor Q3 is used to coordinate the levels between the PIR sensor and the microcontroller, the output of the PIR sensor LVTTL with a maximum threshold of 3.3V. Transistor Q2 serves to indicate the status, transistor Q1 controls the winding of the power relay to which our lighting lamp is connected. A variable resistor is needed to adjust the sensitivity of the light sensor. Chain R2, D3, D6, C2 is needed to capture mains voltage from a key switch. Ripple bounce is handled by software.

To develop a light sensor, I used an imported phototransistor from my old deposits, I don’t even know the markings, but I think such BPW96C is suitable. Since the device is far from the street or any opening, I just can’t solder the phototransistor to the board, and I did not dare to draw a line of about 10 meters to the phototransistor, so I made a repeater on the Rail-to-Rail operational amplifier . But then I ran into problems with calibration, in general, the signal of the phototransistor was very small for normal operation, and I converted the repeater to a non-inverting amplifier with a gain of 2:

image

If you repeat the design and the phototransistor produces an appropriate level, instead of resistor R2, set jumper 1206 with 0 value, and exclude resistor R4 from the circuit. I had an NPN phototransistor, connected the collector pin J1-1, and the emitter pin J1-2.

Having assembled the light level sensor, I filled the circuit board with the Vixint PC-68 compound and put it in the heat shrink tube, leaving only the phototransistor hat with a window on the surface.

Controller Circuit Boards:

image

image

light level sensor:

image

image

Photo of the finished device at the debugging stage:

image

Connection diagram of all devices:

image

In addition, a second version of the printed circuit board was developed for a D3MG-type enclosure with a DIN rail and a connector for programming the AVRISP microcontroller (in the first version, I soldered wires with a connector to the board for programming). The microcontroller firmware is written in C in Atmel Studio.

The source code, two versions of printed circuit boards and circuit diagrams with lists of components (used CAD Dip Trace 3.0.0.1), as well as a simulation file for Proteus 8 can be found in the repository - LightController .

PS:before installation, the controller board and PIR sensor were opened just in case with two layers of zapon varnish. The device is connected to the network through a circuit breaker (the rating depends on the consumption of lamps), in my case, the machine is connected through a circuit breaker of 2 A.

Also popular now: