0

enter image description hereI Have been working on a power logger with INA219 and L298N the thing is, the voltage and current displayed on Serial Monitor is not the same on my multimeter. the Arduino is connected to the pc to view the result on the serial

#include <Wire.h>
#include <Adafruit_INA219.h>

Adafruit_INA219 ina219;


//Adafruit_INA219 ina219_A;
//Adafruit_INA219 ina219_B(0x41);

void setup(void) 
{
  Serial.begin(115200);
  while (!Serial) {
      // will pause Zero, Leonardo, etc until serial console opens
      delay(1);
  }

  uint32_t currentFrequency;
    
  Serial.println("Hello!");
 
  if (! ina219.begin()) {
    Serial.println("Failed to find INA219 chip");
    while (1) { delay(10); }
  }
  ina219.setCalibration_32V_1A();

  Serial.println("Measuring voltage and current with INA219 ...");
}

void data(void) 
{
  float shuntvoltage = 0;
  float busvoltage = 0;
  float current_mA = 0;
  float loadvoltage = 0;
  float power_mW = 0;
    delay(2000);
  shuntvoltage = ina219.getShuntVoltage_mV();
  busvoltage = ina219.getBusVoltage_V();
  current_mA = ina219.getCurrent_mA();
  power_mW = ina219.getPower_mW();
  loadvoltage = busvoltage + (shuntvoltage / 1000);
  
  Serial.print("Bus Voltage:   "); Serial.print(busvoltage); Serial.println(" V");
  Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV");
  Serial.print("Load Voltage:  "); Serial.print(loadvoltage); Serial.println(" V");
  Serial.print("Current:       "); Serial.print(current_mA); Serial.println(" mA");
  Serial.print("Power:         "); Serial.print(power_mW); Serial.println(" mW");
  Serial.println("");

  delay(2000);
}

void loop() {

    analogWrite(9, 245); //ENA pin
    digitalWrite(8, HIGH);
    digitalWrite(7, LOW);
    data();
    delay(5000);
  
    analogWrite(9, 200); //ENA pin
    digitalWrite(8, HIGH);
    digitalWrite(7, LOW);
    data();
    delay(5000);
  
    analogWrite(9, 150); //ENA pin
    digitalWrite(8, HIGH);
    digitalWrite(7, LOW);
    data();
    delay(5000);
  
    analogWrite(9, 0); //ENA pin
    digitalWrite(8, LOW);
    digitalWrite(7, LOW);
    data();
    delay(5000);

}
1
  • not the same on my multimeter What sort of difference are you seeing? – timemage Jan 22 at 16:07
0

The INA219 gives you the instantaneous current and voltage at a given moment in time, whereas your DMM shows you the average over a period.

The L298N is giving out a PWM waveform that is rapidly being turned on and off.

You see where this is going?

Your Arduino detection will be giving you either full power or no power (or somewhere in between owing to the low-pass filter effect of the motor), pretty much randomly, whereas the DMM will give you the average over a number of samples.

You would need to rapidly sample the PWM signal over a period of time and calculate the average to get an idea of what the current and voltage might be.

3
  • Thank you sir, but do you think there is something wrong with the connection or i will just add code for DMM somewhere? – Rhu Pagal Jan 22 at 11:27
  • You need to add code to create an average over time of the values. – Majenko Jan 22 at 12:01
  • Unless I missed something, I didn't see where the control pins (7,8,9) were initialized properly. There should be some 'pinMode()' statements in setup(). Am I missing something? – user3765883 Feb 22 at 1:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.