Motion Triggered Room Light

Motion Triggered Room Light PART NO. 2184587 This project is to build a power switch that is controlled by a motion detector and a light sensor. An ex...
1 downloads 0 Views 3MB Size
Motion Triggered Room Light PART NO. 2184587 This project is to build a power switch that is controlled by a motion detector and a light sensor. An extension cord is cut in half and connected to an electromechanical relay to supply power to an AC appliance such as a desk light. The relay switches on the light at night when motion is detected. A Passive Infra Red (PIR) motion sensor is used to detect motion and a CDS photo resistor to detect ambient light. During day time, the power is always switched off. At night, the power is immediately turned on when motion is detected. After several minutes without any motion activity, the power is switched off. Any motion detected before power off resets the timer.

Time Required: 12 hours depending on experience Experience level: Intermediate

Video Demonstration Warning: This project involves working with AC power from the wall outlet. Safety measures must be exercised. The project steps have been designed to reduce AC power hazard. Follow the construction procedure carefully. Read all instruction before starting construction.

Kit Overview Circuit Schematics

Circuit Operation The basic building blocks of the electronic circuit are: 1. Motion and light sensors module. 2. Timer delay circuit. 3. Relay on/off control. 4. Power supply.

Motion and light sensors The Passive Infra Red (PIR) motion detector senses infra red radiation from human body heat. When there is a sudden change in the PIR reading, the sensor signals the motion with a 5V logic high signal on the MOTION line. It returns to logic low (0V) when dormant (no motion activity detected).

A CDS photo resistor changes its resistance from several K Ohms in daylight to several M Ohms in darkness. In a typical room during evening when lighting becomes necessary, the resistance reading is about 50K – 100K Ohms. The resistance of the light sensor and R1 produces a voltage at the OPTO line. Stronger light intensity corresponds to higher voltage. For the particular sensor and R1 used, daylight condition typically produces voltage above 3.0V. Voltage below 1.5V corresponds to poor lighting condition such as an unlit room in late evening.

Day and night modes When the OPTO line voltage exceeds a certain threshold voltage VH, the circuit goes into the day mode. The relay will never be turned on in this mode. When the sensor reading falls below a certain voltage level VL, the circuit enters the night mode. The relay can be triggered by the motion detector in the night mode only. LED-Y (yellow) indicates the night mode with pin 13 of U1C near zero Volt. Typically VH is set at about 3.0V and VL at 1.5V. The two voltages are adjustable by VR1 and VR2. The voltage difference is called hysteresis voltage. Hysteresis is necessary to prevent the circuit from switching from the night mode to the day mode when the room light is turned on. Without hysteresis, turning on the room light at night could trigger the day mode, which turns off the room light, causing the light to go into on/off oscillation. For proper operation, it is also important to keep the switched light source away from the light sensor to keep its voltage below the hysteresis barrier. C1 limits this oscillation frequency to about one second by limiting the rate at which the light sensor voltage can change. The light sensor voltage is monitored by U1C. The trimmer pot VR1 adjusts the midpoint of VH and VL. The hysteresis voltage is set by the ratio of VR2 and R3. A larger resistance of VR2 increases the voltage feedback from the output of U1C resulting in larger hysteresis voltage gap.

Dormant delay and motion reset When no motion is detected, we want the light to stay on for several minutes before turning off. This delay is achieved by discharging C2 with a tiny input bias current of the comparator LM339. Comparator U1A receives signal from the motion detector at pin 4 of LM339. The reference voltage at pin 5 is set by the voltage divider of R8 and R9 at 2.5V, the midpoint of the motion sensor’s MOTION line. When triggered, the motion detector sends a high signal causing the output pin 2 to go low. This immediately charges capacitor C2 causing pin 6 of U1B to be near zero volt. LM339 comparators have open collector outputs and very low input bias current. When the motion detector becomes

inactive, the output transistor of pin 2 will be switched off. This isolates C2 to ground and the input bias current of pin 6 starts to discharge C2. With 25nA typical discharge current, it takes several minutes to discharge C2 to trip the output of U1B. The trip voltage is set at about 8V. If any motion is detected before tripping, the capacitor will immediately be charge to full by pin 2 and the time delay is reset. Pin 6 input bias current is sensitive to temperature variation. The two switches connected to C2A and C2B increase the capacitance to lengthen the time delay. The on/off combinations of the two switches allow four different time delay settings. R12 provides a positive feedback voltage since pin 6 has a very slow moving signal. This prevents U1B output from chattering near the switching point. The operations of the signals are shown below:

Relay on/off control U1D is a logic decision gate that decides whether the relay should be turned on or off. Pin 8 receives relay control signal from the time delay circuit output pin 1. The high signal (motion detected) is set at 8V by R10, R11, while the dormant signal is at 0V. Pin 9 receives the day/night mode signal. The high signal (day mode) is near 12V while the low signal (night mode) is set by R5 and R6 to be 4V. The two signals results in the following 4 states, only one of which will turn on the relay:

Day/Night mode pin 9

Relay control pin 8

Relay on/off pin 14

Day = 12V

Motion = 8V

Off = 12V

Day = 12V

Dormant = 0V

Off = 12V

Night = 4V

Motion = 8V

On = 0V

Night = 4V

Dormant = 0V

Off = 12V

