Make an Arduino Multifunction Energy Meter
Table of Contents
ToggleIn this post, I will show you how to make an Arduino Multifunction Energy Meter. This little Meter is a very useful device that displays important information on electrical parameters. The device can measure 6 useful electrical parameters: Voltage, Current, Power, Energy, Capacity, and Temperature. This device is suitable only for DC loads such as Solar PV systems. You can also use this meter for battery capacity measurement.
The Meter can measure up to voltage range from 0 – 26V and a maximum current of 3.2A.
Supplies:
Components Used:
1. Arduino Pro Micro ( Amazon )
2. INA219 ( Amazon )
3. 0.96″ OLED ( Amazon )
4. DS18B20 ( Amazon )
5. Lipo Battery ( Amazon )
6. Screw Terminals ( Amazon )
7. Female / Male Headers ( Amazon )
8. Perforated Board ( Amazon )
9. 24 AWG Wire ( Amazon )
10. Slide Switch ( Amazon )
Tools & Instruments Used:
1. Soldering Iron ( Amazon )
2. Wire Stripper ( Amazon )
3. Multimeter ( Amazon )
4. Electrical Tester ( Amazon )
Schematic Diagram
The heart of the Energy Meter is an Arduino Pro Micro board. The Arduino senses the current and voltage by using the INA219 current sensor and temperature is sensed by temperature sensor DS18B20. According to this voltage and current, Arduino does the maths for calculating power and energy.
The Whole Schematic is divided into 4 groups
1. Arduino Pro Micro
The power required for Arduino Pro Micro is supplied from a LiPo/ Li-Ion Battery through a slide switch.
2. Current Sensor
The Current Sensor INA219 is connected to the Arduino board in I2C communication mode ( SDA and SCL pin).
3. OLED Display
Similar to the current Sensor, the OLED display is also connected to the Arduino board in the I2C communication mode. However, the address for both the device is different.
4. Temperature Sensor
Here I have used the DS18B20 temperature sensor. It uses a one-wire protocol to communicate with the Arduino.
Schematic_DIY+Arduino+Multi+Function+Power+Meter+V1.0_2020-07-13_22-00-43
Breadboard Testing
First, we will make the circuit on a Breadboard. The main advantage of a solderless breadboard is that it’s, solderless. Thus you can easily change the design just by unplugging components and leads as you need to.
After making the breadboard testing, I made the circuit on a Perforated Board.
Prepare the Arduino Board
The Arduino Pro Micro comes without soldering the headers pin. So you have to solder the headers into the Arduino first.
Insert your male headers long-side-down into a breadboard. Now, with the headers installed, you can easily drop the Arduino board into place on top of the headers pin. Then solder all the pins to the Arduino Board.
Prepare the Headers
To mount the Arduino, OLED display, current sensor, and temperature sensor, you need some female straight headers pin. When you purchase the straight headers, they’ll be too long for the components to be used. So, You’ll need to trim them down to an appropriate length. I used a nipper to trim down it.
Following are the details about the headers :
1. Arduino Board – 2 x 12 pins
2. INA219 – 1 x 6 pins
3. OLED – 1 x 4 pins
4. Temp. Sensor – 1 x 3 pins
Solder the Female Headers
After preparing the female headers pin, solder them to the perforated board. After soldering the header pins, check whether all the components fit perfectly or not.
Note: I will recommend solder the current sensor directly to the board instead of through the female header.
I have connected through the header pin for reusing the INA219 for other projects.
Mount the Temperature Sensor
Here I am using the DS18B20 temperature sensor in the TO-92 package. By considering the easy replacement, I have used a 3 pin female header. But you can directly solder the sensor to the perforated board.
Solder the Screw Terminals
Here screw terminals are used for external connection to the board. The external connections are
1. Source ( Battery / Solar Panel )
2. Load
3. Power supply to Arduino
The blue screw terminal is used for the power supply to the Arduino and two green terminals are used for source and load connection.
Make the Circuit
After soldering the female headers and screw terminals, you have to join the pads as per the schematic diagram shown above.
The connections are pretty straight forward
INA219 / OLED -> Arduino
VCC -> VCC
GND – > GND
SDA -> D2
SCL-> D3
DS18B20 -> Arduino
GND – > GND
DQ -> D4 through a 4.7K pull-up resistor
VCC -> VCC
At last, connect the screw terminals as per the schematic.
I have used 24AWG colored wires to make the circuit. Solder the wire as per the circuit diagram.
Mounting the Standoffs
After soldering and wiring, mount the standoffs at 4 corners. It will provide sufficient clearance to the soldering joints and wires from the ground.
PCB Design
I have designed a custom PCB for this project. Due to the current pandemic COVID-19 situation, I am not able to place an order for this PCB. So I have not tested the PCB yet.
You can download the Gerber files from PCBWay
When you place an order from PCBWay, I will get a 10% donation from PCBWay for a contribution to my work. Your little help may encourage me to do more awesome work in the future. Thank you for your cooperation.
Power and Energy
Power: Power is the product of voltage (volt) and current (Amp)
P=VxI
Unit of power is Watt or KW
Energy: Energy is the product of power (watt) and time (Hour)
E= Pxt
Unit of Energy is Watt Hour or Kilowatt Hour (kWh)
Capacity: Capacity is the product of Current (Amp) and time (Hour)
C = I x t
Unit of capacity is Amp-Hour
To monitor the power and energy above logic is implemented in software and the parameters are displayed in a 0.96-inch OLED display.
Software and Libraries
First, download the code attached below. Then download the following libraries and install them.
After installation, all the libraries, set the correct board and COM port, then upload the code.
Arduino code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
// Arduino Multi Function Energy Meter V1.0 // Required Libraries // https://github.com/adafruit/Adafruit_INA219 // https://github.com/adafruit/Adafruit_SSD1306 // Credit : GreatScott #include <Wire.h> #include <Adafruit_INA219.h> #include <Adafruit_SSD1306.h> #include <OneWire.h> #include <DallasTemperature.h> Adafruit_INA219 ina219; #define OLED_RESET 4 Adafruit_SSD1306 display(OLED_RESET); // Data wire is plugged into digital pin 2 on the Arduino #define ONE_WIRE_BUS 4 // Setup a oneWire instance to communicate with any OneWire device OneWire oneWire(ONE_WIRE_BUS); // Pass oneWire reference to DallasTemperature library DallasTemperature sensors(&oneWire); float shuntvoltage = 0; float busvoltage = 0; float loadvoltage = 0; float current_mA = 0; float power_mW = 0; unsigned long previousMillis = 0; unsigned long interval = 100; float energy = 0; float capacity=0; float temp=0; void setup() { // initialize ina219 with default measurement range of 32V, 2A ina219.begin(); // Serial.begin(9600); // ina219.setCalibration_32V_2A(); // set measurement range to 32V, 2A (do not exceed 26V!) // ina219.setCalibration_32V_1A(); // set measurement range to 32V, 1A (do not exceed 26V!) // ina219.setCalibration_16V_400mA(); // set measurement range to 16V, 400mA sensors.begin(); // initialize OLED display display.begin(SSD1306_SWITCHCAPVCC, 0x3C); display.clearDisplay(); display.setTextColor(WHITE); display.setTextSize(1); display.display(); } void loop() { unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; read_sensor_data(); display_data(); } } void read_sensor_data(){ shuntvoltage = ina219.getShuntVoltage_mV(); busvoltage = ina219.getBusVoltage_V(); current_mA = ina219.getCurrent_mA(); if( current_mA <0) { current_mA=0; } sensors.requestTemperatures(); // get temperatures loadvoltage = busvoltage + (shuntvoltage / 1000); power_mW = loadvoltage*current_mA; capacity = current_mA / 3600; energy = energy + loadvoltage * current_mA / 3600; } void display_data(){ // show data on OLED display.clearDisplay(); display.setCursor(0, 0); display.print(busvoltage-0.08); display.print(" V"); // Serial.print("Bus Voltage: "); Serial.print(busvoltage); // Serial.println(" V"); display.setCursor(0, 10); display.print(current_mA); display.print(" mA"); // Serial.print("Current: "); Serial.print(current_mA); // Serial.println(" mA"); display.setCursor(0, 20); display.print(power_mW); display.print(" mW"); // Serial.print("Power: "); Serial.print(power_mW); //Serial.println(" mW"); display.setCursor(65,0); display.print(energy); display.println(" mWh"); // Serial.print("Energy: "); Serial.print(energy); //Serial.println(" mWh"); display.setCursor(65,10); display.print(capacity); display.println(" mAh"); // Serial.print("Capacity: "); Serial.print(capacity); //Serial.println(" mAh"); display.setCursor(65,20); display.print(sensors.getTempCByIndex(0)); display.println(" C"); // Serial.print("Temperature: "); //Serial.print(sensors.getTempCByIndex(0));Serial.print(" C"); // Serial.println(""); display.display(); } |
Final Testing
To test the board, I have connected a 12V battery as a source and a 3W LED as a load.
The battery is connected to the screw terminal below the Arduino and LED is connected to the screw terminal below the INA219. The LiPo battery is connected to the blue screw terminal and then switch ON the circuit by using the slide switch.
You can see all the parameters are displaying on the OLED screen.
The parameters in the first column are
1. Voltage
2. Current
3. Power
The parameters in the second column are
1. Energy
2. Capacity
3. Temperature
To check the accuracy I used my multimeter and a Tester as shown above. The accuracy is close to them. I am really satisfied with this pocket-sized gadget.
Thanks for reading my Instructable.
If you like my project, don’t forget to share it. Comments and feedback are always welcome.