2

I've been using an Arduino's analog input to read a resistance. The resistance is typically from an LDR or from an adjustable resistor.

It's working fine so far.

I have 10 bits resolution, usually I don't want more than 4 bits, and at the very most, I'll want 8 bits.

I read about op-amp voltage buffers, but given so far everything works smoothly with my 2 devices (sometimes connected over 40m of wires, that is a Cat5 20m cable with the Arduino at one end and the LDR at the other end).

Do I need that op-amp? And if I don't, could you suggest a case where it'd useful?

user1532080
  • 177
  • 1
  • 7
  • 1
    The higher the impedance of your source relative to the input impedance of your ADC, the more you need the buffer. But if you only want 4-bits of resolution you can get away with quite a bit. – DKNguyen Apr 11 '21 at 06:47
  • Impedance is still a bit of a mystery to me. Typically, I send Aruino's Vcc (5V or 3.3V) over a cable, then there's a resistor, then it comes back over the cable. There's then a voltage divider with a 5K or 10K resistor, and the analog input. – user1532080 Apr 11 '21 at 07:26
  • See https://electronics.stackexchange.com/questions/501734/what-does-a-high-impedance-input-mean-for-an-adc/501737#501737 – DKNguyen Apr 11 '21 at 19:39
  • @DKNguyen thanks! – user1532080 Apr 12 '21 at 11:56

3 Answers3

4

If your LDR is at the end of 40m of wires, then these wires may pick up some noise or AC hum that will screw the accuracy of your ADC measurement.

First thing is to use a shielded cable ; if you use Cat5 and it's shielded Cat5 then just connect the shield to chassis ground on the arduino side. Then use two wires in a twisted pair for your LDR, not two random wires from the cable that are not in a twisted pair.

Then you need to protect the arduino input against voltage spikes the cable could pick up if there is an ESD event or a lightning strike in the general area. So add some protection diodes on the arduino side from the signal wire to VCC and GND.

And you need a filter on the arduino side to get rid of noise. This depends on the frequency of the signal you're measuring. If you use a LDR to know if it's day or night outside, then the speed is going to be pretty slow, so you can just stick a capacitor between the signal and ground, something like a 100nF ceramic. That will get rid of noise and hum, and also help with ESD protection.

The input impedance of a micro ADC inputs has two components. First there is a leakage current, that looks like a very high resistor value, and will add a bit of DC error. So look in the datasheet for this, most likely it isn't a problem. The second component of the input impedance is that SAR ADCs charge their sampling capacitor from the source when sampling, which draws a bit of charge from the source. This has two effects: it uses a current that is proportional to sampling frequency, and if source impedance is too high, the sampling cap won't have time to settle to the correct value. This is why it is sometimes necessary to add a buffer to high impedance sources. Although in your case, if you added a buffer, it would be better on the LDR side, to drive the cable with a low impedance, which reduces noise pickup.

But if the signal is slow enough, which should be the case here, the filter capacitor will do the job just fine: if you use a 10nF cap and the ADC sampling cap is 1pF, when it samples it will at most change the voltage on the filter cap by 1pF/10nF or 1 in 10000 which is much less than 1 LSB, so no problem.

So, you can get away with not buffering a high impedance signal if you use a filter cap, and you use a sampling frequency that is low enough that the ADC input current, which is proportional to sampling frequency and sampling capacitor charge, doesn't create too much error across the source impedance. In practice it works very well, I've used that trick to monitor batteries with high megohm voltage divider values, no need for opamp, just don't sample the voltage on the battery 1000 times per second.

bobflux
  • 77,207
  • 3
  • 91
  • 222
3

