# Phototransistor with digital potentiometer

As per the circuit diagram below, I'm trying to use a phototransistor with a digital potentiometer so that the sensitivity can be adjusted. PH_TR connects to an analog pin on a SAMD21 chip.

Is there any reason why this won't work. I'm not entirely sure how the digital potentiometer works. Will having W connected to GND as well as the low part of the resistor cause any problems?

What I'm trying to achieve is a resistance that can be adjusted between 0$\Omega$ and 10k$\Omega$.

TPL0401 Datasheet (digital potentiometer)

TEPT5700 Datasheet (phototransistor)

• I am not familiar with those chips but the fact that it's a potentiometer means that the output 'W' will be some fraction of the input 'H'. You have 'W' grounded so you are trying to use it as a rheostat rather than potentiometer. You should provide a link (in your question) to the datasheet. Dec 17, 2017 at 23:54
• Added datasheets @Transistor. Also, you're correct, I'm trying to use it as a rheostat, so actually in this case, what I need is a digital rheostat (or a digital potentiometer that can act as one). I should have known that! Dec 17, 2017 at 23:58
• In general it will work but you'll have to work out how the "wiper resistance" varies with "wiper position". It's possible it won't be monotonic, if that matters to you. Dec 18, 2017 at 0:36
• The Resistor is linear and definitely monotonic (all the switches are is series), but you need to use GND and W and ignore H. Dec 18, 2017 at 1:10
• This is a bad circuit because if resistance between H and W is set to a low value (<150 Ohm) and there is enough light hitting the phototransistor (both are external conditions; not inherently excluded by the circuit) both components might get damaged.
– Curd
Jul 19, 2018 at 13:22

This is easily solved with a DAC and a couple components:

I've used this circuit before, to set the threshold for a reflective sensor (4N35 optocoupler shown here for simplicity). PWM is used as DAC here; precision is not required, and an 8-bit counter incrementing at some MHz (10s kHz PWM) will do fine (give or take component values and acceptable ripple).

A regular (analog output) DAC will do just as well, in which case the capacitors can be removed, and larger resistor values are probably acceptable (reducing current consumption).

There are some alternatives with such a circuit, for example R2 can be used to set a default value (during boot, or if the MCU or DAC malfunctions), or as a placement option for fixed bias, while removing R1.

Comment on "digi-pot" ICs:

These are somewhat of a trap for newbies. It's simple to take a basic circuit, with a trimpot for example, and to merely substitute that trimpot for a programmable "equivalent". But what is the trimpot really doing? It's setting a voltage or current, most of the time. And that can be done much more directly by DAC, or digital code (whether PWM or sigma-delta, or a parallel bus, etc.), than with digi-pot type ICs.

What is a digi-pot, then? More generally, it's a multiplying DAC (MDAC). That is, the output voltage is the product of the input voltage and the digital code. This is helpful for things like variable-gain amplifiers (VGAs), volume controls and such. The downside is, DACs are typically made from chains of resistor dividers, selected with massive arrays of analog switches. The switches are tiny, and the resistors numerous; considerable resistance is introduced between the divider proper, and the "wiper" pin.

If you check the datasheets / application notes, you may find digi-pots are discouraged for use as rheostats (i.e., wired as shown in the question): the resistance value is not well controlled (it may bounce up and down as the code is varied), and has a large minimum value.

All these resistors and switches, also have significant capacitance distributed along the chain, which limits bandwidth -- typically to 200kHz or thereabouts. Digi-pots do not make good digitally-controlled variable-gain circuits; for that, a proper OTA or VGA is preferred, or other general-purpose or RF mixer type circuits. (Not that this matters here, for merely DC output levels.)

Thus, it's often better to take a step back, look at the circuit, and think about how it could be controlled by a current or voltage directly (or a ratio thereof). These will be much more amenable to regular DACs, cheap and plentiful, without requiring the more specialized digi-pot types.

This chip is 100 to 10k but using a PV current source may be a much higher or lower impedance so your operating range is limited by the low 3.3V limit and the output is a scaler product of the current *10k and rheostat ratio.

I would suggest an alternative design if you can define the specs.

Another way to make a 'programmable' potentiometer is to take a simple LED, and connect an LDR to it by using (black) isolation tape. Make sure no light except from the LED reaches the LDR.

The resistor of the LED should be chosen so that the maximum brightness can be reached (depending on the type/forward voltage of the LED). The type of LDR is in your case is 10K ohm.

Also this way the two 'subcircuits' can be decoupled (like a kind of analog optocoupler).

Than by lighting the LED, the LDR will change resistance. It doesn't look professional, but for about 5 cents you have a programmable resistor.

See comment of user253751: The above is calla a vactrol.

Also called a resistive opto isolator, see: https://en.wikipedia.org/wiki/Resistive_opto-isolator

• Why are you talking about a LDR but are drawing a photodiode? Using a photodiode will not work as described because it acts as a variable current source not as a variable resistor.
– Curd
Jul 19, 2018 at 13:30
• @Curd I meant an LDR, removed the circuit since I couldn't find an LDR. Jul 19, 2018 at 14:18
• Keyword: that assembly is a vactrol Feb 3, 2021 at 18:45
• @user253751 ... thanks I didn't know that, I added it to the answer. Feb 3, 2021 at 18:57
• @MichelKeijzers Yes, analog synths. Some day I'll build one to play around with. Then reimplement the whole thing on a tiny microcontroller :P - this is very tangential, but I think one reason people like analog synths is that you can get effects you didn't plan for by varying random bits of the circuit, whereas with a digital one you have to think up equations. Feb 3, 2021 at 19:59

The digital potentiometer acts exactly like a mechanical one with a knob, except there are limits to what potentials you may apply to the H and W terminals.

As you have it, when the potentiometer is set to have wiper W connected directly to H ($$\N=127\$$, see below), the resistance between those terminals is 0Ω, and the poor photo-transistor is connected directly across the power rails. Under strong illumination this could pass so much current that the transistor is destroyed. Don't do that.

Use the potentiometer as it was intended to be used, as a resistor potential divider, in the same way audio volume controls use them:

simulate this circuit – Schematic created using CircuitLab

The resistance to ground from the transistor's emitter is always 10kΩ, so transistor current never exceeds $$\\frac{3.3V}{10k\Omega} = 0.33mA\$$.

Potential $$\V_E\$$ at E is permitted to vary with illumination, as it should, but the potential divider now produces some controllable fraction of that value at its wiper, output $$\V_{OUT}\$$.

That output will have maximum amplitude when wiper W is at its highest position setting (127), and zero amplitude when W is connected to ground (position 0). In between those two extremes, output amplitude will be some predictable and controllable fraction of the maximum.

Since your digital potentiometer has 128 different possible position settings (0 to 127), a value I will call $$\N\$$, output $$\V_{OUT}\$$ will be:

$$V_{OUT} = V_E \times \frac{N}{127}$$

As you can see, for any given input illumination, the output signal amplitude will vary in direct proportion to $$\N\$$, which I assume is what you are aiming for.