Electrical – Measure the power consumption of a circuit with Arduino

arduinopowerpower-consumption

I need to measure the power consumption of a circuit I have built.
The components are as follow:

  • Lipo battery 500mAh
  • Accelerometer
  • RTC
  • RedBear Nano 2

Usually I measure the consumption using an Arduino and its analogical pin. The level of accuracy is enough. In this case my idea is to attach to every component a relatively small resistor and see which is the voltage of this resistors. Comparing this values to the battery voltage I should get an idea of how much power consumption I have. Is that correct, am I missing something?

enter image description here

The picture shows the configuration I wanna make, the green annotation represents the measures I will take with an Arduino.

The Arduino code I am using for a single analog pin is the following:

int Re = 1000;    

void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
float voltage = sensorValue * (5.0 / 1023.0);
float current = voltage / Re;
Serial.print(millis());
Serial.print(",");
Serial.print(voltage, 10);
Serial.print(",");
Serial.println(current, 10);
delay(500);
}

EDIT:
What I am trying to measure is basically how much time my circuit can be on. Thus, let say that 2 or 3 days of variance in the result can be manageable.

Best Answer

You'll get very poor results using this methodology.

  1. Since you are sensing current in the low side the signal you create will subtract from the sensor/MCU Vdd.
  2. The signal you develop across the sense resistor is in series with any signals between the sensors and the MCU ...for example the I2C interface.
  3. The Vdd for the sensors and MCU will vary because of the signal developed across your sense resistor so measuring the battery voltage is inaccurate.

I'd suggest if you're using a separate MCU for the power measurements that you use an INA219 or its three channel variant the INA3221 to measure the currents using a high side sense resistor.

There are breakout boards readily available on Ebay/Adafruit, and you can easily modify the sense resistor(s) to measure much lower currents.

enter image description here

If all you want is an estimation of the battery lifetime, then you don't need to measure each individual portion of your project.
You could use a single high side sense resistor and an op-amp or better still an INA169 to feed you ADC.
You could even use a sensitive multimeter and a large filter cap on the Vdd to measure the current (and use a power supply instead of the battery so you can increase the voltage). This would allow you to make an estimation.

If all you have is an Arduino Nano and some resistors (from your comment), then the only way to get any worthwhile result is to program the ADC to use the Internal 1.1V reference. This at least will give you a better range on the ADC.
Refer to the Nano schematic and the ATMega328p datasheet, section 28.