Q1 operates as a switching transistor to drive the relay and LED-R (red). D1 absorbs the energy of the relay coil to avoid flyback voltage against Q1.

Power supply The power supply is provided by a 12VAC transformer, through a bridged rectifier DB1 and LM7812 voltage regulator for a 12VDC operation. Another voltage regulator LM78L05 provides 5V power supply to the motion and light detection module. The entire circuit only consumes about 15mA during standby and about 75mA when the relay is turned on. Most of the current is consumed by the relay and LEDs. The motion sensor only consumes a few mA and the control circuitry based on LM339 consumes even less. LED-G (green) is always on to indicate the status of power supply. The extension cord is cut in the middle and reconnected inside the project enclosure box. The fuse protects against overloading and unforeseen AC hazards.

Required tools or supplies not included          

Household extension cord, 2 conductor, 3 - 6 ft. Four-conductor low voltage phone wires, for example Jameco 2125851 with connectors removed. Similar wires taken from computer mouse or earphone are also suitable. Small plastic enclosure to house the motion detector and light sensor. Adhesive and fastener to secure components, circuit board and project enclosure. Soldering equipment. Digital Multimeter. Drill and hardware for enclosure box carpentry. Two 9V batteries, for testing purpose only. Alligator clips. Non-contact infrared thermometer.

Est. time required to complete: 10 - 20 hours

Motion detector used on a desktop computer switching a desk lamp (not shown).

Bill of Material Manufactur er Part Number CDS00018001

Jameco Part Number

10

1N914

36311

DIODE BRIDGE, 1A, 50V

1

DF005M

178001

Q1

PNP, general purpose, 40V, 200mA

10

2N3906BU

783455

RELAY

RELAY, SPDT, 12VDC, 360Ohm, 15A, 120VAC

1

144186

T1

STEP-DOWN TRANSFORMER, 120VAC/12VAC, 200mA

1

221292

U1

IC, QUAD COMPARATOR

1

IC socket, 14 pin DIP

1

U2

Standard Regulator 12 Volt, 1A, 3-Pin TO-220

1

LM7812

51334

U3

Standard Regulator 5 Volt, 0.14A, 3-Pin TO292

1

LM78L05

51182

FUSE

FUSE, 5x20mm, GMA, 3A, 250V

1

103924

Fuse Clips, 5mm, front leads

10

102860

ABS Plastic Enclosure, 4.9" x 2.5" x 1.5"

1

18914

PROTOBOARD, 4.1 x 2.4 inch

1

28178

Resistor, Trimmer, 500K

2

254044

DIP SW

Switch DIP ON OFF Single Pole, Single Throw 2 Slide

1

1951385

R1, R7

RESISTOR, 10K, 0.25W

10

2157167

R2, R8

RESISTOR, 390K, 0.25W

50

691489

R3, R13

RESISTOR, 1M, 0.25W

10

691585

Quan tity

Name

Component

CDSPHOTO

Photo resistor

1

D1

Diode switching, 100V, DO-35

DB1

VR1, VR2

LM339N

202403

23851 37197

R4, R14, R15 R5, R10, R12 R6, R9, R11

RESISTOR, 2K, 0.25W

50

690937

RESISTOR, 51K, 0.25W

50

691278

RESISTOR, 100K, 0.25W

10

2156084

C1

CAPACITOR, POLARIZED, 10uF, 50V

10

29891

C2, C2A

CAPACITOR, POLARIZED, 0.47uF, 50V

10

330465

C2B

CAPACITOR, POLARIZED, 1uF, 50V

10

29831

C3, C4

CAPACITOR, POLARIZED, 100uF, 50V

10

29962

LED-R

LED, Uni-Color, Red

10

2081932

LED-Y

LED, Uni-Color, Yellow

10

206480

LED-G

LED, Uni-Color, Green

10

333201

PIR-MD

PIR motion sensor

1

2082927

Component pin identification Component

CDS Photo resistor

D1, 1N914, Diode

DB1, DF005M, Diode Bridge

Q1, 2N3906

RELAY

Pin Identification

Schematic representation

T1, Transformer, 120VAC, 12VAC

U1, LM339

U2, LM7812

VI GND VO

(front view)

U3, LM78L05

VO GND VI

FUSE

VR1, VR2, Trimmer resistor

C2A, C2B DIP SW

LED-R, LED-G, LED-Y, LED, Red, Green or Yellow color

C1 – C4, Electrolytic Capacitor

R1 – R15, Resistor, 0.25W

PIR-MD, Motion Detector

Resistor color codes (5% error tolerance) Name

Value

Resistor color code

R1, R7 R2, R8 R3, R13 R4, R14, R15 R5, R10, R12 R6, R9, R11

10K 390K 1M 2K 51K 100K

Brown- Black -Orange-Gold Orange-White-Yellow-Gold Brown-Black-Green-Gold Red-Black-Red-Gold Green-Brown-Orange-Gold Brown-Black-Yellow-Gold

Project Steps Step 1: Sensor modules Objective: Construct and test the sensor module. The sensor module has four wires connected to the main unit: +5V GND MOTION OPTO

+5V power supply Ground Motion detected signal, 0 – 5V, active high Light intensity voltage

