Electronic projects

[Electronic projects][bleft]

Arduino Projects

[Arduino Projects][bleft]

Metal detectors

[Metal detectors][bleft]

Home projects

[Home projects][bleft]

Arduino power meter: measure voltage, current and power consumption


As electronic engineers, we always need to rely on instruments to measure and analyze the working conditions of the circuit. From simple multimeters to complex power quality analyzers or DSOs, everything has its own unique applications. Most of these meters are readily available and can be purchased according to the parameters to be measured and their accuracy. But sometimes we may encounter situations where we need to make our own meters. For example, you are working on a solar photovoltaic project and you want to calculate the power consumption of the load. In this case, we can use a simple microcontroller platform like Arduino to make our own power meter.

 Making your own meters not only reduces the cost of testing, but also provides us with room to simplify the testing process. For example, a power meter built with Arduino can be easily adjusted to monitor the results on the serial monitor and draw graphs on the serial plotter, or add an SD card to automatically record the voltage, current, and power values ​​at predefined time intervals. Sounds interesting! ? let's start......

Required materials

● Arduino Nano development board

● LM358 operational amplifier

● 7805 voltage regulator

● LCD display 1602

● Test load

● Breadboard

● Welding kit

Circuit schematic

The complete circuit diagram of the Arduino power meter is as follows:

For ease of understanding, the Arduino power meter circuit is divided into two units. The upper part of the circuit is the measurement unit, and the lower part of the circuit is the calculation and display unit. For those who are not familiar with this type of circuit, please refer to the label. For example, the +5V label means that all the pins connected to the label should be considered as they are connected together. Labels are often used to make circuit diagrams look neat.

This circuit design is suitable for systems with a working voltage range of 0-24V and a current range of 0-1A, taking into account the specifications of solar photovoltaic power generation. But once you understand the working principle of the circuit, you can easily expand the range. The basic principle behind the circuit is to measure the voltage across the load and the current through it to calculate the power consumption. All measured values ​​will be displayed on the LCD screen 1602.

Next let us divide the circuit into small segments so that we can clearly understand how the circuit works.

Units of measurement

The measurement unit includes a voltage divider to help us measure the voltage, and a turn-off resistor with a non-inverting operational amplifier to help us measure the current through the circuit. The voltage divider part of the above circuit is as follows:

Here the input voltage is represented by Vcc. As mentioned earlier, we are designing a circuit with a voltage range of 0V to 24V. But a microcontroller like Arduino cannot measure such high voltage values; it can only measure voltages of 0-5V. Therefore, we must map the voltage range of 0-24V to 0-5V. This can be done easily by using the voltage divider circuit shown below. The resistors 10k and 2.2k together form a voltage divider circuit. The output voltage of the voltage divider can be calculated using the following formula. It is also used to determine the value of resistance. If you redesign the circuit, you can use our online calculator to calculate the resistance value.

Vout = (Vin×R2)/(R1 + R2)

The mapped 0-5V can be obtained from the middle part labeled Voltage. Then the mapped voltage can be fed back to the Arduino analog pin.

Next we must measure the current through LOAD. We know that the microcontroller can only read analog voltage, so we need to convert the current value to voltage in some way. This can be done by simply adding a resistor to the path. According to Ohm's law, this resistor will reduce the voltage value on it, which is proportional to the current flowing through it. The value of this voltage drop will be very small, so we use an operational amplifier to amplify it. The circuit is as follows

The value of the shunt resistance (SR1) here is 0.22 ohms. As mentioned earlier, we are designing a 0-1A circuit, so according to Ohm's law, we can calculate the voltage drop across the resistor. When the maximum 1A current passes through the load, the voltage drop is about 0.2V. This voltage is very small and can be read by the microcontroller. We use an operational amplifier in non-inverting amplifier mode to increase the voltage from 0.2V to a higher level for Arduino to read.

The operational amplifier in non-inverting mode is shown above. The gain of the amplifier is designed to be 21, so 0.2 * 21 = 4.2V. The formula for calculating the gain of the operational amplifier is given below. If you are redesigning the circuit, you can also use this online gain calculator to get the value of the resistance.


