Skip to main content

Subsection 14.3.1 The Divider and the Fixed Resistor

With the sensor at the top, from \(V_{cc}\) to the node, and the fixed resistor \(R_M\) from the node to ground,
\begin{gather*} V_M = V_{cc} \cdot \frac{R_M}{R_\text{sens} + R_M} \end{gather*}
and \(V_M\) rises as \(R_\text{sens}\) falls. On the STM32C031C6, \(V_{cc}\) is 3.3 V and the 12-bit reading is \(4096 \times V_M / 3.3\text{,}\) so one count is about 0.8 mV.
For a sensor whose resistance swings between \(R_\text{low}\) and \(R_\text{high}\text{,}\) the fixed resistor that puts the two readings farthest apart is their geometric mean,
\begin{gather*} R_M = \sqrt{R_\text{low} \times R_\text{high}} \end{gather*}
The swing in \(V_M\) between the two states is small when \(R_M\) is far below both resistances (both readings near 0 V) and when it is far above both (both readings near \(V_{cc}\)); the geometric mean puts \(R_\text{low}\) and \(R_\text{high}\) the same factor below and above \(R_M\text{,}\) which is where the swing is largest. A cell that happened to swing between 2 kΩ and 200 kΩ, not this photocell’s own range, would have a geometric mean of \(\sqrt{2\text{ kΩ} \times 200\text{ kΩ}} = 20\) kΩ: ten times 2 kΩ, and a tenth of 200 kΩ, the same factor each way. The Adafruit guide calls this the Axel Benz formula. You build with the nearest standard resistor value; a value away from the geometric mean costs you a smaller swing between the dark and the lit reading, not a wrong reading.
The photocell’s resistance against illumination is close to a straight line on log-log axes. The PDV-P8001 datasheet’s Sensitivity row defines
\begin{gather*} S = \frac{\log(R_{100}) - \log(R_{10})}{\log(E_{100}) - \log(E_{10})} \end{gather*}
with \(R_{100}\) and \(R_{10}\) the resistances at 100 lux and at 10 lux and \(E_{100}\) and \(E_{10}\) those two illuminances, and gives 0.6 as the typical value. The sheet prints the magnitude; on the plot the slope is negative, because \(R\) falls as \(E\) rises:
\begin{gather*} \log_{10}(R_{100}) - \log_{10}(R_{10}) = -0.6\,[\log_{10}(E_{100}) - \log_{10}(E_{10})] \end{gather*}