The PIR sensor, R1 and CDS photo resistor are soldered and housed in small plastic enclosures forming the sensor module. The enclosure must be non-conducting and opaque. Small soap box, cups, etc. are suitable. The prototype shown below used the plastic lid of a coffee can. Take precaution to provide sufficient insulation and avoid exposing metal parts of the components. The surface of the photo resistor without pin leads is sensitive to light. You might want to adjust its orientation so that it picks up the ambient light of the room while avoids pointing directly to the room’s light source to be switched on/off. This helps to keep the lighting feedback within the hysteresis voltage. The photo resistor is connected between the +5V and OPTO lines while R1 is between the OPTO and GND lines. The photo resistor should have a resistance less than 10K Ohms in very bright light condition, about 50K – 100K Ohms in dim light and more than 1M Ohms in darkness. The photo resistor and R1 produce a voltage at the OPTO line with brighter light having a higher voltage. When the construction is completed, perform Tests 1A – 1C to verify the sensor module’s operation.

CDS photo resistor

R1

PIR sensor

OPTO, VCC, GND, MOTION lines

CDS photo resistor, R1 and PIR motion detector soldered in the sensor module.

CDS photo resistor

PIR sensor

Front side of sensor module.

Test 1A: Sensor module current consumption Use a 9V battery as power supply and connect U3 (LM78L05) and the sensor module with alligator clips according to the circuit schematics. Beware of the pin polarity of LM78L05. Pin VI of LM78L05 is connected to battery +9V and VO is connected to +5V line of the sensor module. Verify that the voltage at the output of LM78L05 is 5.0V before connecting it to the sensor module. Leave the MOTION and OPTO and lines unconnected in this test. Be sure that the lines are not shorted together. Measure the current drawn by the sensor module. The PIR motion detector has a red LED inside the dome lens that will light up when triggered. This will increase the current consumption by about 2mA. Current consumption also increases slightly when the CDS photo resistor is under bright light. In any case, the total current consumption should be less than 5mA. If large current (e.g. more than 50mA) is observed, you might have a short circuit, wrong wiring of photo resistor, R1 or defective motion detector.

LM78L05

VI (+9V)

VO (+5V)

GND

Test 1A: Measuring the current consumption of the sensor module.

Test 1B: Motion detector signal Provide battery power to the motion sensor module as Test 1A. Measure the voltage of

the MOTION line to GND. When dormant, it should be near zero Volt. A reading below 1.0V is acceptable. Trigger the motion detector and the reading should be near 5.0V. Signal above 4.0V is acceptable. An internal jumper can adjust the sensing distance to “short” or “long”. You might want to take this opportunity to find out the effective coverage area and distance of the motion detector.

Test 1C: Light sensor voltage Provide battery power to the motion sensor module as Test 1A. Measure the voltage between the OPTO line and GND. This voltage is the divider between the photo resistor and R1. Cover the sensor module or shine light to simulate dark and bright condition. The measured voltage should be more than 3.0V in bright light condition and less than1.5V in dim light. Deviation up to 1.0V from this specification is acceptable because the trigger points are adjustable by VR1 and VR2. Make sure that the indicator LED light of the PIR motion detector does not interfere with the light sensor and affect its voltage reading. If it can swing the OPTO line voltage by more than 0.1V, reposition the CDS photo resistor away from the motion sensor’s dome.

Step 2: Component placement on circuit board Objective: Place circuit board components to ensure feasibility. This is a component planning step without soldering. Insert all components on the circuit board. The recommended component placement is given below. Some components may have slightly different sizes than the placement plan given and it may not be possible or necessary to have identical placement. Cut or trim your circuit board to fit the project enclosure space in this step. It is important to place all components before soldering to avoid time consuming rework. Use adhesive tape to secure IC sockets and components to the circuit board if necessary. Some soldering points are needed on the top side of the circuit board to connect the wires from the sensor module and power cord. Make sure that these soldering points have sufficient clearance from other components for easy soldering access. Components leads of resistors or capacitors are ideal for making these soldering points. You can also use header plug and pins for the sensor module wires. In the plan shown below, LED-R, LED-Y and LED-G are positioned at the side of the circuit board to avoid off-board wires. Do not drill holes on the enclosure in this step. Wait till Test 6B has been completed. You may need to reposition them due to wiring errors. Note that the bottom-view of the circuit board shown is left-right flipped.

The AC power lines of the extension cord will be connected to the relay to be switched on/off. Make sure that the relay pins are correctly identified using resistance measurement of your Digital Multimeter (DMM). The coil resistance should be about 360 Ohms. If the relay is not SPST type, it will have more than two switch contact pins. Make sure you identified the normally opened and normally closed pins correctly. Energize the relay coil with 12V DC battery power and measure the switch pins resistance to identify them. The datasheet of the relay may be outdated. Do not solely rely on the data sheet information to avoid AC power line hazard.

WARNING: Relay will be connected to AC power lines. Verify the pin configuration with your DMM. Do not solely rely on the datasheet information to avoid AC power line hazard. Datasheet may contain errors or may be outdated.

Step 3: Circuit board wiring Objective: Solder circuit board components and wires. After the previous step, we have established the component placement and how everything is to be fitted into the project enclosure box. We are ready to solder the components on the circuit board. It is recommended to start with the signal wiring before VCC and GND wiring. The excess component pin leads can be used for the front side soldering points. The circuit board is divided into HOT and COLD sections to identify the high voltage areas. Leave more room for the soldering points of extension cord because the wires are thicker. You can drill holes on the circuit board and use nuts and bolts for electrical connection. This method requires more space allocation. Do not install transformer T1 in this step. It will be done in a later step after battery powered testing for safety reason. However all wiring involving the transformer, relay and extension cord needs to be marked and reserved. The four wires from the sensor module need to be soldered in this step for testing. They will be reworked later to fit the wires inside the enclosure box.

Circuit board example at Step 3.

Wiring on back side of the circuit board at Step 3. Caution: Use the wiring plan as the reference. Do not use the prototype photos. The board and components provided may be different.

Step 4: Electronic circuit testing Objective: Test the operation of the electronic circuit with battery power. Prior to this step, all low-voltage wiring of the circuit has been completed. For safety reason, most of the testing will be done with battery power. After the electronic circuit and AC power supply are verified, they will be connected together at a later step. Completion of mechanical construction is not necessary at this step. Make sure that you follow the test procedures below in the order described. This is essential to ensure that you have wired the components properly. It also minimizes the risk of damaging ICs due to improper construction, soldering or defective components. When installing the LM339 to its socket, pay attention to the polarity. Wrong installation may cause permanent damage to the IC. Use the continuity test of DMM to check wiring and soldering when in doubt.

Warning: Follow the test procedures in the order described. Do not proceed to the next test until the current test has passed.

Test 4A: Component polarity The following components are polarized. Check to make sure that they have been wired properly: LED-R, LED-Y, LED-G, D1, DB1, C1 – C4, Q1, U1, U2, U3, T1, RELAY.

Test 4B: GND network continuity The purpose tests 4B and 4C is to make sure that the soldering work of the power supply network is good. This is done without the IC on the socket and no power supply to the circuit. Set your Digital Multimeter (DMM) to beeping continuity test or resistance measurement. Pick a component of the GND network, for example the negative pin of C1. Measure the continuity to every test-point listed below to ensure that the resistance is less than 1 Ohm.

Test 4B: Test-points for GND network continuity test. No power should be applied. Sensor module GND line U1 pin 12 U2 pin GND (center) U3 pin GND (center) D1 pin A DB1 negative pin LED-R, LED-G pins K R9, R11, C1, C3, C4 VR1, RELAY

Test 4C: VCC network continuity This test is the same as Test 4B but repeated for the VCC network. The following test points must be connected: Test 4C: Test-points for VCC network continuity test. No power should be applied. U1 pin 3 U2 pin VO U3 pin VI Q1 pin E LED-Y pin A R2, R6, R8, R10, R13, R15, C2, C4 DIP SW

Test 4D: IC pin short-circuit to VCC or GND This test ensures that no signal pin of U1 is shorted to the VCC or the GND network. Do not insert U1. Do not apply power to the circuit during this test. Set your DMM to beeping continuity test or resistance measurement. Measure the resistance of every pin at the IC socket to the GND line. The resistance should not be near zero, except for pin 12. Otherwise you have a short circuit at the pin. Repeat the same test for short-circuit to the VCC power network.

Test 4E: VCC to GND resistance In this test, we want to make sure that there is no short-circuit of the power supply network. Do not install U1. Do not apply power. Use a DMM to measure the resistance between pin 3 and pin 12 of U1 socket. It should be about 5K – 15K Ohms. The resistance is primarily from the internal resistance of U2, U3, the photo resistor and R1. If this resistance is only several Ohms, you definitely have a VCC to GND short circuit. Check your soldering work to locate the problem. Do not power up the circuit when there is a VCC to GND short circuit. Repeat the test on the two AC input pins of DB1. The resistance should be similar or higher than the VCC to GND resistance. If it is near zero, make sure that you have disconnected T1 from DB1. Also check the wiring and polarity of DB1. DB1 could be defective if T1 is disconnected but this test still fails. Due to the large capacitance of C3, the resistance measurement might need 30 seconds to settle to the final reading depending on the DMM.

Test 4F: Current consumption and AC to DC rectifier If all the above tests passed, you are ready to apply battery power. Use small, low power batteries. Two 9V batteries connected in series is recommended. Do not use lead-acid battery or any type that can supply high current. The circuit only draws up to 80mA during normal operation and testing. Do not install U1. Connect 18VDC battery power between the two AC pins of DB1. These are the two pins that are currently unconnected from T1. Measure the current consumption drawn at the battery. It should be no more than 10mA on top of the current measured in Test 1A (consumed by the sensor module). If the current consumption is significantly higher, remove power immediately and check for short-circuit, improper soldering, incorrect component values or defective components. If the current consumption is reasonable, LED-G will be on but LED-Y and LED-R will be off. If LED-R and/or the relay are on, check Q1 polarity and R7. Now, reverse the battery polarity so that voltage applied to the two AC pins of DB1 is reversed. The measured current should be the same (within 0.5mA). This verifies the AC to DC rectifying capability of DB1. Check the polarity of DB1 if this test fails.

Apply 18VDC between AC pins of DB1

Test 4F: Applying battery power between AC pins of DB1.

Test 4G: IC socket voltage levels Do not install U1. Connect 18VDC battery power between the two AC pins of DB1. Measure the voltages of the U1 socket pins. With the negative probe of DMM connected to pin 12, check the following voltages with the positive probe:

