By: Jeremy Cook
Electric lighting requires energy. If you’re in a situation where electricity is limited (e.g., using a battery-powered device), you don’t want to waste valuable power when the sun is out or when other lights are already shining. In this post, we’ll construct a light sensor circuit to allow an LED to turn off automatically when it senses light.
Light Sensor Circuit: LDR, Transistor, Resistor
For this experiment, you’ll need the following components. Values used are in brackets but can be varied depending on the input voltage and components available:
- NPN Transistor [2N2222A]
- (2) Resistors [R1 = 102Ω, R2 = 5.1kΩ]
- LED [red]
- LDR
- Voltage source [5V]
Hook up your circuit according to the “DARK DETECT” schematic below. When properly implemented, the absence of light will turn the LED on. When sufficient light shines on the LDR, it turns off.
Light Circuit Diagram: Reverse R2 and LDR to detect light or dark
Light Sensor Circuit Explanation
As light shines on the LDR, its electrical resistance is lowered from the multiple MOhm range in total darkness to the 100 Ohm range with sufficient light. The LDR and R2 act as voltage dividers, with voltage at VX dictated by VX = VDC * RLDR / (RLDR + R2). Current begins to flow from the collector (3) to the emitter (1) when VX/base voltage is sufficiently high (around .6 VDC for my setup). When active, current flows through the LED and transistor, inhibited by R1 to protect the LED.
To dynamically change the point at which the LED switches on, you can use a variable (tuning) resistor for R2. As its resistance is turned higher, a greater LDR resistance—and thus a lower light level—is required to reach sufficient voltage (VX) to activate the transistor and light up the LED.
Detecting darkness | Credit: Jeremy Cook
Conversely, you can reverse the position of R2 and the LDR to turn the LED on with sufficient light. In this situation, as the LDR’s resistance decreases with more light, the voltage drop from VX to ground becomes higher. When VX becomes sufficiently high, it allows current to flow through the LED.
Microcontrollers, Operational Amplifiers, and “Things” Control
Switching on an LED based on ambient lighting is certainly useful for illumination. However, this sort of light-dependent resistance circuit setup can be applied elsewhere.
Differential voltage input (from an LDR or otherwise) can be used with an operational amplifier for switching instead of a single transistor. You can also use a microcontroller (or other computing devices with an analog-to-digital converter) to actuate equipment based on ambient lighting. We explain how to use such a sensor with an Arduino microcontroller setup here.
Measuring light (or lack thereof) can be used for presence detection or to pass signals while maintaining electrical isolation. With the help of local computing resources, data can even be sent to the cloud and amalgamated with other sensing devices, allowing control possibilities limited only to your imagination. That’s not bad for an extremely simple and inexpensive sensor!