Here is a list of my personal recommendations:

  1. If the output impedance of the source is high then you should consider using an opamp. But you should also check the input impedance of the ADC channel Even if it's high enough, the recommended max output impedance of the source should be 10 kΩ. This determines the need for buffer use.
  • Let's say you want to measure the supply voltage of the system using a voltage divider, and the divider resistors are a few kΩ. Using a buffer here is overkill because a direct connection will not affect the measurement.
  • But, if you want to measure the voltage of a 12-volt backup battery without draining it then you should use very high divider resistors (something like hundreds of kΩ or even MΩ), and using a buffer here becomes a must. For example, using 9 MΩ and 3 MΩ divider resistors will bring an output impedance of 2.25 MΩ, and if the input impedance of the ADC is 10 MΩ then the error will be more than 20% Fun fact: Input bias current of the opamp becomes a key parameter here.
  1. Using a buffer when carrying a signal over a long distance may be useful. If, again, the source impedance is high and the signal amplitude is low (e.g. lower than 10 mV) then you may consider using a buffer. Because the higher the output impedance, the higher the noise it will pick up. But if the signal amplitude is over a few hundred Volts and the required accuracy is not precise then buffering may not be needed.
Rohat Kılıç
  • 33,940
  • 3
  • 29
  • 85
  • 2
    Hi, Rohat. You may be interested in https://www.nist.gov/pml/weights-and-measures/writing-metric-units where there is a summary of the SI rules. e.g. SI units named after a person have their symbols capitalised but are lowercase when spelled out. 'V' or 'volt' (not 'Volt'). Space between numbers and units (same as "7 mice", not "7mice"). Other docs explain that abbreviations and long form should be used consistently so 'MOhm' fails. It should be 'M$\Omega$ or 'megaohm' or 'megohm'. – Transistor Apr 11 '21 at 07:48
  • Thanks, @Transistor, especially for the link. Sometimes I don't pay attention to those details when posting a quick answer. I'll try from now on. – Rohat Kılıç Apr 11 '21 at 08:56
  • Arduino's ADC input is not 20 Mohm. If that is a Mega328P or another AVR, the datasheet says the source impedance should be 10k or less, to be able to charge the sampling capacitor fast enough during the sampling phase for accurate measurements. – Justme Apr 11 '21 at 18:49
  • @Justme thanks for correction. – Rohat Kılıç Apr 13 '21 at 03:00
1

Many microcontroller ADCs will sample an input by momentarily connecting a capacitor. Depending upon the controller, this capacitor may be precharged to a voltage near the previous voltage that was converted (not necessarily on the same channel), the analog zero reference, or an arbitrary and unpredictable voltage. This can lead to three scenarios:

  1. If the resistive impedance of the analog input is low enough, and the combination of the chip's internal capacitor with any external capacitance is low enough, the input voltage will be disrupted when the chip connects the capacitor, but will rebound within the chip's sampling time, yielding a good reading.

  2. If the external capacitance on the analog input is much higher than the chip's switched capacitance, that capacitance will limit the size of the disturbance when the capacitor is switched in. Note that to limit the disturbance to 1% of the voltage difference, the external capacitor would have to be 100 times the size of the internal capacitance. To limit it to 0.1% of the voltage, it would need to be 1000 times the size.

  3. If neither of the above conditions applies, usable ADC accuracy may suffer, especially on devices that don't precharge the cap to a consistent voltage. If a device consistently precharges the cap to the analog zero reference, and the input resistance and capacitance remain constant, the voltage disturbances will cause the readings to be lower than they should be, but it may be possible to compensate for them. If taking a reading leaves the cap precharged to the input voltage, then good results may be obtained by taking a few readings in succession and discarding all but the last one. On devices that precharge the cap to an arbitrary and unpredictable voltage, I don't think there's any good alternative to either buffering the input or adding enough capacitance to achieve scenario #2 (in cases where that wouldn't cause other problems).

Unfortunately, I don't think I've ever seen a chip specify the internal capacitor's precharge behavior, or anything about it other than (hopefully) an upper bound on its capacitance.

supercat
  • 46,736
  • 3
  • 87
  • 148