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.
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 circuit output equation can be written versus its input as follows:
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:
Comparing this to the summing amplifier transfer function
and considering V1 our input signal Vin, we realize that
The first equation leads to the requirement that the resistor ratios have to be equal.
From the second equation, if we choose V2 = 2.5V, the resistor ratio equality is inverted:
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.
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.
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.
- Measure a Wheatstone Bridge Sensor Signal with an ADC I received a message from one of my readers asking me to help with a Wheatstone bridge circuit. Since my...
- Design a Bipolar to Unipolar Converter to Drive an ADC Most ADCs have a unipolar input range that can be a problem when designing bipolar circuits. Some common ADC input...
- Design a Bipolar to Unipolar Converter with a 3-input Summing Amplifier Since the publication of Design a Bipolar to Unipolar Converter to Drive an ADC, several readers contacted me with requests...
Related articles by YARP.