# Differential analog signal conversion using Arduino Uno

I need to perform a A/D conversion for a differential signal using Arduino Uno. I have tried a software method where I connect one input to A0 and another to A1, read ADC for both channels and then subtract it in the code. But the 100 ms time to convert the analog signals is causing some errors as it is not perfectly a differential signal conversion (i.e. there is some delay between the two samples taken and hence it is not exactly differential signal).

Now I am not sure about this, but can I connect one of the analog inputs to the Arduino Uno GND pin and then perform a conversion for the other signal i.e. one input to ground of Arduino another to A0 of Arduino and then perform A/D conversion for A0. Would this be correct? Would it cause damage from a circuit perspective?

• Connecting signal source to GND is bad idea. What is your signal source you want to measure? Can you add schematic? I feel you are trying measure differential signal incorrectly. – Kamil Jun 14 '14 at 20:49
• I think you mean 100µs. – Gerben Jun 14 '14 at 20:53
• Yes i meant 100 micro seconds.....typing error – dpk Jun 15 '14 at 17:23
• How negotiable is your choice of Arduino? If you were to use e.g., a Leonardo or Micro instead of an Uno, you'd have a differential A/D converter built in. – microtherion Sep 13 '14 at 0:29

Given your requirement to measure a 20mV signal on top of 2.5V, one solution to this is to use an instrumentation amplifier. To get 10-bit-ish accuracy out of a 20mV signal you need 20uV-ish stability. One choice, only available in a rather tiny MSOP8 package, would be the AD8237. Use the maximum gain possible that will not result in any possible saturation (of the amplifier or overrange of the ADC). That way you can get about 10 bits resolution rather than just a few bits- maybe 200-250 times better.

You could use a lower performance difference amplifier, but it would greatly compromise the measurement.

simulate this circuit – Schematic created using CircuitLab

If you look at the ATMega328p datasheet you'll see that the ADC only supports single ended voltage measurements. For some other Atmel chips (e.g. the ATTiny45) you can change the negative pin used by the ADC by setting the ADMUX register. For instance

ADMUX |= _BV(MUX0);


should set ADC1 as the negative input.

If you look at the Arduino source for analogRead (wiring_analog.c) you'll see that this method resets the ADMUX register so you'd have to write your own function if you wanted to use a differential measurement using a chip that supported it.

• How does this relate to the original question? Can you be more specific? – jose.angel.jimenez Dec 22 '15 at 8:22
• If you connect one input to ADC0 and the other to ADC1 then set ADC1 as the negative input to the ATMega's ADC you will perform a differential measurement in a single conversion. I haven't tried this using the Arduino analogRead yet but it works using the ADCSR. I use this all the time when building transimpedance amplifiers using op amps. You need to measure the differential voltage across the feedback resistor to get the full resolution of this circuit so I hook the op amp output to ADC0 and the other side of the feedback resistor to ADC1. – 32bits Dec 22 '15 at 17:36
• I just got ahold of an ATMega and realized I'm wrong. This chip does not support differential A to D conversion. The section I was reading is the mega's Analog Comparator which does allow a differential comparison. My comments stands for ATTiny chips though which is what I've been using to measure my TIA circuit. – 32bits Dec 23 '15 at 4:18
• Please, update your answer accordingly. It is a great answer, even if it does not proves useful for the MCU used by the OP. You can edit and comment that you cannot use an ATMega328p for the purpose but that you can use some other Atmel MCUs (with very similar microarchitecture). Thank you! – jose.angel.jimenez Dec 23 '15 at 8:33

You should use one of these (hardware) solutions

• op-amp in differential circuit (LM358 - cheap and popular rail-to-rail op-amp)
• external differential ADC (MCP3421 - i2c, differential, slow, accurrate, easy to use but slow)

to measure differential signal with ATmega328, because this microcontroller ADC has no differential feature.