ATtinyPowerMeter

23K17273

Intro: 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".

54 Comments

Hi , could you please tell me is there any way to make this project suitable for ATtiny88 ???
Not tried, but should be suitable.
Good morning,
Very nice job still bravo!
In yours knowledge can they augment brightness on ssd1306 so yes how to make svp?
I think I have missed something. The ATtiny has several analogue inputs, why not use those to measure the power?
Obviously that would make the code more difficult, and that may be reason enough, but if we are trying to minimise power consumption, then why use two chips when one will do?
ATtiny itself hard to measure current accurately.
Ah yes, I'd muddled my units: with a 0.1 ohm shunt, it's only good down to about 10mA, yours will do 0.1mA.
Silly me. :?
Hello ! Thank you for your development, very good design. Please help me change the measurement range to 24 Volts and 3.2 Amps. I could not get. :(
the latest source code will auto step up to high value mode if detected value overflow.

I like very much the nice project.

One point - I need to setup the system with 2 INA219 - how can I ad INA219 I2C addresses to the sketch / h files?

The library I am using is tailor-made for ATtiny85, the compiled size is just fit for 8K flash. I am afraid ATtiny may not capable adding code for controlling 2 INA219. If you are using normal Arduino (ATMEGA), you can try Adafruit INA219 library.

Thank you very much for replying.

I am looking for the very nice solution of ATtiny85 and 2 x INA219 for a monitor for a powersupply 0 -> +/- 12 V dc.

monitor for the current in each line (positive and negative) and voltage monitor.

Monitoring on OLED 1306 display.

Your tailor made project supports all but one more INA219.

Therefore I hoped for a changed / updated tailor made INA219 lib for addressing 2 INA219.

Do you have any plans to make this possible in the future?

can you talk more about your use case?

Yes of course.

The application:

A DC powersupply delivering 0 to 12V positive and negative with a common ground. This is for my daily work developing small modules for my own test equipment.

I woild like to be able to monitor the current in the positive part of the powersupply and the negative part of the power supply.

I also like to monitor the output voltage.

All of this can be done with two INA219. Actually I have the system running now on Arduino UNO. everything is fully working as I intend.

I also have your application running with one INA219 and ATtiny85 - great.

But it would be an elegant solution with two INA219 and ATtiny85. This could be a very nice little monitor module. :)

ok, I think INA3221 can do the job

Ok, yes - I actually allready ordered the INA3221 but I have not received it yet. So the INA3221 only needs one I2C address? and if yes - your drivers for ATtiny85 can be used?

I found this information re. INA3221:

"That module doesn't bring out the 3 pairs of sense pins separately, it cannot be used as a high-side
current sensor, only low-side. Ground is used as the return for all channels."

And the INA3221 is not possible for my project. (sad :( )

Solved !

I have solved the challange.

ATtiny85 - OLED 64x128 (1306 display) - 2xINA219

I have used the Tiny4kOLED and TinyWireM libraries.

ATtiny85 storage use: 6985b / 85% - 145b / 28%

Good to see that! Waiting for your instructables!
Hello classicaudio, could you shortly explain how did you solved the issue with 2 x ina219? I'm also interested in such a solution. Did you also use the plot function from the author? If yes, how did you managed the data output of both ina219 channels to the display? Nevertheless, I like the project from the author a very nice diy project, well done! Regards
Could you explain how to modify the code to change the number of samples averaged together? Thank you for this tutorial.
More Comments