Make Your Own Power Meter/Logger

100,862

538

67

Introduction: Make Your Own Power Meter/Logger

About: Awesome Electronics Tutorials, Projects and How To´s

In this project I will show you how I combined an Arduino, an INA219 power monitor IC, an OLED LCD and a Micro SD Card PCB in order to create a power meter/logger that has more functions than the popular USB Power Meter. Let's get started!

Step 1: Watch the Video!

The video gives you a good overview on how to create your own power meter. In the next steps though I will present you some additional information to make this project even simpler.

Step 2: Order Your Parts!

Step 3: Create the Circuit!

Here you can find the schematic for the Arduino Nano version and the portable version of this project. You can also find those schematic on the EasyEDA website:

https://easyeda.com/GreatScott/PowerMeter-b6051723...

https://easyeda.com/GreatScott/PortablePowerMeter-...

You can also use the pictures of my finished board as a reference for your own.

Step 4: Upload the Code!

Now that your circuit is complete, it is time to upload the code. You can download it here. But don't forget to download and include the following libraries before uploading:

https://github.com/adafruit/Adafruit_INA219

https://github.com/adafruit/Adafruit_SSD1306

https://github.com/greiman/SdFat

Step 5: Success!

You did it! You just created your own Power Meter/Logger


Feel free to check out my YouTube channel for more awesome projects:

http://www.youtube.com/user/greatscottlab

You can also follow me on Facebook, Twitter and Google+ for news about upcoming projects and behind the scenes information:

https://twitter.com/GreatScottLab

https://www.facebook.com/greatscottlab

7 People Made This Project!

Recommendations

  • Puzzles Speed Challenge

    Puzzles Speed Challenge
  • "Can't Touch This" Family Contest

    "Can't Touch This" Family Contest
  • CNC Contest 2020

    CNC Contest 2020

67 Discussions

0
AlrickH
AlrickH

Question 2 years ago

hi, congrats and thanks for a great video. I want to make a similar project but i need to monitor more current like upto 24 volts and 21 Apms.......what you suggest i do, or replace in the your given circuit? Hope to get a quick reply.

0
DerekB103
DerekB103

Answer 1 year ago

You can modify the INA219 to measure current greater than 3.2 amps. You need to change the sense resistor value. You can Google 'change current measurement of INA219'.

0
SławomirS
SławomirS

Reply 3 days ago

Hi, how about changing voltage up to 54V?

0
utamadonny10
utamadonny10

Question 9 months ago

ive question

shuntvoltage = ina219.getShuntVoltage_mV();
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
loadvoltage = busvoltage + (shuntvoltage / 1000);
energy = energy + loadvoltage * current_mA / 3600;

why shuntvoltage divide by 1000 dan curren_mA is divided by 3600??

0
waltsfo
waltsfo

Answer 7 months ago

Dividing mV by 1,000 gives volts.
Dividing seconds by 3600 (60x60) gives hours.

0
hm010120
hm010120

Reply 5 months ago

Hello,
this is a great project! I just reviewed it and I have a quick question about the calculation for the energy. In my understanding, the calculation of the energy is not 100% correct as the time interval is missing. I would propose for the calculation of the energy --> energy = energy + loadvoltage * interval * current_mA / 3600.

What is your opinion about that?
Regards

0
JohnT184
JohnT184

Reply 7 weeks ago

I agree that is what I thought. If the formula was called every second it would be correct. However the interval is 100ms which is 10 times a second!

This was my formula which can be rearranged but I found it easier to follow in it's current format.

energy = energy + (power / (3600 * (1000/interval)));

1
mlhanes
mlhanes

Question 1 year ago on Introduction

Can this project be used to monitor a larger piece of equipment like for instance a copier?

0
bassbindevil
bassbindevil

Answer 3 months ago

Old question... but if you want to monitor something that runs on mains AC voltage, it would be much safer to buy an energy monitor like a Kill-A-Watt or a no-name equivalent. $10 and up on eBay for a plug-in style monitor. Around $20 for a panel mount unit that'll handle up to 100A. Just search for energy monitor.

1
aoti100
aoti100

Question 5 months ago on Step 2

Great project indeed - I write to have support to solve an issue - I have done circuit and develop code according example. All is working up I do not use the library SdFat.h. Basically I can have the meter and OLED working without the SD part in the program. When I introduce SD part all is load in Arduino but OLED screen freeze or show black in particular if I active command SdFat SD. Seems and issue of memory but when compiling program give 77% program memory free and 59% for dynamic variables free and seems not the case. Attached also my sketch. I am using last library available from Arduino IDE.

Adafruit GFX Library 1.7.5
Adafruit INA219 1.0.6
Adafruit SSD1306 2.2.0
SdFat - Adafruit Fork 1.2.3


Thanks for help Regards Alex


===========================================================

#include // Serial Peripheral Interface comunication SD reader writer module
#include // Wire bus comunication I2C on SCL SDA display SD1306 and Ina219
#include // Display SSD1306 library
#include // Display shape library
#include // INA219 board library current voltage reader
#include //SD comunication library