Test 4G: Voltage levels of IC socket with respect to GND. U1 not installed. Test point

Voltage

Note

Pin 3

12.0V

VCC power supply from the voltage regulator U2.

Pin 4

0.0V or 5.0V

See Test 1B, MOTION line voltage.

Pin 5

2.5V

Voltage divider of R8 and R9

Pin 7

8.0V

Voltage divider of R10 and R11

Pins 1 and 8

8.2V

Voltage divider of R12 and R13

Pin 10

0.0V to 6.7V

Pin 11

See Test 1C

Voltage divider of VR1 and R2 depending on the wiper of VR1 OPTO line voltage. Bright light exceed 3.0V. Low light below 1.5V

Caution: Do not install U1 into socket until Tests 4A – 4G have all passed to avoid damages to LM339. Check your soldering work if any test fails.

Test 4H: Basic circuit operation with LM339 If Test 4G passed, remove battery power and install U1 (LM339). Reapply power and measure the current consumption drawn at the battery. This current is now mainly affected by the relay. With the relay off, the current consumption should be slightly larger than the current observed in Test 4F because LM339 is now installed. If this current is more than 10mA compared to Test 4F, check the IC polarity. With the relay on, additional 40 – 60mA is drawn by the relay and LED-R. Remove the power immediately if the current consumption is out of range. LM339 may be installed incorrectly or defective. If the relay and LED-R does not turn on at all, check the polarity of D1. If the relay can turn on but not LED-R, check LED-R’s polarity or R14.

Test 4I: Day and night mode hysteresis voltage Apply 18VDC battery power between the two AC pins of DB1. This test verifies the hysteresis voltages of the day and night modes of U1C. First, adjust VR2 so that its resistance is near zero. Cover the sensor module with an opaque box allowing only some light to enter. Measure the voltage at pin 11 to GND. It should be about 1.0V. Increase or decrease the light entering the sensor module to reach this voltage. Precise control is not necessary as long as the voltage is stable. Now, adjust VR1 and observe LED-Y (yellow). When VR1’s wiper is dialed near GND, the voltage at pin 10 will fall below that of pin 11 and LED-Y should be turned off (day mode, pin 13 high). When the wiper is dialed to the other direction, LED-Y should be turned on indicating the night mode. This verifies that comparator U1C is operating properly. If this is not observed, check the polarity of LED-Y, the wiring and the values of VR1, VR2, R2, R3, R4, R5 and R6.

If the above test passed, dial VR1 so that the voltage at pin 10 is at 2.0V. This should correspond to the wiper position about 1/3 from the GND. With VR2 still at zero resistance, measure the voltage across C1 (the OPTO line). Slowly cover and uncover the sensor module to see that LED-Y can turn on/off when the voltage at C1 is above or below 2.0V. If your test environment is too dark, you may need to shine light into the sensor module to increase the voltage. We are now ready to verify the hysteresis voltage. Cover the sensor module so that the circuit is in night mode with LED-Y turned on. Increase the resistance of VR2 (from zero) to about 10% of the maximum value. Slowly uncover the sensor module to allow light to enter while observing the voltage at C1 and LED-Y. You should see that it now takes more than 2.0V to go from night to day mode. At the same time, it also takes less than 2.0V to go from day to night mode. These two voltages observed are VH and VL described in the Circuit Operation section. Increase VR2 resistance 10% further. You should see that VH increases while VL decreases which means that a larger difference in light intensity is needed to switch between day/night modes. Both voltages also rise and falls with the reference voltage set by VR1. Repeat this test for higher resistance of VR2 to understand the useful range setting. When VH is too high or VL is too low, it becomes impossible to switch mode because the OPTO line voltage swing cannot overcome VH or VL.

Test 4J: Motion trigger We have verified the motion detection capability of the detector module in Test 1B. This test verifies the motion trigger and delay operation of LM339. Apply 18VDC battery power between the two AC pins of DB1. Measure the voltage at pin 2 (negative probe of DMM) to VCC (positive probe of DMM). This is the voltage across C2. When the motion detector is triggered, U1A output transistor turns on and the measured voltage should be 12.0V, verifying that C2 is charged. When the MOTION line reverts to the dormant voltage, the capacitor should be slowly discharged by the input current of pin 6 during normal operation. However when the DMM is connected, the internal resistance of the DMM is much lower than the input resistance of pin 6. The DMM provides a faster leakage path to discharge C2. You should see that the voltage drops quickly and reaches zero in about 30 seconds depending on the internal resistance of the DMM. (The voltage cannot be measured with the DMM connected between pin 2 and GND because the internal resistance of the DMM will charge C2 even when pin 2 is off.) If the capacitor cannot be charged, check the MOTION line voltage and the reference voltage at pin 5 (see Test 4G). If the above test passed, we want to further verify that the signal at pin 1 is correct. If you have a second DMM, use it to measure the voltage of pin 1 to GND. If you only have one DMM, connect a 1M – 10M Ohm resistor between pin 2 and VCC using alligator clips. The purpose is to discharge C2 quickly to shorten the measurement time. With the motion detector dormant, the voltage at pin 1 should be near zero after C2 is discharged. (Without the resistor across C2, it could take 2 – 5 minutes to discharge.) If

