Tubelight off led on

I want to create a project where ldr detects room light and turns on led when room light is off. Any help please?

@sainath2k20 , you can do this project in two ways:

(For both ways, the hardware configuration will be same) Hardware confuguration is as follows

  1. Without simple loop: Write a python code in which write an infinite while loop which will repeat itself after 30 seconds ( delay is upto you ). In the loop, fetch the value from the A0 pin and then use some condition that sensor_value < 250 (set the threshold accordingly). Then if the condition is true then make the port of the led which is connected to say GPIO 1 pin high by the command mybolt.digitalWrite(‘2’,‘HIGH’). This will make the Led glow whenever the LDR value decreases below a threshold.

Code will look like this:

  1. By the Z-Score Analysis: One way of anomaly detection os through the Z Score analysis. So you can write a code such that whenever the threshold value is not withinlower and higher bounds computed through the Z Score. Then the led will glow on using the command mybolt.digitalWrite(‘1’,‘HIGH’). You can have a look at the project training to look how to implement Z score analysis.
1 Like

@sainath2k20 there is another simple way to built this project and that is by using transistors and LDRs.
The basic components that will be required to built this circuit are:
LDR, x BC547 NPN Transistors, resistor, potentiometer, LED and power supply
Circuit:


You can also do this circuit in a software named TinaTi.
In this above circuit, we are using the transistors in darlington pair since it provides enough current at the output end.
So, for the first transistor, the LDR and the potentiometer forms the biasing resistors. Thus, when light is incident on it, Resistance decreases. As a result of no biasing voltage(i.e, Resistance is directly proportional to voltage),the LED will switch off. Then when the light is removed or the LDR is placed in a dark room, then the LED glows. This will turn on the 1st transistor which in turn will turn on the 2nd transistor(since its input is connected to the 1st transistor’s output). Hence, the LED connected to it also glows.
I hope this will help in clarifying your doubt. :innocent: :slightly_smiling_face: