Brightness control using a light dependent resistor (LDR)
6
Brightness control using a light dependent resistor
(LDR)
In some battery operated applications, the microcontroller needs to be powered if the
environment is lit otherwise, it must be kept powered-off. For such applications, a light
dependent resistor (LDR), whose resistance depends on light intensity, is useful to control
the microcontroller state. Using an LDR sensor, the microcontroller can switch to/from Low-
power mode depending on the voltage provided by the LDR resistor.
to connect an LDR resistor to an STM32L15xxx device COMP2 non inverting input, can be
connected to an LDR resistor through a voltage divider (V
externally to PB3 or set internally to V
COMP2 output (CMP2OUT) can be internally connected to EXTI line 22 which, when
configured to detect both rising and falling edges on CMP2OUT, can be used as an interrupt
source to switch to/from Low power mode.
Figure 12. Connecting an LDR resistor to an STM32L15xxx device
1. PB4 or PB5 can be used as COMP2 non-inverting input. Thus, V
The voltage V
Equation 5
As the LDR resistance decreases with increasing light intensity, the voltage V
as more light shines on the LDR.
16/19
can be computed using
IN
V
Doc ID 17758 Rev 1
IN
, 3/4 V
, 1/2 V
REFINT
REFINT
can be connected to PB4 or PB5.
IN
Equation
5.
LDR
×
--------------------------- -
=
V
(
)
IN
DD
LDR
R
+
Figure 12
shows how
). The threshold can be set
, or 1/4 V
REFINT
REFINT
decreases
IN
AN3248
. The
Need help?
Do you have a question about the AN3248 and is the answer not in the manual?
Questions and answers