# Intelligent Photoswitch based on ldr

#### megatron100101

Joined Jun 18, 2021
9
I want to make a photoswitch light based on LDR that would turn on in absence of sunlight and turn off in presence of sunlight. But the problem is when the light goes on it causes LDR to turn the light off and when light goes off it will cause LDR to turn it on and hence it will be an endless loop. It can be solved by placing LDR circuit outside the room but due to some limitations, I can not do that. One solution would be that I can check if turning the room light on and then off has any effect on LDR or not and if it has effect then keep the lights on because if it has no effect then it must mean there is sunlight present in the room so no need to turn on light. But I cannot design any circuit of the given implementation. Can anybody suggest me circuit to do the given job? (This is my first post to forum So I dont know if it is valid question or not. Also sorry for bad English).

#### ElectricSpidey

Joined Dec 2, 2017
2,593
What you describe is usually solved with a mechanical solution, not a circuit.

Try placing a tube shield over the LDR and point it away from the light.

#### megatron100101

Joined Jun 18, 2021
9
What you describe is usually solved with a mechanical solution, not a circuit.

Try placing a tube shield over the LDR and point it away from the light.
then LDR will be in dark forever. I know solution I proposed in post can be implemented by using some counter ic timer, just dont know how

#### LowQCab

Joined Nov 6, 2012
3,452
The LDR can be "remote-mounted" in a window facing outside,
( and packaged inside of a cardboard-tube as well ).

The difference in the intensity of Light falling on the Sensor
must be substantially different between outside Light, and inside Light.
There is no Electronic way to get around this Physical requirement.
.
.
.

#### LesJones

Joined Jan 8, 2017
4,013
If you could tolerate the light going off for a short time (Say one second.) every 5 minutes or so then you could sample the LDR to see if it was dark during the one second period. If it was dark you would switch the light back on at the end of the one second period. Using a microcontroller would be the easiest way to implement this method. I have used this method with a PIR controlled light.

Les.

#### KeithWalker

Joined Jul 10, 2017
2,872
That's a lot of technology just to see if it is light outside. Just point the LDR out the window and shield it from the inside light. If you don't want a long electrical lead to the LDR, use some fiber optic strands from a cheap decoration to get the outside light to it.
I firmly believe in"KISS" even if it brands me as a dinosaur!

#### LesJones

Joined Jan 8, 2017
4,013
I agree Keith, Unless the light that is being controlled is so bright it is similar to daylight shielding the LDR and adjusting the threshold at which the LDR switches between light and dark should solve the problem. (In the unit that I build to work with a PIR I was already using a PIC15F18446 to set the length of time that the light stayed with an 8 bit DIP switch. So it just required a few extra lines of code being added.)

Les.

#### Ian0

Joined Aug 7, 2020
8,386
If you could tolerate the light going off for a short time (Say one second.) every 5 minutes or so then you could sample the LDR to see if it was dark during the one second period. If it was dark you would switch the light back on at the end of the one second period. Using a microcontroller would be the easiest way to implement this method. I have used this method with a PIR controlled light.

Les.
You could make that gap much shorter than 1 second, and it would still work. May need something quicker than an LDR such as a photodiode.
If the light has 100Hz flicker, the it could be sampled during the low period, or if it’s an LED with a PWM dimmer it could be sampled in the dark period. (But I think Philips has a patent on it)

#### megatron100101

Joined Jun 18, 2021
9
If you could tolerate the light going off for a short time (Say one second.) every 5 minutes or so then you could sample the LDR to see if it was dark during the one second period. If it was dark you would switch the light back on at the end of the one second period. Using a microcontroller would be the easiest way to implement this method. I have used this method with a PIR controlled light.