pin 1 cannot reach zero Volt, check the wiring and values of R10, R11, R12 and R13. When the motion detector is triggered, the output of pin 1 goes into high impedance and the voltage measured should be 8.2V, consistent with Test 1F. If this voltage is too low (less than 4.0V) the relay might not turn on. If it is too high, the relay could turn on even in the day mode.

Test 4K: Time delay and reset This test verifies that the time delay of C2 discharge is operating properly and that motion triggered before the delay expiration can reset the timer. Adjust VR1 or lower the ambient light intensity so that LED-Y is on (night mode). Trigger the motion detector. The relay and LED-R should turn on. Do not further trigger the motion detector and use a stopwatch to time the delay till the relay is switched off (LED-R off). This should be typically between 2 – 5 minutes at ambient temperature of 25 degree C. The time delay is dependent on the input bias current of LM339. According to LM339 specifications, the typical current could vary from 20 – 70nA in the temperature range of +85 to -40 degree C. Different IC manufacturers may also have different current ranges. The typical to worst case current can also vary from 50 to 200nA from the same manufacturer. All manufacturers seem to guarantee less than 500nA in the full operating temperature range. In general, higher temperature leads to less leakage current resulting in longer time delay. You can change the time delay by setting the two DIP switches to increase the capacitance. Closing the switches adds C2A and C2B capacitance and increases the delay. Four different settings can be achieved with the two on/off switches. If the time delay is too short, the most common problem is wrong polarity of C2, C2A and/or C2B. Electrolyte capacitor connected in the wrong polarity presents a self leakage current path that could exceed the input bias current of LM339 by more than 10 times. Another possible cause is the leakage caused by the circuit board or IC socket. This could happen if excessive soldering heat has carbonized the board or IC socket. A 100M Ohms resistance can cause a 100nA leakage current at 10V. If you suspect this, disconnect the power; remove U1 and measure the resistance of pin 2, pin 6 to VCC and GND. Most DMM cannot measure resistance above 20M Ohms. You might need a more sensitive Ohm meter if the resistance measurement is out of range. If the time delay never expires, first check the voltage of pin 7 to see if it is at 8.0V (see Test 4G). If it is within specification, measure the voltage across C2 (similar to Test 4H) to see if the voltage at pin 6 can rise above pin 7. When pin 6 voltage is higher than pin 7, U1B should turn on and its output voltage at pin 1 should be near zero to switch off the relay. If the act of measuring C2 causes the time delay to expire but the delay cannot expire in normal operation, there might be a current leakage path from pin 2 (or pin 6) to GND.

This leakage lowers the voltage at pin 6 so that it can never rise above that of pin 7 to switch U1B. You will need to disconnect the power, remove the IC and locate the leakage path. If the time delay test passes, test the reset operation. Trigger the motion detector before the time delay expires. Use the stopwatch to verify that the time delay is reset. See the timing chart in the Circuit Operation section for the reset function.

Test 4L: Combined operation of day/night modes and motion trigger This test verifies the logic gate operation of U1D given by the following table: Day/Night mode pin 9

Relay control pin 8

Relay on/off pin 14

Day = 12V

Motion = 8V

Off = 12V

Day = 12V

Dormant = 0V

Off = 12V

Night = 4V

Motion = 8V

On = 0V

Night = 4V

Dormant = 0V

Off = 12V

Adjust VR1 or expose the sensor module to bright light. LED-Y should be turned off indicating the day mode. Trigger the motion sensor to verify that the relay will not turn on in the day mode. If it does, the day mode voltage at pin 9 may not be correct. It should be near 12.0V so that U1D cannot turn on the relay regardless of the motion detector status. Now, adjust VR1 or reduce sensor light exposure to enter the night mode. The relay should be turned on with LED-R lit. After the time delay has expired, the relay should be turned off. If the relay cannot be turned off in the night mode, check the voltage divider of R5 and R6. Pin 9 voltage should be at 4.0V in the night mode for the relay work properly. Check the motion and dormant voltages at pin 8. The test passed when you have verified all 4 states of the table.

WARNING: For safety reason, Tests 4A through 4L must NOT be performed with AC power applied.

Step 5: AC relay switching construction and testing Objective: Construct and test relay’s AC switching. Cut a household extension cord in half and solder the male and female sides of the extension cord to the circuit board based on the wiring plan given in Step 1. For North America US, the pin polarity of the AC power outlet is shown below. Check your local electrical code for other regions of the world.

North America US AC power outlet pin polarity.

Test 5A: Relay switched off isolation With T1 still unconnected, apply 18VDC battery power between the two AC pins of DB1. Do not apply AC power in this test. Set your DMM to resistance measurement higher than 10M Ohm range. Adjust VR1 or sensor module so that the circuit is in day mode with the relay off (LED-R off). Measure the resistance between the HOT line of the male and the HOT line of the female side of the extension cord. The resistance should exceed 10M Ohm. If not, you might have a wrong wiring or a defective relay. Also measure the resistance from HOT to NEUTRAL at the female side of the extension cord with the relay either on or off. Again, the resistance should exceed 10M Ohm to pass this test.

Test 5A and 5B: Measuring extension cord isolation and contact resistance

Test 5B: Relay switched on resistance Apply 18VDC battery power between the two AC pins of DB1. Do not apply AC power in this test. Turn on the relay (LED-R on). Set your DMM to the lowest resistance range. Measure the resistance between the HOT line of the male side and the HOT line of the

