Measure a Bipolar Signal with an Arduino Board

Arduino is a popular family of open source microcontroller boards. Hobbyists, students and engineers all over the world use this platform to quickly design and prototype a microcontroller driven circuit. One of its interfaces with the analog world is the ADC. Since these boards are mostly designed around an ATMEL ATmega32 or ATmega168 microcontroller, the ADC has 8 inputs and 10-bit resolution, making it suitable for many applications.

From time to time I receive a message through my Contact page with the question, how to interface a sensor, or an outside circuit with the Arduino ADC? In most cases the answer is an interface between a bipolar circuit and the Arduino board. As the bipolar circuit output varies from some negative to a positive level, the Arduino ADC cannot measure this signal directly, because the ADC inputs can only be between 0V and the reference voltage.

In one of these messages a reader asked me how to build an interface between a board that has an output voltage of -2.5V to +2.5V and the Arduino ADC. He told me that the Arduino reference voltage is AVCC = 5V. He would like to measure the +/-2.5V signal with the Arduino board and direct the microcontroller to take some action based on the result.


The solution is a Bipolar to Unipolar Converter, as described in this article: MasteringElectronicsDesign.com:Design a Bipolar to Unipolar Converter to Drive an ADC. The summing amplifier is a versatile circuit and simple enough to be built in no time. All we have to do is to calculate the resistors. Here is the summing amplifier schematic that would do this conversion.

Bipolar to unipolar converter for arduino boards

Figure 1

How did I calculate the resistors? For this circuit one can use the offset and gain method I described in MasteringElectronicsDesign.com:Design a Bipolar to Unipolar Converter to Drive an ADC, or the method described in MasteringElectronicsDesign.com:Solving the Summing Amplifier.

Any linear circuit transfer function can be written as follows:

General equation of a linear circuit (1)

where Vout is the output voltage and Vin is the input voltage.

If we choose the offset and gain method, we have to start by answering these two questions: What is the circuit offset and what is its gain? Let’s write down what we know:

If Vin = -2.5V, then Vout = 0V
If Vin = +2.5V, then Vout = 5V

Therefore, the gain is Gain = 1, since both the input (Vin) and output (Vout) span are 5V.

The offset needs to be Voffset = +2.5V, because we want to shift the signal up, so that 2.5V in the input becomes 0V at the converter output.

We can rewrite equation (1) with our gain and offset values:

Circuit tranfer function (2)

Comparing this to the summing amplifier transfer function

summing-amplifier-equation (3)

and considering V1 our input signal Vin, we realize that

gain-and-offset-equations (4)

The first equation leads to the requirement that the resistor ratios have to be equal.

resistor-ratios (5)

From the second equation, if we choose V2 = 2.5V, the resistor ratio equality is inverted:

resistor-ratios (6)

This is only possible if all the resistors are equal. If we choose R1 = R2 = R3 = R4 = 10k the result is the circuit in Figure 1.

Once this circuit is implemented, the ADC will convert the input voltage into counts, based on the following formula.

adc-counts-versus-input (7)

where VADC is the ADC input voltage and Vref is the Arduino reference voltage.

If you want your board to show the actual voltage Vin, the program will have to take the number of counts into a variable and calculate Vin. Vin can be determined from equation (2) where Vout is replaced with VADC of equation (7). Therefore the Arduino program will have to use the following equation to determine the input voltage from the external circuitry.

arduino-input-voltage-versus-counts (8)

Indeed, if the ADC measures 0 counts, Vin is -2.5V. If it measures 1023 counts, the output is 2.495V. The 5mV difference comes from the ADC full scale level, which is Vref – 1LSB. Read MasteringElectronicsDesign.com:An ADC and DAC Least Significant Bit (LSB) to see why.

It is worth mentioning here that the operational amplifier needs a negative voltage, because its input stage has to be driven below ground. The Arduino board is only powered at +5V, so we need an extra negative power supply for this interface. One has to assume that, if your circuit output is from -2.5V to +2.5V, it surely has a negative power supply, to accommodate the negative output voltage. So, use that supply for your circuit.

Depending on your application, choose a general purpose or a low noise Op Amp, and look at the power supply requirements in the datasheet. For most general purpose Op Amps, the power supply has to be at least 1.2V higher than the highest signal (or lower than the lowest signal). However, some rail-to-rail Op Amps require just a 0.1V delta voltage (or even less) between the signal peak and the power supply, so choose one of these Op Amps if available.

