John R. answered 05/16/26
Developer with a passion for C++ and over 11+ years of experience
Sounds like a pretty standard transimpedance setup where a photodiode feeds to an op-amp with the digital pot as the feedback resistor. The diode puts out a current proportional to incident light, the op-amp turns that current into a voltage (Vout = Iphoto × Rf), and what you're calling "sensitivity" is really just the gain of that stage. Moving the digipot wiper changes Rf, which changes volts per amp of photocurrent.
Worth double-checking your goal here though: if you're already reading 4V, you're 80% of the way to the rail. Pushing the gain 'higher' will clip you, unlikely to give you your desired result. What you probably want is to 'lower' the gain when the output gets close to saturation, so that more light fits inside the 0–5V window. This is exactly how auto-ranging light meters work. As for the other half of your question on how to talk to the pot really depends on the part. MCP41xxx and AD5160 are SPI. AD5241 is I2C. X9C103 uses a three-wire up/down/CS interface. Once you know which one you've got, it's either this: SPI.transfer() or this: Wire.write(). Here's the shape of the control loop, assuming an Arduino and an MCP41010-style SPI pot:
A few things to watch out for:
- The wiper-position-to-gain relationship isn't always linear. If your digipot is one leg of a divider rather than the whole feedback resistor, you'll need to redo the math from the schematic.
- Once you change gain, your ADC reading no longer means the same thing in absolute terms. Track the current pot value if you care about actual light measurements.
- Without hysteresis you'll oscillate around the threshold. A better pattern is to drop gain when you exceed ~4V and bump it back up when you drop below ~1V.
- A digipot-controlled TIA gets you maybe 2–3 decades of dynamic range total. If you need to span anything close to sunlight-to-moonlight, look at a dedicated part like the TSL2591 with built-in gain stages, or add a log amp.
What's the digipot part number, and is it the only thing in the feedback path? Easier to give you specific code (and confirm the gain math) if I know the exact circuit.