ATtinyPowerMeter

5,574

119

30

Posted

Introduction: ATtinyPowerMeter

This instructables show how to make a simple power meter using 3 components: ATtiny85, INA219 and OLED module.

It can continuous measure the voltage(V), current(mA) and accumulated power usage(mWh). And also plot a simple graph to visualise the figures.

Step 1: Why?

While developing IoT device, power consumption does matter, especially if it cannot wired. A simple multi-meter is not enough for continuous monitoring the voltage and current at the same time. And also the accumulated power consumption (mWh) is very important for deciding how big a battery required in the IoT project.

So I use the components in hand to create this ATtinyPowerMeter.

Step 2: Preparation

The power meter should not drain too much power itself, it is the major criteria to choose the components:

MCU

ATtiny85 only draw less than 1 mA while running at 1 MHz and 8 KB program flash can well fit a power meter program.

Power Monitor Module

INA219 module is the only module I can found that can monitor voltage and current at the same time (leave comment to me if you known other modules). It draws around 1 mA power.

Display Module

SSD1306 OLED display module drain few mA for display, it is the major power consumption. It should be better if using mono LCD display, but I only have this I2C display module in hand, so I will use it this time.

Battery

According to the data sheet, the above 3 components can operate at 3 V to 5.5 V, 2 rechargeable AAA battery is not enough, 3 AAA battery is better, 1 Lipo battery also ok. But in this project I am testing a new type battery, Lithium iron phosphate (LiFePO4 or LFP) battery. It is the same as AAA battery in size, but can provide 3.2 V 600 mAh. It should be good enough for most electronic project but I am still testing it.

Others

A 380 hole breadboard, some breadboard wire, a breadboard friendly battery holder, a 3 pins screw terminal block and a switch. And also a ISP for programming the ATtiny85.

Step 3: Download Source Code

Download source from GitHub:

https://github.com/moononournation/ATtinyPowerMete...

If you are not familiar GitHub, simple press "Clone or download" button and then "Download ZIP".

Step 4: Program ATtiny85

Step 5: Circuit Design

Here is the connection summary:

Battery +ve -> switch -> ATtiny85 pin 8, INA219 module Vcc, OLED module Vcc
Battery -ve -> ATtiny85 pin 4, INA219 module GND, OLED module GND, screw terminal block middle pin
ATtiny85 pin 5 -> INA219 module SDA, OLED module SDA
ATtiny85 pin 7 -> INA219 module SCL, OLED module SCL
INA219 module Vin- -> screw terminal block left pin
INA219 module Vin+ -> screw terminal block right pin

Step 6: Testing

  1. Turn on the switch, you should see V and mA figure is 0.
  2. Connect testing power source +ve and -ve to screw terminal right pin and middle pin respectively, you should see V figure become the power source Voltage value and mA still 0
  3. Connect testing loading device +ve and -ve to screw terminal left pin and middle pin respectively, you should see mA figure become the loading device drawing current value

Step 7: Self Test

You want to know how much power draining this power meter itself? In my measurement it draws around 3 - 6 mA, just for your reference.

Step 8: Happing Measuring!

It is the time to design and testing your device power consumption now!

P.S. My source code configured measure maximum 16V and 800 mA, you may change the configuration at "INA219.h".

Share

Recommendations

  • Spotless Contest

    Spotless Contest
  • Science of Cooking

    Science of Cooking
  • Microcontroller Contest

    Microcontroller Contest
user

We have a be nice policy.
Please be positive and constructive.

Tips

Questions

25 Comments

Hi moononournation,

Is there any documentation to adding/modifying a font to the ssd1306 library? Is this your fork of an earlier DigisparkOLED Library? At this stage I just want o add a period to font_2x.h (so I expect I need a slash as well).

Thanks, Nic

good to see that ;>

Thanks, I found that a few hours ago. It looks like the "convert" script in the instructable does not output the array that's in the "font_2x.h" file. Can you confirm the -flip and -rotate switches are still necessary for the output used in "font_2x.h"?

I do not remember I have changed the parameters, what is your testing result?

Extremely garbled output. I cannot make out any discernible characters with variations with switches on or off. That is even printing a single digit 0, with no extra characters added to the array.

good to see that ;)

How to change the maximum current limit. ( can you please specify)

you can change the maximum current limit by setting the Calibration Register (address = 05h).

Calibration value = 0.04096 / CURRENT_LSB / 0.1

CURRENT_LSB = maximum current limit / 2^15

You may refer to Data Sheet Page 12 Chapter 8.5.1 and Page 25 Figure 27 for more details.

If i need current limit of 3 amps?