19 thoughts on “Measure a Bipolar Signal with an Arduino Board”

  1. The circuit should not require a dual supply. If the input is -2.5V then the voltage at the summing junction would be 0V. When the input voltage is +2.5V then the voltage at the summing junction is +2.5V. So the input common mode swings between 0V and +2.5V.
    Practically the op-amp would need to include the bottom rail, 0V, which most do. On a single supply of 5V the +2.5V at the summing junction allows for a 2.5V headroom for the input common mode range. Most PNP or P Channel input op-amps will not have that bad of an input common mode range. The output will need to be rail to rail and if one does not want to drop any codes due to rail performance then I could see a dual supply being used.

    Reply
    • Hi Wayne, great comment. Indeed, this particular circuit does not need a negative supply unless the user really wants to hit 0V, down to millivolts level.

      Readers should be aware though, that if the input signal goes below the negative value of the reference voltage, then they need a negative power supply. If the input signal stays above the negative value of the reference voltage at all times, then they do not need a negative power supply.

      Thank you for your contribution.

      Reply
  2. Hi Adrian, I was wondering if this circuit configuration would work to read a sinusoidal input with range -5V to +5V, and would the Gain of the summing amplifier be 2 and offset = 5?
    Thanks!

    Reply
  3. Please, what is a triangle U1 on your scheme? I wonder if I could reproduce this scheme using resistors only, as you say.
    Sure, my question is naive. Sincerely thank you for reply.

    Reply
    • That is an operational amplifier, or short op amp. It is needed to buffer the resistor pair R1/R2. The other two resistors set the gain of the circuit. I would need to see your circuit, or get more info about your application, to give you an answer if you need the op amp or not.

      Reply
  4. Great article!

    Can you also talk about the errors introduced by this circuit due to component tolerances and temperature drift?

    Reply
  5. In your example, I was wondering about the 2.5V shifting voltage. specifically, if I use a voltage splitter on the +5V Arduino power line with equal value resistors to get 2.5V, what values should I use? Does the summation where R1 and R2 lines meet require equal current from the 2.5V shift and the analog signal? I’m probably saying this wrong, but I’m really new to this. I was thinking 1K and 1K for the splitter. Thanks!

    Reply
    • Assuming that your input and output voltage levels are the same as the ones in the article (input -2.5V to 2.5V, output 0 to 5V), you can use a voltage divider with two resistors. This will divide 5V in 2, for the 2.5V reference. However, these two resistors will change the ratio of R1 and R2. So you need to drop the value of R2 to take the divider resistors into consideration. So, if you use two 10kohm resistors for your divider, make R2 = 4.99kohm. All resistors should be at least 1%.

      Reply
  6. Hello,
    I need to use a level shift cct to interface emg sensor and arduino. What is the best cct diagram from those two cct diagrams. this article was really helpful. thank you very much

    Reply
    • Which diagrams are you referring to? There is just one figure in this article. To answer your question, you need to tell me more: What is the sensor signal amplitude? What is the sensor output resistance? What is the signal level expected at this circuit output?

      Reply
  7. Why not just use the “Analog Input Reference” pin on the Arduino/AVR to cause its ADC
    to read +2.5 to -2.5V and then scale the ADC input for whatever range you might want?
    Seems too easy.

    Reply
  8. Hi, thanks for the article – it’s very helpful. I just have a couple of questions:
    1. If I use a buck voltage regulator to supply the 2.5V supply, do I need to modify the resistances at all?
    2. In the first comment above you mention that for this specific example, the second voltage supply is not actually required; do you mean that the +v and -v feeding the op amp are not required?
    Thanks!

    Reply
    • 1. As long as it is a 2.5V supply you do not need to modify the resistors.
      2. An op amp cannot function without a power supply. The comment says that, for this particular circuit, you do not need the negative power supply. But you need the positive one.

      Reply
  9. Hi Adrian,
    Greetings. Good article. I may be wrong, but, I do believe that there could be an error in your circuit. You are missing a 10K resistor to ground node from the non-inverting input of the opamp. At least thats how classical summing amplifier configuration is depicted or thats how I remember it from my college days.
    The classical equation for the o/p of the summing amplifier is as follows:
    Vout = V1(R5/ (R1+R5))*G + V2*G – V3(R4/R3)
    where I have assumed R5 to be a 10 K resistor from the non-inverting terminal of the opamp to circuit ground AND
    where G = 1+ R4/R3
    In your case since R5 is infinity then the equation reduces to
    Vout = (V1 + V2) * G – V3(R4/R3)
    Therefore what you refer to as the “Offset” its technical nomenclature happens to be the Pedestal voltage. This pedestal voltage in the above circuit is 2.5 V and when multiplied by the non-inverting gain of (1+ 10K/10K) = 2 will give you an effective pedestal voltage of 5V. Therefore the signal will swing not around +2.5V but around 5V.
    Just my two cents.
    Regards Anand

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Show Buttons
Hide Buttons
'