Les.
Thats the solution I am looking for but how to do it without microcontroller( I mean cheaper way, may be it can use timer and counter ICs?

#### megatron100101

Joined Jun 18, 2021
9
The LDR can be "remote-mounted" in a window facing outside,
( and packaged inside of a cardboard-tube as well ).

The difference in the intensity of Light falling on the Sensor
must be substantially different between outside Light, and inside Light.
There is no Electronic way to get around this Physical requirement.
.
.
.
How about Lesjohn's proposal?

#### Ian0

Joined Aug 7, 2020
8,386
Thats the solution I am looking for but how to do it without microcontroller( I mean cheaper way, may be it can use timer and counter ICs?
You could probably do it with a 555 to generate the PWM, then a sample-and-hold to sense the light level. It would need a higher sampling frequency - more like 100 times a second than once every 5 minutes to deal with the droop-rate of the sample-and-hold

#### LesJones

Joined Jan 8, 2017
4,013
One thing that needs to be considered is the light source in the room. Some LED light fitting do not go out as soon as the power is removed so this would be more of a problem than the response time of an LDR. A microcontroller would probably be cheaper than using a few ICs. (I was thinking of a PIC12F1840 which costs about £1.12 + VAT.) Here is the start of an idea to use 4000 series ICs. Start with a CD4060 with the oscillator frequency set so that the final stage changes state about every 5 minutes. Use the low to high transition of the final stage to trigger two monostables (CD4047) one to give a pulse of about 1 second the other to give a pulse of about 0.5 seconds. The 1 second one would shut of the power to the light. (For 1 second.) The falling edge of the 0.5 second pulse would clock a D type flipflop. (CD4013) The data in of this flipflop would from the comparator that that converts the LDR output to the light / dark signal. The output of this flopflop would store the light /dark state from the one second period that power was removed from the light. So this would now set the light to be on or off. The times in this example are just a starting point. and could be changed. I like Ian's PWM idea but it would depend on the light responding fast enough.

Les.

#### Alec_t

Joined Sep 17, 2013
13,783
Tell us the type of light you have. Mains powered? Battery powered? LED? Incandescent? .....?

#### Ian0

Joined Aug 7, 2020
8,386
I like Ian's PWM idea but it would depend on the light responding fast enough.
It would only work if you were building your own luminaire, and had direct control of the LEDs.
Perhaps best avoided as Philips are notoriously litigious about their patents!

#### megatron100101

Joined Jun 18, 2021
9
Tell us the type of light you have. Mains powered? Battery powered? LED? Incandescent? .....?
Mains powered LED and Incandescent

#### Alec_t

Joined Sep 17, 2013
13,783
I think you could do what you want with a latching 'window comparator' having adjustable lower and upper thresholds. With the lamp off, when room light-level falls below the lower threshold (evening) the lamp turns on. When room light-level due to the combination of the lamp and daylight rises above the upper threshold (dawn) the lamp turns off.

#### megatron100101

Joined Jun 18, 2021
9
I think you could do what you want with a latching 'window comparator' having adjustable lower and upper thresholds. With the lamp off, when room light-level falls below the lower threshold (evening) the lamp turns on. When room light-level due to the combination of the lamp and daylight rises above the upper threshold (dawn) the lamp turns off.
I am going to test your solution but I suspect my LDR will hardly notice the difference between daylight and combination of led+daylight

#### megatron100101

Joined Jun 18, 2021
9
One thing that needs to be considered is the light source in the room. Some LED light fitting do not go out as soon as the power is removed so this would be more of a problem than the response time of an LDR. A microcontroller would probably be cheaper than using a few ICs. (I was thinking of a PIC12F1840 which costs about £1.12 + VAT.) Here is the start of an idea to use 4000 series ICs. Start with a CD4060 with the oscillator frequency set so that the final stage changes state about every 5 minutes. Use the low to high transition of the final stage to trigger two monostables (CD4047) one to give a pulse of about 1 second the other to give a pulse of about 0.5 seconds. The 1 second one would shut of the power to the light. (For 1 second.) The falling edge of the 0.5 second pulse would clock a D type flipflop. (CD4013) The data in of this flipflop would from the comparator that that converts the LDR output to the light / dark signal. The output of this flopflop would store the light /dark state from the one second period that power was removed from the light. So this would now set the light to be on or off. The times in this example are just a starting point. and could be changed. I like Ian's PWM idea but it would depend on the light responding fast enough.

Les.
It will take time to understand what you just said, would be better with block diagram or circuit but I am still trying

#### LesJones

Joined Jan 8, 2017
4,013
I think a timing diagram will be the best way for you to understand the idea. I will try to draw one tomorrow. It also occurred to me that the microcontroller I suggested has a built in analogue comparator so it would almost be a one chip solution. I did think about writing some code to do the job using an ATtiny13A as I have some code already in use that could be a basis. But I am not sure if you have totally rejected using a microcontroller.

Les.

#### Alec_t

Joined Sep 17, 2013
13,783
I suspect my LDR will hardly notice the difference between daylight and combination of led+daylight
I think the difference would be easily detectable with the LDR. A 20% illumination intensity increase, for example, might go unnoticed by a person because of the logarithmic response of the eye, but should reduce the LDR resistance enough to switch off the lamp. It will be interesting to hear the result if you try the experiment.