1

I have a small and very basic circuit that PWMs an RGB LED. It has a potentiometer to allow me to set brightness level for night time and a LDR that allows me to detect night time.

I took some measurements of the LDR under various lighting conditions so that I could select a reasonable resistor to put in series with the LDR as a voltage divider.

In practice, however, the readings were not what I expected. If I measure the resistance of the LDR with my multimeter, it's about 1/5th what I had measured when it was not in the circuit.

I selected a 51K Ohm resistor for the LDR divider circuit. My multimeter is also measuring that as 10K Ohm. The potentiometer I'm using for setting the brightness is 10K Ohm, but in circuit it measures as about 3K Ohm.

I'm assuming that these resistances are reduced because they're in parallel with each other, but I can't figure out how to isolate them so that I can get reliable readings for the micro-controller.

I'll do my best to mock up the circuit . . .

schematic

simulate this circuit – Schematic created using CircuitLab

Based on some of the comments, I decided I should isolate parts of the circuit to see if I could reproduce the measurements in the full circuit. I built this circuit in a breadboard and the measurements are the same as I mentioned above. That is to say, my expected resistances are reduced by about 66%.

schematic

simulate this circuit

D. Patrick
  • 626
  • 6
  • 20
  • 1
    That's an effect of measuring the diodes internal to the µC which are protecting the input pins from over/undervoltage. Remove the µC and measure again. (It does not matter, though.) – Janka Nov 12 '18 at 00:58
  • 2
    In general, you should not expect to be able to measure the resistance of an individual component with a multimeter when it is connected in-circuit. – The Photon Nov 12 '18 at 01:00
  • 1
    @Janka most resistance meters don't output a voltage high enough to switch on diodes, so I don't think this is the issue. Even if this was the case though, I would think the resistance he'd measure would be much lower than what he's seeing – DerStrom8 Nov 12 '18 at 01:00
  • Janka and DerStrom8, I reduced the circuit to just the two voltage dividers and was able to reproduce the measurements. It makes sense that the rest of the circuit is impacting measurements like ThePhoton said, but the circuit behaves like you would expect with the in circuit measured values rather than the measurements I took out of circuit. – D. Patrick Nov 12 '18 at 01:18
  • 1
    Just curious, but have you considered the idea of doing the analog stuff externally, including the hysteresis, and simply having a digital I/O signal for light/dark? See my answer for Choosing Voltage Divider Resistor For LDR. – jonk Nov 12 '18 at 01:46
  • 1
    Are you trying to measure resistances with power applied to the circuit? If so, any readings you get will have little or no relation to the "real" resistance. An ohmmeter applies a voltage between its probes, and measures the resulting current (or applies a current, and measures the resulting voltage). If something else is also causing currents or voltages in the circuit, the ohmmeter reading is meaningless. In any case, the meter measures the apparent resistance between its probes - which will include anything connected in parallel with the component you wish to measure. – Peter Bennett Nov 12 '18 at 02:19
  • @PeterBennett, thanks. I’m measuring without power. I think that my two voltage dividers are creating a parallel resistance and are reducing their values. Or, something like that. There’s probably a smart way to describe this; however, I don’t know how. :) – D. Patrick Nov 12 '18 at 02:33
  • 1
    @D.Patrick Are you actually intending on measuring the resistance? Because it goes through two to three decades of change, from light to dark. Something like from $9:\text{k}\Omega$ to $3.7:\text{M}\Omega$ for one device I have here. To linearize that where you get a relatively uniform change in voltage over its typical operating range of lighting, you'd need to take the logarithm. Otherwise, most of your range winds up pinched at one end or the other of your ADC range. You can survive it. But it's ugly. So digital in with hysteresis? Or truly analog in? – jonk Nov 12 '18 at 04:29
  • @jonk, I see what you're saying I think. Using the circuit from your previous answer, I can take the analog signal and convert it to a digital on/off signal. The hysteresis is kind of a threshold where the signal won't change due to noise (or the ambient light hovering around the light dark limit I set)? That seems like a pretty reasonable approach. Do I set the desired threshold with the resistors in your circuit? One problem I have is that I have two limits. This is a night light, so when the ambient light dims, I dim the LED. When it's dark, I stop showing blue light. – D. Patrick Nov 12 '18 at 15:22
  • 1
    @D.Patrick What one uses to solve problems depends on what experiences and knowledge one can apply. So just using an ADC might be obvious and best for a software-only type since a resistor divider is easy to understand for almost anyone. For someone with any electronic design skills, though, and strictly speaking from a hobbyist point of view here, it would be better to just apply hysteresis outside and get a digital input that "just works right." For an electronic designer eyeing 10,000 units a year, the divider might again be better because its less parts and no BJT variation to worry about. – jonk Nov 12 '18 at 15:33
  • 1
    @D.Patrick The hysteresis is a dead-band of sorts that sets up a different threshold depending on the prior state. Without it, you might get lots of noisy transitions while the LDR slowly varies in value. With it, you get nice clean and widely separated signal changes that "feel right" when you see the results. And yes, different resistor choices can set the position as well as the width of the dead-band into different places. [The added complexity you indicate (the blue light and dimming an LED?) I think you should have written out all this in your question at the outset.] – jonk Nov 12 '18 at 15:35
  • @jonk, that's fair. I was trying to avoid providing too much unnecessary information and may have been overly exclusive. Sorry about that. – D. Patrick Nov 12 '18 at 15:39

2 Answers2

3

This is a bit of an X-Y problem. You cannot accurately measure the resistances involved in the voltage dividers when the circuit is not powered, because the constituent resistors wind up in parallel. For instance, when you attempt to measure the resistance across the LDR, you wind up measuring the resistance of this circuit:

