Brightness control using a light dependent resistor (LDR)
AN3248
16/19
Doc ID 17758 Rev 1
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.
Figure 12
shows how
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
IN
). The threshold can be set
externally to PB3 or set internally to V
REFINT
, 3/4 V
REFINT
, 1/2 V
REFINT
, or 1/4 V
REFINT
. The
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
IN
can be connected to PB4 or PB5.
The voltage V
IN
can be computed using
Equation 5
.
Equation 5
As the LDR resistance decreases with increasing light intensity, the voltage V
IN
decreases
as more light shines on the LDR.
6$$
#/-0
2ESISTOR2
6).
/THERPOSSIBILITIES
6
2%&).4
0"
¢6
2%&).4
6
2%&).4
62%&).4
34-,XXX
0"0"
%84)LINE
AI
#-0/54
,IGHTDEPENDENT
RESISTOR,$2
V
IN
LDR
LDR
R
+
(
)
----------------------------
V
DD
×
=