female side of the extension cord. It should be near zero Ohm. Also measure the NEUTRAL lines of the male and the female sides of the extension cord. It should be near zero Ohm regardless of whether the relay is on or off. If this test fails, trace the conduction path to locate the high resistance point. It could come from the extension cord, plug, socket, contact points, relay, soldering points or the fuse. Do not use the extension cord under this condition because the high resistance will generate excessive heat, a fire hazard.

WARNING: For safety reason, Test 5A and 5B must be done WITHOUT any AC power.

Step 6: AC power supply construction and testing Objective: Construct and test AC power supply. Prior to this step, we have verified the operations of the electronic circuit with battery power. Now you are ready to solder the primary (high voltage) side of the transformer T1. Before soldering, measure the resistance of the transformer’s primary and secondary. The primary should have higher resistance than the secondary. Leave the low voltage side of the transformer unconnected to DB1. It will be connected after Test 6A has passed.

Safety precautions working with wall outlet AC power: 1. Use alligator clips to secure the DMM probes to test points before plugging into the AC wall outlet. 2. Unplug or turn off AC power immediately after the measurement is taken. Do not physically handle the circuit board, DMM or probes when AC power is active. 3. Do not probe the circuit when AC power is active. Probing action might cause shortcircuit accidentally. 4. Beware that the HOT section of the circuit board carries live AC voltage. Avoid any human body contact.

Test 6A: Transformer secondary AC voltage Plug in the male side of the extension cord to energize the transformer. Measure the AC voltage at the secondary of the transformer (the open terminals to be connected to DB1). It should be 13 – 16VAC. If the voltage is very high, you might have the primary and the secondary reversed. If the voltage is not observed, check the fuse and primary side connection of the transformer. Check if 120VAC is reaching the primary.

Test 6B: AC power supply With Test 6A passed, disconnect AC power and solder the transformer secondary to the two AC pins of DB1. Plug in the male side of the extension cord to energize the transformer. Measure the AC voltage at the secondary of the transformer. The voltage should be 12 – 15VAC, slightly lower than the voltage measured in Test 6A because the secondary is now loaded. If the AC voltage at the transformer secondary is normal, set your DMM to DC voltage

and measure the voltage across C3. It should be 15 – 20VDC. If this voltage is near 12V, C3 could be defective. Next, measure the voltage between VCC and GND. This is the voltage across C4. It should be 12.0V. This verifies that U2 is regulating the voltage properly. Note that LM7812 is a linear voltage regulator. The input voltage needs to be higher than the output for proper voltage regulation. This “drop out” voltage is typically 2.0V at 1A current consumption. This unit only consumes about 60mA so the drop out voltage should be less, perhaps 1.0 – 1.5V depending on the manufacturer. If the VCC voltage is very low and/or the T1 secondary AC voltage is also low, there could be a short-circuit overload of the VCC and GND. LM7812 has self protection against this condition. Nevertheless, the power should be immediately removed to avoid device overheat. Repeat the tests starting from Test 4A to locate the problem area.

Test 6B: Measuring VCC and GND voltage with AC power supply.

WARNING: For safety reason, do not handle the test probes, circuit board or change the DMM measurement range while AC power is plugged in.

Step 7: System completion Objective: Final construction and system test. At this step, many critical tests have been conducted. You are now ready to install the circuit board into the project enclosure box. Glue a few non-conducting plastic washers on the back side of the circuit board to prevent the component pins from touching the base of the enclosure box. This avoids physical stress to the component pins and soldering.

Non-conducting plastic washers on the back side of the circuit board. Drill holes on the enclosure box side wall to expose LED-R, LED-Y and LED-G. Also drill holes for extension cord and sensor module wires. De-solder all wires used during AC tests of the previous steps. Final soldering of the wires will be done with the circuit board inside the enclosure box.

Drill holes on the enclosure box wall for LEDs and sensor module wires. To prevent external force of the extension cord from ripping the internal soldering, make a kink or a knot at the location where a cord enters the box. This is an important mechanical construction to prevent AC power hazard. If the internal soldering of the extension cord is loose, AC power line short-circuit may occur. Because the extension cord wires are very thick, you might want to insert the wires into the enclosure box before soldering them to the circuit board. Solder the four sensor module wires to complete all electrical connections.

Wire kinks to avoid ripping

Kinks inside the enclosure box avoid ripping extension cord soldering joints.

All electrical wiring soldered.

Test 7A: Operating temperature First, test the entire system with only the male side of the extension cord plugged in and leave the female side is unconnected. Use a noncontact infrared thermometer to measure the temperature everywhere on the circuit board. The temperature should be no more than 10 degree C above the ambient temperature. T1 is probably the device that generates the most heat. Measure other devices on the circuit board for excessive temperature. You may need to let the unit operate for 30 minutes to reach the equilibrium temperature.

Test 7A: Measuring temperature with a noncontact infrared thermometer.

Test 7B: AC appliances switching This is the first test that draws current from the female side of the extension cord. Start with a low power AC appliance such as a night light or a low power radio (less than 10W). Plug the AC appliance into the female side of the extension cord and check that it can be turned on/off properly by the relay. If this test passed, you can now plug in the actual device you want to operate. The internal fuse is rated at 3A capable of supplying 360W at 120VAC line voltage. The fuse protects against overloading the relay switch and extension cord. For safe operation, do not exceed 300W load.

