A Light / Dark activated switch is a circuit that will somehow measure the light level and will turn on or off a relay accordingly. We will use an LDR (Light Depended Resistor) to measure the light level. Also, we will not demonstrate only one circuit but instead, three circuit will be put under the microscope. Each one will have different characteristics but the operation will be the same.
The first circuit - The blind man's sensor
The circuit assembled on a breadboard
The circuit is is a simple transistor switch with the base of the transistor connected to a voltage divider. The voltage divider has two resistors. The first is the 100K potentiometer plus the protective 1K resistor. the second resistor is the LDR. This is the schematic of the circuit:
As light falls on the surface of the LDR, the LDR changes it's resistance. The more the light, the less the resistance of the LDR, the less the resistance, the less the voltage drop across it. The less the light, the more the resistance and thus the more the voltage drop across it.
As the voltage drop increases, so does the VB of the 2N2222 transistor and therefore the ICE increases accordingly, until the time that the current is enough to actuate the relay.
The amount of light needed to actuate the relay can be changed by changing the 100K potentiometer. Basically, any change to the potentiometer will have an effect to the voltage drop of the LDR, as they are both members of the voltage divider described above.
The 1N4001 diode is used to eliminate any back voltage when the relay is disarmed. It is very important to have this diode because without it, the transistor may be damaged.
The second circuit - Increased sensitivity
This has a better sensitivity than the previous
The above circuit works fine as far as the activation is concerned. There will be no problem to detect dark or light and actuate the relay, but there will be a problem when the relay needs to be released back again. At this point, the circuit has a big hysteresis. therefore, we need to further amplify the signal before we apply it to the switching transistor.
We will use the BC517 NPN Darlington pair transistor. We will put it between the 2N2222 and the LDR, as the following circuit indicates:
With this addition, the sensitivity of the circuit is further increased. The hysteresis window is significantly decreased, although there is still a region that when the relay is activated, it will not be deactivated with the same amount of light that existed just before it's activation.
Selecting different parts
The above circuits may work with different voltage and/or parts. For example, you may change the voltage to 5 volts, but you should then consider changing the 1K resistor into 560 Ohms, the potentiometer into 10K and the relay of course must have the appropriate coil voltage.
You may use any kind of NPN transistor for switching the relay, as long as it is capable to work under your selected voltage and also be able to provide enough current (ICB) for the relay.
Adjusting the circuits
Only one adjustment needs to be made and that would be (of course) the potentiometer. Your goal is to make the circuit actuate the relay when you have equal or less light to the pre-defined value. The easiest way to do this is as follows:
Let the LDR be lighted with the amount of light you want. Keep the potentiometer into it's highest value. Then start slowly turning the potentiometer and reducing it's resistance. When you hear the 'click' of the relay, you have found your set point. From then on, every time the light is less or equal (or more if the circuit is configured as "light activated") to the light that you made this pre-setting, the relay shall be activated.
Convert into light detectors
The above circuits operate as dark detectors. This means that when the light level falls under a preselected value (read previous paragraph), the relay is actuated. In case you want a light detector that will actuate the relay when the light level is increased above the preselected value, just remove the protective 1K resistor and switch places between the LDR and the potentiometer, readjust and that's it.
The third circuit - Sensitivity to higher levels!!!
The next circuit has nothing to do with the above. It uses a 741 op-amp to achieve maximum sensitivity. This circuit can sense very slight light changes and can be really fine adjusted. Let's take a look at the circuit:
This circuit has so much sensitivity and so low reaction time, that is sometimes improper to be used
As you may have notice, the 741 is connected as a voltage comparator. Two voltage dividers are easy to be found: The first one is the LDR and the 100K resistor. The second one is composed by the two 470 Ohms resistors and the potentiometer. Both the outputs of the dividers are connected as inputs to the voltage comparator.
The second voltage divider will settle the reference voltage. The first voltage comparator that contains the LDR, will change it's voltage according to the light level. When the voltage across the negative input of the comparator is less than the voltage to the positive input of the comparator, the output is held low. When the voltage on the negative input rises, there will be a time that it becomes greater than or equal to the positive (pre-selected) voltage, and then the output becomes high and the relay through the 2N2222 is actuated.
Selecting different values
As long as the transistor is concerned, any NPN switching transistor capable to drive your relay will do. As for the LDR, you need to make sure that it pairs with the 100K resistor. This means that the mid-value of the LDR is almost the same as this resistor. Any pair will work theoretically, but i have not test others than this pair. If you have problems please let me know.
The circuit is designed to work with 12V, but it can operate in lower voltages as well, as long as you make sure you select the right relay for the occasion.
Convert into light detector
This circuit, just like the previous two circuit, operate as dark activated switch. If you want to change the functionality of this circuit, simply exchange places between the 100K resistor and the LDR.
Which one to use?
This section could also be named "advantages and disadvantages". But i chose this name as my goal is to help you find the proper circuit for each occasion. Also, it would be unfair for a circuit to name advantages or disadvantages in it's name, as there are actually none! Instead, there is proper and improper use and/or application for each one of them.
Starting with circuit #1. This is a very easy and cheap circuit. Excluding the relay, it would cost about a Euro or less. This circuit is proper for detecting large light changes. I would use it for example if i wanted to detect the light in my room or in a hall if it works or not. Small changes like shadows and staff does not affect this circuit and thus it gives a straight answer to the question: - Is the light turned on? Is my car's rear stop light working?
The second circuit on the other hand is much more sensitive to changes. The Darlington pair transistor will significantly increase the slight current changes from the LDR. Still there is a big window between activation and deactivation of the relay. This makes it ideal for outdoor uses to detect if there is ambient light. It could be perfect for example to control your automatic lights. It will not be affected by shadows from a bird flying against the sun or a cat is passing near by the sensor trying to catch this bird. Or even the human with larger shadow area, that tries to save the bird from the cat. Nevertheless, it will be accurate as far as the light level detection is concerned. The automatic lights shall indeed be turned off when the sun start shining the day.
The third and last circuit is the most accurate and the most sensitive. If for example a shadow falls and covers the 2/5 of the LDR it may not actuate the relay, but if the shadow covers the 3/5 it may actuate it. Small light changes may result into relay state change. This makes it completely inappropriate for the pre-mentioned applications. It would be very good in human detection from light level changes. For other applications, you should consider adding a delay circuit at the output of the 741. If the light level is very close to the preselected value, the relay will flicker due to the almost zero light level window that with this circuit is accomplished. It would also work very well as light signal receiver.
Hi Giorgos, for the 12v supply powering the LDR circuit is it possible to power it using the same incoming 12v that the relay is triggering? This being so you don't have to use a battery to keep the circuit running? If I had the relay triggering a 12v light from a AC to DC transformer can I use that same DC 12v going to the light to power this sensing circuit or will this blow the circuit? Thanks a lot!
Hi, I build the second circuit. But the relay does not releases back when the light come on the LDR. So I connected a series of LEDs in place of the relay and I see LED's turning off when light falls. So I assume that 2N2222 doesn't cut off when the light is on or it doesn't go below than the hold current of relay coil. In this case, what should I change ? Will increasing 1.5K work ? please let me know.
@Autumn Try different values for the 100K feedback resistor of the 741. If this does not work you need different LDR or different resistor value for the LDR voltage divider performed with the other 100K resistor.
Hi, I was built the third circuit but I'm using a 9V battery. It able to activated the relay but failed to turn it off when vary the light. I found that the voltage across relay is around 6.7V and it only drop to 6.5 when cover the LDR. The voltage at transistor also around 1V only. It is transistor and relay problem or battery not suitable?
I made the circuit 3-4 times and even made it twice at the same time and this is my result: [URL=http://s1054.photobucket.com/user/bgoody32/media/DSC02259_zpsb8c6fea9.jpg.html][IMG]http://i1054.photobucket.com/albums/s489/bgoody32/DSC02259_zpsb8c6fea9.jpg[/IMG][/URL]
The pink represents the components and wires that were hooked up which caused the coil/relay to close. When I hook up everything else, or, remove everything else, it makes no difference. I also used 2 different op-amps and tested my transistor on another circuit.
@Brent If you use the circuit with the opamp, you do not need to change the LDR. I think i got what you mean with the resistors. In that case, you only need different LDR if you plan to draw lot of current through it, something that does not happen with op-amps, so its ok...
I can use high value resistors, I just thought with my working range of 800 to 1050 Ohms it might be different. It sounds like about 500K is good. I will experiment on that.
My LDRs are rated from 10k to 1meg Ohm. However, with my set up, the resistance is only 800-1500 ohms when the motor is activated. These are the values of the LDRs in this amount of light. In other words the switching in both circuits occurs when the light about 15%(arbitrary value), such as when a cloud goes in front of the sun. My blinds will not allow direct sunlight into a room, only values such as 800-1500 ohms, such as when the sun is behind a cloud. My dark circuit will open the blinds and the light circuit will close them.
Could you point me in the right direction if you still think I need different LDRs?
Thanks again for your help!
@Brent oh I see. Here is what: if you use such a high value off with these resistors, then you miss the precision. That being said, I suggest that you use a different ldr. May I ask. why can't you use biger resistors???
The 100k resistor is the one under the op-amp (AKA feedback resistor)
First, I want to thank you for your help. This is a big project for me since my knowledge of circuits is very limited; hence your help is greatly appreciated.. Second, I did not explain myself very well last time. I am doing two circuits on the same motor, a dark activated circuit and a light activated circuit. The relays in both circuits will be wired together so only one will work at any given time so that the motor will not short out. When it is completely dark, and up to about 15 percent light, the motor will turn one direction. When it is brighter than this, the motor will turn the other direction. The resistance values of the LDR that I will be working with are only from about 800 ohms to 1050 ohms. Anything above this or below this range will not be utilized in my project. My question is this; will I still want the 100k(500K if that was the mid-range of the LDR) resistor that is above the LDR, or should I give it a different value, a value closer to the range I am working with? Question 2, When you said in your last post to change the 100k resistor to 22k to help with flicker, you meant the 100k resistor under the op-amp?
@Brent 500K if the ldr is linear of course.
As for your second question, you can adjust the flicker with the hysteresis by altering the 100K resistor. use a smaller one, 22K or smaller. Run some tests.
i have made first and second circuit both works like a charm but:
-i wanted to use it for fluorescent bulbs, the relay wont stay put ,it goes intermitent . I know the reason but i don't know how to fix it, fluorescent bulbs have high voltage discharges when its lighten up and that parazite oscilation is affecting the relay coil.
how can i fix this?
If you don't mind a few questions for you. First, if the ldr is 10K to 1M Ohm, would the mid range for the accompanying resistor be 500K ohms?
Second, lets just say I wanted to turn the relay on when the light was 15% of total sunlight, like an overcast day. Would circuit 3 be good? Would I get too much flicker from the relay. What I am trying to do is get blinds to close when the light is about 15-20% and open when it goes below this range.
I made some changes based upon your suggestion that I reverse the ldr and take out the fixed resistor. It worked using a 9 volt battery. However I need to use a 12 volt battery, and the ldr that I was using with the 9 volt would not work, but I happen to have an ldr with a higher resistance using the reverse design, it seems to work. My goal is to turn off a camera at night and on at daylight. I also had to increase the ohms of the variable resistor. Once I have a going circut, I will probably change to a fix resistor. Incidently the ldr that I was originally using had 5k-100k as called for.
Your circuit may be of use for my mini solar project. I want the circuit to start allowing voltage through as soon as it reaches 11 volts (and not before 11 volts). Is a relay necessary or are there any other options? Thank you.
@gahn at first,try the first circuit instead. it has less sensitivity so when the light is at the point where the circuit is on and off, it will not flicker. as for the relay, i suggest you post some image or photo in the forum to understand.
the relays i am using are OMRON G2R-1-E 12VDC,16A 250VAC, 16A 30VDC.This is after stopping to use SRD-12VDC-SL-C 10A 250VAC, 10A 30VDC. both have 5 legs. i have connected the (-ve)Negative of the circuit with the COM for relay. then the (-ve)Negative of lamp to NO of relay. The ( ve)positive of circuit connected with ( ve)positive of lamp then to ( ve)positive of battery. please advice on any error being committed.
thank you for quick reply
Circuit no.2 operates as outdoor switch for our home security light. the light is 50 watts DC Voltage.
the relay works well for 3-4 days then it starts hissing then the lamp flickers on and off... any suggestions on improving on stability of the circuits.
@Gahn most probably the 2n2222 is dead, but get also a bc517. As for the load, get a 5 amperes relay, it can handle some 1000 watts of load easily. Also a 1 ampere relay is enough, but the price difference is ridiculous.
I want to trigger the first circuit with a pulse of 12 volts and keep it on for 30 seconds after the 12 volts is removed. The relay would be supplied with its own supply. What other circuit mods would have to be made to make this work.
Thanks in advance for any information
My 100K linear potentiometer have 5 legs (pins)
Which pin should i connect to 1K and LDR. Also My 12v delay has 8 pins and i connected as suggest by Kammenos but the leds not lighted. Please advise. Thanks
@toni675 you need to get a relay capable to handle the current of the lamps. If for example each lamp is 60 watts, I=P/V => I=0.27 amperes. Two of these lamps makes about 0.6 amperes, so you need a relay capable to handle contact 220 volts 1 ampere at least, with coil 12 volts (this is how you ask it). As a matter of fact, almost all relays can handle at least 1 ampere, so this is simple to get. I suggest you get 5 amperes relay. The pinout is subject to the relay you will get. Usually the pinout is on the shell of the relay painted.
Excellent work guys.The circuits are very explanatory even for the amateurs like us. I'd like to control two 220vac loads(ex. lamps) with the activated relay. Can you suggest me the appropriate relay?If yes can you provide with the correct connection(NO, common)?Tanks anyway.
@ken, you can connect ONLY THE SECONDARY of the relay to the 220 volts, as long as the relay permits it. Be very careful with 220. Of course, the circuit cannot be connected to 220. You can ONLY control 220 load with the relay.
Kammenos, can u send me the complete diagram for the circuit 2 and 3 together with the LED, i having problem on connecting the LED with the relay, i try to connect the NC leg of the relay on a power source and a resistor in series with LED and my CM is connected to ground but there is no response on the LED
vincent they are made for 12 volts, so you can use them with no change. As far as the battery is concerned, use any battery that can handle your load (for example car battery, or motorcycle, or 8x AA batteries...).
Please, i appreciate on your view toward the circuit though that my building on light activated i used a circuit resemble the third circuit viewed, but im still supriase who made this recovery because even now i ve not gotten the review on this write up so can you shared the literature review on my topic mentioned above. Thanks.
I built circuit #2. I could get the relay to activate when adjusting the potentiometer. However, the relay stays activated even if I shine light on the LDR or adjust the potentiometer. I am using a 12V relay, it activates at about 8.5 volts and I could get it down to 6 volts, but the relay will still stay activated. The LDR I'm using is 3-200 K ohms. pls help.
i used transistor 2N2222 for the dark activated switch but that does not work.m using the bc 109 transistor now.the circuit works but it is affected by shadows.how do i make my circuit unaffected by shadows??
my circuit consists of
a 6volt activated relay
protective diode 1n4001
transistor BC 109
input of 9v
An LED is a diode. If you connect it without a limiting resistor, then the current will flow within uncontrollable. At 12 volts, you need an LED around 300 Ohms 1/2 Watts (http://pcbheaven.com/wikipages/LEDs/). You will connect the resistor in series with the LED, and all this parallel to the relay.
You remove the 2n2222 and the 1n4001 and the relay completely. Then, you connect a monostable multivibrator circuit. You can select to make it either with transistors (http://pcbheaven.com/wikipages/Transistor_Circuits/ circuit #6) or with a 555 timer (http://pcbheaven.com/wikipages/555_Circuits/ circuit #8).
Thanks you for your reply Kammenos! Its perfectly clear for me now :)
A have another question. How can i modify the 2nd circuit to light the LED for a specific amount of time? For example, when the LDR detect dark it turns the led on for 1 minute and then turn off.
Please send me the modified circuit on my email if you can. Thanks!!!
My email: hacket_t (-at-) yahoo(.)com
the LED is conencted at the output of the relay, just for demonstration reasons for the video. When you provide yourself a relay and yo make the circuit, you will connect the LED to a Normal OPEN contact of the relay. For example, in my schematics, on the right side of the relay there are 3 contacts that are not connected anywhere. The LED should be connected to the middle and bottom contacts. If this is not quite clear to you, i will send you by email a draft schematic.
Just use a resistor value between 1kohm to 1k5 (1,5 kohm) for 12volt. If 5 or 6 volts is the operating voltage of your circuit 330 or 470 ohm should be fine.Not so critical. Something i forgot to write about the LDR: The one i found in the market had a resistance around 6 to 8 kohm in natural daylight room conditions. When cutting the light from the surface, value increased to 20kohm and above. In my situation a potensiometer of 33k or 47 k (instead of 100k) should give more accurate sensitivity on adjust.
For starters you can hear the relay whether is activated or not.
From the NO of the relay you connect a resistor and the positive wire of the led to it. You put the negative led to ground and you're good to go.
Led's operate in DC voltage, no need for AC. Be carefull, AC can easily hurt you.
Eitherways the contacts of the relay since you plan to use outside power source don't affect the other circuit which powers up only the coil of the relay.
I went to the component store, but could not get the 5-500k photoresistor. Only manage to get a normal LDR will it work too?
I\'m using the circuit 2 to detect the darkness in a shelter that is placed outdoors
Bill Of Materials for the 2nd circuit:
1 x 1 KOhm resistor 1/4 Watt
1 x 1.5 KOhm resistor 1/4 Watt
1 x 10 KOhm resistor 1/4 Watt
1 x 100K linear potentiometer
1 x BC517 NPN Transistor
1 x 2N2222 NPN Transistor
1 x 1N4001 General purpose diode
1 X 5-500K Photoresistor
1 x 12V DIP relay
The relay you mentioned bellow is ok and should work.
Please do not spam. Subscribe to the comments board so that you can edit your own messages instead. Thank you for understanding.
The switching capability of the relay is irrelevant. You can use whatever 12V relay you may. The coil is that matters. I use a 16mA coil (720 Ohm). Any value near is ok. I believe that any dip relay at 12V coil is OK.
This is a DPDT 1A 12VDC PCB mounted yes?
As you look it with the pin on top,there are 2 pins on one side (left) and 6 on the other (right). The two pins on the left are the coil. You connect those across the 1N4001 protective diode.
The other pins are 2 sets of contacts to use. You can use the top 3 pins for example. From left to right, those pins are:
COMMON - NC - NO
This means that if you want your load to light when the relay is actuated, you will use the COMMON and the NO contact. If you want your load to turn OFF when relay is actuated, you will use the COMMON nd the NC pins.
Yunami, this resistor value depends on the type of LDR you will use. I use a 5-500K LDR. This means that my LDR has 5K resistance in light and increases to 500K resistance in dark. If you choose one close to this (10-1000K or 20-2000K), then it should work. If you use something far beyond these values, then you MAY need to change it. I have not try this though. Test it with the 100K resistor. It is 95% success.
You see, i'm planning to make a database with the parts and the manuals together, that you can download a bill of material + the manuals for every part. This requires some time, because i have to make a BillOfMaterial script that will cooperate with the database. That is why i have to no circuit a BOM. The parts are of course all at the schematics. I know this is frustrating, but please be patient.
This is a nice simple introduction for an electronic noob like me so thanks for that, but I'm a bit confused when it come to purchasing components. Can you provide a parts list with links to the items in an online store? I'm sure you could use a referral scheme to make some money too :)
Although i have not test it with 6V relay, i am sure it should work if you reduce the 10K resistor at the base of the transistor. Give it a try using a 4.7K instead. If you keep having this problem, please inform me and i will run a test with the circuit for you.
Thanks for the circuit. I have build the third circuit and i have change the relay to 6v relay. The problem that i got now is my relay cannot be trigger.i supply my circuit with 7v. when i measure the output voltage using voltmeter across the diode (without the relay)the voltage do varied from 0 - 7v when i play with the LDR. But when i put the relay my voltage drop until 3.5v and when i play with the LDR the voltage drop within 3.5 - 3.4v only. So i decided to increase my supply to 10v and my relay do trigger but the problem after the the relay cant be turn off. Pls help.