#define SCREEN_WIDTH 128 // OLED display width in pixels
#define SCREEN_HEIGHT 64 // OLED display height in pixels
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
#define ROTATION 0

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_INA219 ina219;

unsigned long previousMillis = 0;
unsigned long interval = 100;
const int chipSelect = 10;

float shuntvoltage = 0;
float busvoltage = 0;
float current_mA = 0;
float loadvoltage = 0;
float power_mW = 0;
float energy = 0;

SdFat SD;

File TimeFile;
File VoltFile;
File CurrentFile;


void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay(); // Clear the display
display.display(); // Flushes all changes to the display hardware
display.setRotation(ROTATION); // Set Rotation
display.setTextSize(1); // Set text size
display.setTextColor(WHITE);

delay(2000);

ina219.begin();
SD.begin(chipSelect);
}

void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval)
{ previousMillis = currentMillis;

ina219values(); //subroutines reading
displaydata(); //subroutines display

// Write on files - Time - Volt - Current

TimeFile = SD.open("Time.txt", FILE_WRITE);
if (TimeFile) {
TimeFile.println(currentMillis);
TimeFile.close();
}

VoltFile = SD.open("Volt.txt", FILE_WRITE);
if (VoltFile) {
VoltFile.println(loadvoltage);
VoltFile.close();
}

CurrentFile = SD.open("Current.txt", FILE_WRITE);
if (CurrentFile) {
CurrentFile.println(current_mA);
CurrentFile.close();
}
}
}


void ina219values()
{
shuntvoltage = ina219.getShuntVoltage_mV(); // V across shunt V+ and V-
busvoltage = ina219.getBusVoltage_V(); // V across V- and Gnd
current_mA = ina219.getCurrent_mA(); // I across the shunt
loadvoltage = busvoltage + (shuntvoltage / 1000);
power_mW = ina219.getPower_mW();

energy = energy + loadvoltage * current_mA / 3600;
}


void displaydata() {
display.clearDisplay();

display.setCursor(0, 0);
display.println("Voltage:");
display.setCursor(60, 0);
display.println(loadvoltage);
display.setCursor(100, 0);
display.println("V");

display.setCursor(0, 10);
display.println("Current:");
display.setCursor(60, 10);
display.println(current_mA);
display.setCursor(100, 10);
display.println("mA");

display.setCursor(0, 20);
display.println("Power:");
display.setCursor(60, 20);
display.println(loadvoltage * current_mA);
display.setCursor(100, 20);
display.println("mW");

display.setCursor(0, 30);
display.println("Energy:");
display.setCursor(60, 30);
display.println(energy);
display.setCursor(100, 30);
display.println("mWh");

display.display();
}

IMG_1995-new.jpg
0
Craig12345
Craig12345

Answer 3 months ago

Alex, I too had memory problems with my 128X64 OLED. I stumbled on a fix that worked: in library file Adafruit_SSD1306.h, selecting "#define SSD1306_128_32" instead of the "#define SSD1306_128_64" seemed to work. (Select by commenting one and uncommenting the other.) Be aware that you may have multiple *.h files. The problem may be because the memory requirements of the *64 font outstrip the memory allocation for the OLED. Changing to the *32 font definition results in a dimmer display as it appears that every other row of pixels are not lighted. That would make sense in that I have a 64 pixel device but using the "define" command for a 32 pixel device. I noticed that you also modified some of the original code and defined SCREEN_WIDTH and SCREEN_HEIGHT, probably to match your 128X64 device. I'm no expert, but that may override the default definitions in the Adafruit_SSD1306.h file. Maybe it would be better to stick closer to the original code. I spent 3 days on this problem and thought I better write this down for others and for my own record.

0
aoti100
aoti100

Reply 3 months ago

Dear Craig, thanks a lot for input I will check in this week end and test with your suggestion and let know. I tested alredy many things with no success up to know. Even if I copy and paste the original GrateScott code project do not work. Thanks again for kindness to reply. BR Alex

1
BelenH2
BelenH2

2 years ago

Hello Scott

Sorry but I do not know how you manage to power a 5V Arduino with a 3.7 lipo battery. There should be a boost coverter in the middle right?
Thanks for all your support

0
mikegleasonjr
mikegleasonjr

Reply 2 years ago

The battery, when full, is giving 4.2v I think, I read in the video's comments that Scott is directly powering the Arduino with it.

0
masterleo
masterleo

Reply 5 months ago

There is a deep discharge protection. That is mendatory. The rest isn't

2
Kin97
Kin97

Question 2 years ago on Step 1

How accurate is this? Or the minimum watt measured by it?

0
masterleo
masterleo

Answer 5 months ago

Good question !!!!

0
soundmagic2016
soundmagic2016

Question 9 months ago

Hi GreatScott,

Do you make this board for some one like me who would pay you?
If its possible could you make a quote of line
Thank you for any input or answer

0
masterleo
masterleo

Answer 5 months ago

Please feel free to tell me your best price ! Sending from France.

0
kevinbeninca
kevinbeninca

Question 7 months ago

I made the circuit all working but I just changed the SD FAT library for the SD arduino IDE itself but when I put the card in the reader it does not write the information just creates the 3 files