schematic

simulate this circuit – Schematic created using CircuitLab

Which, if you do the math gives you:

\$R_{measured} = \frac{1}{ \frac{1}{R_{LDR}} +\frac{1}{ R_{1} + R_{2}} }\$

\$R_{measured} = \frac{1}{ \frac{1}{82k} +\frac{1}{ 51k + 10k} } = 34.97k\Omega\$

That said, this does not mean that the two dividers will interfere with each other in circuit. In that case, as long as the power supply is stable and has low impedance, the voltage across the whole divider can be considered fixed. The typical way that surrounding circuitry interferes with the output of a voltage divider is when enough current is drawn out of the voltage divider to create a meaningful error in the divider.

schematic

simulate this circuit

Ideally, the load current on the output of the voltage divider would be zero, and if the voltage divider were connected to the input of an op amp, that would be close enough to true. If, however, we draw a substantial amount of current \$I\$ out of the divider, then we get an error:

If \$I\$ is zero: \$V_{out} = \frac{V}{R_{1}+R_{2}}\times R_{2}\$

If \$I\$ is non-zero: \$V_{out} = (\frac{V}{R_{1}+R_{2}}-I)\times R_{2}\$

(note that the sign of \$I\$ depends on the direction of current flow, so the error could increase or decrease our actual reading)

This shows that the amount of current that flows out of the voltage divider \$(I)\$ needs to be substantially smaller than the current that flows through the divider \$ (\frac{V}{R_{1}+R_{2}})\$ to minimize this error.

Now, you haven't mentioned whether your ADC readings are coming out as you expect, but let's discuss the main potential source of error there anyway. To start with, lets look at what a typical ADC channel looks like, electrically. In this case, it's going to have a sampling capacitor that is temporarily connected to the input for some period of time before the ADC performs the conversion. Something like this:

schematic

simulate this circuit

What this means is that during the sampling time, the input mux will have connected the appropriate input channel to the sampling capacitor, and the capacitor will charge (or discharge) towards the input voltage at a rate determined by the capacitance and the impedance of whatever's connected to the selected ADC input (in this case, one of your voltage dividers). In order to get an accurate reading, your sampling time must be some multiple of the time constant of the sampling capacitor and your total input impedance (check the datasheet for details). If your sampling time is inadequate, your ADC readings will be off, because the sampling capacitor does not have adequate time to charge or discharge to the correct voltage.

For this reason, the sampling time on MCU ADCs is typically configurable, as the required sampling time will depend on the nature of the circuitry you're attempting to measure. If you have some really high impedance circuitry, you would probably want to use an op-amp buffer as another answer suggests. However, in your case, this is entirely unnecessary as long as your sampling time is set correctly.

ajb
  • 3,414
  • 12
  • 31
1

The easiest way to do this is using an op-amp buffer circuit:

enter image description here

V_in is connected to the output of your voltage divider, and V_out connects to the rest of the circuit.

No current flows into the inputs of an op-amp (practically speaking, anyway), so this will not affect the behavior of the voltage divider. The output voltage of the op-amp will follow the input voltage exactly, since it is a x 1 amplifier. This is usually the easiest way to isolate your voltage divider from the rest of the circuit so that additional impedance doesn't affect the voltage divider output.

EDIT: You may need to use one of these as the supply to the voltage dividers for your particular setup. In that case connect V_in to your Vcc, and V_out to the "top" of the resistor divider.

DerStrom8
  • 21,314
  • 9
  • 63
  • 97
  • 1
    An excellent question by the way. – DerStrom8 Nov 12 '18 at 00:59
  • Thanks so much! It took me quite a bit of time to learn enough to even know what to ask. I'm still not really certain I'm on the right track. :) I'll try your solution. I think I have some op amps lying around from a kit. Thanks!! – D. Patrick Nov 12 '18 at 01:22
  • 1
    This is definitely information worth knowing, but is not clearly related to the OP's present problems, which relate to using a multimeter to measure in circuit, nor to the actual function of the OP's circut, where the impedances are low enough that this technique is not necessary. – ajb Nov 12 '18 at 02:44
  • 1
    @ajb The title of the question itself asks how to isolate the dividers so that they aren't interfered with by other parts of the circuit, which is the question that I answered. But either way I would expect this solution to help, though as was already mentioned in comments, the best way would be to pull the parts out of the circuit. – DerStrom8 Nov 12 '18 at 02:58
  • 1
    @DerStrom8 An opamp buffer will essentially add nothing over OP's current circuit. Some of the interference comes through R2 and the rails, some of it through the ESD protection devices, which an opamp is as likely to have as a microcontroller. The circuit is effectively identical to the current one, since you still have the same things connected effectively in parallel to the DUT. – nitro2k01 Nov 12 '18 at 06:21
  • 1
    @nitro2k01 I don't think you understand my answer. First of all, I doubt ESD protection devices are interfering in this case because, as I already said before, most resistance meters don't apply a voltage high enough to cause silicon to switch on. Therefore it can be treated as an open circuit, or at the very least a very high impedance. As for the op-amp buffers, you can use them to isolate each divider/resistance from the rails, which is what the OP was asking for. – DerStrom8 Nov 12 '18 at 11:30
  • @DerStrom8 How would the high impedance of an input pin on a microcontroller be different in this context from the high impedance of an input pin of an opamp? – nitro2k01 Nov 13 '18 at 12:49
  • @nitro2k01 I am talking about using the buffer to isolate the resistors on the rails from one another. I'm not talking about isolating them from the microcontroller. Perhaps you didn't read my Edit? – DerStrom8 Nov 13 '18 at 13:05