How to convert Voltage to Current 4-20mA (OPAMP)

ampop

In this post, I will show you how you can generate a current within the 4 to 20 mA range by converting a PWM wave output from an Arduino dev board.

In the next video, you can see the expected final result after following each step of this tutorial.

Parts Required

In the development of this tutorial was used the following equipment:

  • 1 Arduino Uno;
  • 1 breadboard;
  • 1 capacitor of 10uF;
  • 1 potentiometer;
  • 1 resistor of 100 Ω;
  • 1 resistor of 270 Ω;
  • 1 resistor of 10k Ω;
  • 1 NE5532 op-amp;
  • Jumper wires;
  • -12V, 12V power supply.

What exactly will be done in this publication?

Recently I was working with Programmable Logic Controllers (PLC) and one analogic card that, like it is usual, accepts inputs within the range of 4 to 20 mA. To test my algorithms, I decided to develop a test circuit and use it every time I needed one input of that current range. This way, the objective of this post is to generate a current that varies within the range from 4 to 20 mA.

With this objective in mind and after thinking a bit, I came to the following system in Figure 1. Firstly I wanted to generate a variable voltage with my Arduino board and since the one I used didn’t have any DAC, I used a PWM output and a low pass filter combined to generate a variable voltage using a potentiometer. This output was limited to the range of 1 to 5V when the potentiometer is in the minimum and maximum scale, respectively.

Figure 1 – System chart.

This 1-5V output was then converted to 4-20mA using an Operational Amplifier (Op-Amp). Follow the next sections to understand in more detail what has been done.

Generating the PWM using an Arduino board

The first step of this system is to generate a PWM wave which has its duty cycle controlled by a potentiometer attached to an Arduino board. If you never generated a PWM wave with your Arduino board you can check this post, there you will learn how to generate a PWM wave output.

This first step can be divided into two smaller ones. Firstly we will read a voltage with the A0 analog input port from the Arduino board. The voltage to read will have a range that goes from 0 to 5 V, since we connected the potentiometer pins to the 5V and GND of the board. Secondly, we will output an PWM wave, that varies its duty cycle accordingly to the potentiometer.

CAUTION: If you are using an ESP board, you will damage it if you connect to 5V. Use 3,3V instead.

If you don’t have any potentiometer you can hardcode the algorithm and obtain an output of a PWM wave with a fixed duty cycle.

In Figure 2 is presented to you the schematic for this step and after that you have the code that executes what has been explained to you. This code used the function map() which re-maps a number from one range to another. The values introduced in this function were chosen, having in mind the idea of obtaining an output with a range that goes from 1 to 5V, to correspond to the mininum and maximum of the potentiometer.

Figure 2 – Generating a PWM wave output.
// ====================================================================================
// --- Libraries ---

// ====================================================================================
// --- Constants ---
const int outPin = 3; 

// ====================================================================================
// --- Inicializations ---
// 
Code that only runs once
void setup() {  
  pinMode(A0, INPUT);
} // setup end

// ====================================================================================
// --- Infinite loop ---
// 
Code that runs repeatedly
void loop() {
  // Read value of potetiometer.
  // 0 volts corresponds to 0 and 5 volts corresponds to 1023
  int val_pot = analogRead(A0);

  // Converts to diferent range since analogwrite max is 255
  int val_conv_0_255 = map(val_pot, 0, 1023, 51, 255); 
  
  // PWM wave
  analogWrite(outPin, val_conv_0_255);

  // waits 1 sec
  delay(1000);

} // loop end

Low-pass filter

To obtain a DC from the PWM wave it will be used a low-pass filter. The used circuit is formed by two components, one resistor, and one capacitor. In a simplified way, the resistor will limit the current to the capacitor and the capacitor will fill the gaps between PWM pulses with the stored energy.

The schematic of this second step is present in Figure 3. As can be seen in the image from the green wire is possible to get a voltage with a range of 1 to 5 V depending on the position of the potentiometer. The components used in the RC filter were a 10 kΩ resistor and one 10 uF capacitor.

Figure 3 – Low-pass filter.

Converting voltage to current (Op-amp)

Finally, the main step of this post! In the third step, to convert voltage to current was used a NE5532 op-amp and a 270 Ω resistor, applying the schematic in Figure 4. The op-amp was fed with -12V and 12V and to obtain the 270 Ω resistor, the following calculations were done:

Since: V+ = V- = Vx and R=V/I

And we want that V+ = [1 ; 5] V and Io = [4 ; 20] mA, then:

Figure 4 – Voltage/current converter using NE5532 schematic.

Since standard resistors don’t include 250 Ω values, an 270 Ω were the used one. After assemble the circuit of Figure 4 you should obtain the final result of Figure 5. As have been said previously, a power supply was used to fed the op-amp with +12V and -12V.

Figure 5 – Converting voltage to current using a NE5532 op-amp.

If you want to measure the output current you should break the circuit and place your ammeter proves were you have break the circuit, check Figure 6.

Figure 6 – How to measure current.

Results

Here is presented to you the obtained result with this mini-project. In Figure 7 you, can the output current when the potentiometer is in its minimum position and, in Figure 8, you can the current when the potentiometer is in its maximum position. The values didn’t exactly coincide with 4 and 20 mA since we used 270 Ω instead of 250 Ω. Don’t forget to take a look at the video at the beginning of this post for an overview of this post.

Figure 7 – Conversion of 1V to current.
Figure 8 – Conversion of 5V to current.

Leave a Reply

Your email address will not be published.