How to measure current of arduino circuit over time

I need to write a sketch to measure how much power consumption a circuit I design will require (i.e. what mAh battery capacity I need. I need whatever battery I supply for it to last 6 months. My power requirement averages about 8mAh per day.

I just purchased a INA260 Current Power Sensor. If my circuit draws a constant current it would be a simple exercise to calculate my power requirements but it doesn't. My circuit has both an active and a power-down cycle over a 24 hour period. On top of that when it is active, it is programmed to turn on a LED and an electromagnet at random intervals.

Therefore, I would like to write a sketch that is more like a current logger over time. Is there a way that I can do this by hooking up an Arduino to the INA260 (and my circuit to the INA260) and then constantly monitoring/capturing data from my serial monitor to give me a cumulative mAh consumption of my circuit over a 24hr. period?

Any ideas would be appreciated.

thanks in advance.

investigate this sensor at the Project Hub on this site
then at the Adafruit web site

if you don't find what you need there, come back and ask well informed questions

mbiasotti:
Therefore, I would like to write a sketch that is more like a current logger over time. Is there a way that I can do this by hooking up an Arduino to the INA260 (and my circuit to the INA260) and then constantly monitoring/capturing data from my serial monitor to give me a cumulative mAh consumption of my circuit over a 24hr. period?

You want the INA260 to monitor the current when the processor is powered down ?

mbiasotti:
My power requirement averages about 8mAh per day.

The INA260 is designed for high currents, and is almost useless for measuring very small currents.
Leo..

mbiasotti:
My power requirement averages about 8mAh per day.

Sorry, I don't understand what you are asking; if you know the requirement is 8mAh per day then what do you need to measure? Just multiply 0.08 by the number of days to get the battery capacity. Don't forget that all batteries, of any chemistry, lose capacity with use. For this reason I suggest that you get a battery with double or more the capacity you calculate.

Hi PerryBebbington,

the 8mAh a day is just an average power budget I mentioned for reference to show how little power I need. The actual circuit draw is different because it has a random duty cycle - that is, the LED and electromagnet come on for approx. 1000ms once every 5 to 15 seconds. So the duty cycle is very low, but again random. So my thinking is that I need to constantly monitor the circuit's current an accumulate a total or average current in time (mAh) - somehow?

It is disappointing to hear the the INA260 is accurate at low currents... I did not know this.

I see no need (yet) to measure current.
You can measure supply/battery voltage with the Arduino itself, internally, just with code.
And keep track of how long the users (LED, solenoid) are 'on'.
That can be calculated to mAh if you know current draw of the Arduino/LED/solenoid.
Leo..

For such a low current node, I cant see it makes a lot of sense to have the node measure its own current consumption, the act of measuring will take power.

In addition, if the board is using sleep mode as suggested, then there is the power used in sleep and during power up that you cannot measure.

Wawa:
I see no need (yet) to measure current.
You can measure supply/battery voltage with the Arduino itself, internally, just with code.
And keep track of how long the users (LED, solenoid) are 'on'.
That can be calculated to mAh if you know current draw of the Arduino/LED/solenoid.
Leo..

As an extension of that idea I suggest you use your multimeter to measure the current when the Arduino only is working, when the Arduino and the LED are working and when the Arduino and the solenoid are working. Subtract the Arduino-only current to get the current for the LED and for the solenoid. With that basic information you just need to know how long the Arduino will exist in each state to have a good overall estimate of energy consumption.

...R

mbiasotti:
Hi PerryBebbington,

The 8mAh a day is just an average power budget I mentioned for reference to show how little power I need.

Is it correct, or at least close to correct? For example, is 16mAh per day definitely more than you need? It doesn't matter if the instantaneous load changes all over the place, it is the average over time that is important. If 8mAh per day is about right then that's all you need. My comment about having a bigger battery than calculated still stands.

mbiasotti:
Therefore, I would like to write a sketch that is more like a current logger over time. Is there a way that I can do this by hooking up an Arduino to the INA260 (and my circuit to the INA260) and then constantly monitoring/capturing data from my serial monitor to give me a cumulative mAh consumption of my circuit over a 24hr. period?

You only need the right current sensor or a shunt resistor and amplifier.
The shunt resistor converts the current into a voltage. Because that inevitable voltage drop should be as small as possible, an amplifier or very sensitive ADC is required - that's the well known secret behind DC current sensors.

Please consider that both Arduino circuits do not normally share the same GND level. Eventually have the second (logging) Arduino powered by another battery, just like a DMM, and wireless transmission of the results.

I second the idea of measuring with your multimeter the total system current draw at each possible state, then sum up based on the time each state exists. Even if some things are on randomly, there is presumably a maximum, and if it's really random you can assume the average time on is one-half the maximum. I think that's going to give you at least as good an answer as trying to measure it over time. The answer is going to be approximate anyway because current draw and/or battery life will vary with temperature and battery discharge state.

Thanks all for your responses. I like the idea of modifying my sketch to log when the LED and the electromagnet are triggered and measure the time that they are on and the frequency and perhaps accumulate that data thru the serial monitor. Calculating the current of the ATTINY45 is simple both when it is running and when it is in sleep mode and I have a predetermined amount of time that it is awake and when it is sleeping over a 24 hr. period.

I've learned since initially posting this how difficult it is to get accurate readings for low voltage current.

I just wish I had something like my Killawatt which, if you don't know what it is, is a 120VAC device that you plug an appliance into and it measures how many watts/hours you consume over time. This is what I had in mind for a low voltage, low current type of device for arduino.

BTW, this is a design for a consumer product that is currently being developed and we are trying to determine whether we use a solar cell and rechargeable LiFePO4 (default) or use Alkaline batteries - think Solar powered path lights. Solar cells have been hit with a 25% Tariff coming from China.

I use a USB power meter when I need to know many mAhr a project is using.

The YZXstudio ones are good.