Gain = Vout / Vin = 1 + (Rf / Rin)

In this example, the value of Rf is 20k and the value of Rin is 1k, so our gain value is 21. Then the amplified voltage of the operational amplifier is provided to the RC filter, and a filter with a resistance of 1k and a capacitance of 0.1uF is used to filter any coupled noise. Finally, the voltage is fed back to the Arduino analog pins.

The last remaining part of the measurement unit is the voltage regulator part. Since we will provide a variable input voltage, we need a stable +5V for the Arduino and op amp to work. The regulated voltage will be provided by the 7805 voltage regulator. Add a capacitor to the output to filter out noise.

Calculation and display unit

In the measurement unit, we designed the circuit to convert the voltage and current parameters to 0-5V, which can be fed back to the Arduino analog pins. Now, in this part of the circuit, we connect these voltage signals to the Arduino and connect the LCD screen 1602 to the Arduino so that we can view the results. The circuit is as follows

As shown in the figure, the voltage pin is connected to analog pin A3, and the current pin is connected to analog pin A4. LCD is powered by +5V of 7805 and connected to digital pins of Arduino, working in 4-bit mode. We also use a potentiometer (10k) connected to the Con pin to change the contrast of the LCD.

Programming Arduino

Now that we have a good understanding of the hardware, let's turn on the Arduino and start programming. The purpose of this code is to read the analog voltage on pins A3 and A4 and calculate the voltage, current and power values, and finally display it on the LCD screen. The complete program is given at the end of the page, which can be used for the hardware discussed above. Next, the code is divided into small pieces and explained.

As with all the procedures we started, define the pins we use. In this article, pins A3 and A4 are used to measure voltage and current respectively, and digital pins 3, 4, 8, 9, 10 and 11 are used to connect LCD and Arduino.

  1. int Read_Voltage = A3;
  2. int Read_Current = A4;
  3. const int rs = 3, en = 4, d4 = 8, d5 = 9, d6 = 10, d7 = 11; //Mention the pin number for LCD connection
  4. LiquidCrystal lcd(rs, en, d4, d5, d6, d7)

We also include a header file called liquid crystal, which is used to connect the LCD display to the Arduino. Then in the setup function, we initialize the LCD display and display an introduction text " Arduino Wattmeter " and wait two seconds before clearing it. The code is shown below.

  1. void setup() {
  2.   lcd.begin(16, 2); //Initialise 16*2 LCD
  3.   lcd.print(" Arduino Wattmeter"); //Intro Message line 1
  4.   lcd.setCursor(0, 1);
  5.   lcd.print("-Circuitdigest"); //Intro Message line 2
  6.   delay(2000);
  7.   lcd.clear();
  8. }

In the main loop() function, we use the analog read function to read the voltage values ​​from pins A3 and A4. We know that the Arduino ADC output value is 0-1203 because it has a 10-bit ADC. Then the value must be converted to 0-5V, which can be done by multiplying by (5/1023). Then in the previous hardware, we have mapped the actual value of the voltage from 0-24V to 0-5V, and the actual value of the current from 0-1A to 0-5V. So now we must use a multiplier to restore these values ​​to actual values. This can be done by multiplying it by the multiplier value. The value of the multiplier can be calculated theoretically using the formula provided in the hardware section, or if you have a set of known voltage and current values, you can actually calculate it. I followed the latter option because it is more accurate in real time. So the value of the multiplier here is 6.46 and 0.239. So the code looks like this

  1. float Voltage_Value = analogRead(Read_Voltage);
  2. float Current_Value = analogRead(Read_Current);

  3. Voltage_Value = Voltage_Value * (5.0/1023.0) * 6.46;
  4. Current_Value = Current_Value * (5.0/1023.0) * 0.239;

How to measure more accurately?

The above method of calculating actual voltage and current values ​​can work normally. But there is a disadvantage, that is, the relationship between the measured ADC voltage and the actual voltage is not linear, so a single multiplier will not give a very accurate result, and the same applies to current.