Continue to monitor the unit’s temperature in operation, especially under full AC load. Weak solder joints, defective extension cord or components can still operate but might generate excessive heat. The extension cord temperature should be no more than 2 degree C above ambient under any circumstance. With the conclusion of this test, you have completed the project.

Completed project.

Summary of test procedures Test procedures

Passing criteria

Test 1A: Sensor module current consumption. Battery power on +5V and GND lines.

Current consumption no more than 5mA regardless of the triggering state of the motion detector and lighting conditions.

Test 1B: Sensor module MOTION signal. Battery power on +5V and GND lines.

MOTION line voltage to GND is below 1.0V in the dormant state. MOTION line voltage to GND above 4.0V in the active state.

Test 1C: Sensor module OPTO line voltage to GND is above 3.0V in bright light. OPTO line voltage. Battery power on +5V OPTO line voltage to GND is below 1.5V in dim light. and GND lines. LED indicator light of motion detector does not affect OPTO line voltage by more than 0.1V. Test 4A: Component polarity.

LED-R, LED-Y, LED-G, D1, DB1, C1 – C4, Q1, U1, U2, U3, T1, RELAY pins wired with the correct polarity.

Test 4B: Continuity test of GND network. No power applied.

The following component pins have near zero resistance among them: Sensor module GND line U1 pin 12 U2 pin GND (center) U3 pin GND (center) D1 pin A DB1 negative pin LED-R, LED-G pins K R9, R11, C1, C3, C4 VR1, RELAY

Test 4C: Continuity test of VCC network. No power applied.

The following component pins have near zero resistance among them: U1 pin 3 U2 pin VO U3 pin VI Q1 pin E LED-Y pin A R2, R6, R8, R10, R13, R15, C2, C4 DIP SW

Test 4D: IC output pins No signal pin of U1 socket is shorted to the GND network. shorted to VCC or GND. U1 not installed. No No signal pin of U1 socket is shorted to the VCC network. power applied. Test 4E: VCC to GND resistance. U1 not installed. No power applied.

Measured resistance 5K - 15K Ohms between VCC and GND (U1 pin 3 and pin 12).

Test 4F: Current consumption and AC to DC rectifier. U1 not installed. Battery power supply only.

Measured current drawn from battery is no more than 10mA above the current measured in Test 1A (consumed by the sensor module).

Test 4G: U1 socket voltage. U1 not installed. Battery power supply only.

Measured voltage from U1 socket pins: Pin 3 = 12.0V Pin 4 = same as Test 1B Pin 5 = 2.5V Pin 7 = 8.0V Pin 1 and 8 = 8.2V Pin 10 = 0.0V to 6.7V depending on VR1 Pin 11 = same as Test 1C

Test 4H: Current consumption. U1 installed. Battery power supply only.

Measured current is no more than 10mA above current measured in Test 4F when relay is off.

Test 4I: Day and night modes hysteresis voltages. Battery power supply only.

LED-Y can turn on in night mode.

Measured resistance between the two AC pins of DB1 is higher than VCC and GND resistance.

Measured current is within +/- 0.5mA when battery voltage polarity at AC pins of DB1 is reversed.

Measured current is no more than 60mA above current measured in Test 4F when relay is on.

VR1 can adjust day/night mode threshold when VR2 is at zero resistance. Increasing VR2 resistance can increase hysteresis voltage of day/night mode.

Test 4J: Motion triggered operations. Battery power supply only.

Voltage across C2 can reach 12V when motion triggered. U1 pin 1 is 8.2V when motion triggered; zero Volt when motion trigger expired. 

Test 4K: Time delay and Time delay can expired in 2 – 5 minutes and turn off relay. reset. Battery power supply only. Motion detected before time delay expires can reset the timer. Test 4L: Combined operation of day/night modes and motion trigger. Battery power supply only.

Day mode cannot turn on relay in motion triggered or dormant state.

Test 5A: Relay switched off isolation. Battery power supply only.

Measured resistance is more than 10M Ohms between male HOT and female HOT lines of extension cord when relay is off (LED-R off).

Night mode can turn on relay in motion triggered state and turn off relay in dormant state.

Measured resistance is more than 10M Ohm between female HOT and female NEUTRAL lines of extension cord when relay is on and/or off. Test 5B: Relay switched on contact resistance. Battery power supply only.

Measured resistance is less than 1 Ohm between male HOT and female HOT lines of extension cord when relay is on (LED-R on).

Test 6A: Transformer secondary AC voltage. AC outlet power supply.

Transformer secondary measured voltage is 13 – 16VAC when unconnected.

Test 6B: AC outlet power supply.

Transformer secondary measured AC voltage is 12 – 15VAC when connected.

Measured resistance less than 1 Ohm between male NEUTRAL and female NEUTRAL lines of extension cord when relay is on and/or off.

Measured voltage across C3 is 15 – 20VDC Measured voltage between VCC and GND is 12.0VDC. Test 7A: Operating temperature. AC outlet power supply.

Component temperature is no more than 10 degree C above ambient.

Test 7B: AC appliances switching.

Relay can turn on/off AC appliances (300W max) on extension cord female side. Extension cord temperature under full AC load is no more than 2 degree C above ambient.