Therefore, in order to improve the accuracy, we can use a known set of values ​​to draw the measured ADC value and the actual value, and then use the data to draw the graph and use the linear regression method to derive the multiplier equation. ,

Finally, once we have calculated the actual voltage and actual current through the load, we can use the formula to calculate the power (P = V * I). Then we use the following code to display all three values ​​on the LCD display.

  1. lcd.setCursor(0, 0);
  2. lcd.print("V="); lcd.print(Voltage_Value);
  3. lcd.print(" ");
  4. lcd.print("I=");lcd.print(Current_Value);

  5. float Power_Value = Voltage_Value * Current_Value;

  6. lcd.setCursor(0, 1);
  7. lcd.print("Power="); lcd.print(Power_Value);

Work process and testing

I used a breadboard to solder all the components as shown in the circuit. I use screw terminals to connect the load and a normal DC socket to the power supply. The Arduino Nano development board and LCD are mounted on the breadboard so that they can be reused in the future.

After preparing the hardware, upload the Arduino code to the Nano development board. Adjust the trimmer potentiometer to control the contrast of the LCD until you see a clear introduction text. To test the circuit board, connect the load to the screw terminal connector and the power supply to the jack. When this project is working, the power supply voltage should be greater than 6V, because Arduino needs +5V to work. If everything is normal, you should see the voltage value and current value displayed on the load on the first line of the LCD, and the calculated power displayed on the second line of the LCD screen, as shown below.

The interesting part of making something is testing it to see how well it will work. To do this, I have used the 12V car indicator bubble as the load and RPS as the power source. Since the RPS itself can measure and display current and voltage values, we can easily check the accuracy and performance of the circuit. Yes, I also use my RPS to calibrate my multiplier value to get close to the accurate value.

This Arduino-based power meter project has more upgrade functions that can be added to improve the performance of automatic data recording, such as drawing graphics, notifying over-voltage or over-current conditions, etc. So stay curious and let me know what you will use it for.

Complete Code

The complete code used in this article is as follows:

  1. /*
  2. * Wattmeter for Solar PV using Arduino
  3. * Dated: 27-7-2018
  4. *
  5. * Power LCD and circuitry from the +5V pin of Arduino whcih is powered via 7805
  6. * LCD RS -> pin 2
  7. * LCD EN -> pin 3
  8. * LCD D4 -> pin 8
  9. * LCD D5 -> pin 9
  10. * LCD D6 -> pin 10
  11. * LCD D7 -> pin 11
  12. * Potetnital divider to measure voltage -> A3
  13. * Op-Amp output to measure current -> A4
  14. */

  15. #include <LiquidCrystal.h> //Default Arduino LCD Librarey is included

  16. int Read_Voltage = A3;
  17. int Read_Current = A4;
  18. const int rs = 3, en = 4, d4 = 8, d5 = 9, d6 = 10, d7 = 11; //Mention the pin number for LCD connection
  19. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

  20. void setup() {
  21.   lcd.begin(16, 2); //Initialise 16*2 LCD

  22.   lcd.print(" Arduino Wattmeter"); //Intro Message line 1
  23.   lcd.setCursor(0, 1);
  24.   lcd.print(" With Arduino "); //Intro Message line 2

  25.   delay(2000);
  26.   lcd.clear();

  27. }

  28. void loop() {

  29. float Voltage_Value = analogRead(Read_Voltage);
  30. float Current_Value = analogRead(Read_Current);

  31. Voltage_Value = Voltage_Value * (5.0/1023.0) * 6.46;
  32. Current_Value = Current_Value * (5.0/1023.0) * 0.239;

  33. lcd.setCursor(0, 0);
  34. lcd.print("V="); lcd.print(Voltage_Value);
  35. lcd.print(" ");
  36. lcd.print("I=");lcd.print(Current_Value);

  37. float Power_Value = Voltage_Value * Current_Value;

  38. lcd.setCursor(0, 1);
  39. lcd.print("Power="); lcd.print(Power_Value);

  40. delay(200);
  41. }

No comments:


Arduino Projects

[Arduino Projects][twocolumns]