I want to measure the current of the motor for that i have this INA219 breakout board(module) and i want to collect the current of the brushed dc motor.
i have followed this connections, but values i am getting in serial monitor is not understandable.
Please help me with this
#include <Wire.h>
#include <Adafruit_INA219.h>
#define INA219_ADDRESS (0x40)
Adafruit_INA219 ina219;
const int ENA_PIN = 9;
const int IN1_PIN = 11;
const int IN2_PIN = 12;
void setup() {
Serial.begin(9600);
// Initialize INA219 sensor
ina219.begin(INA219_ADDRESS);
ina219.setCalibration_32V_1A();
// Set motor control pins as outputs
pinMode(ENA_PIN, OUTPUT);
pinMode(IN1_PIN, OUTPUT);
pinMode(IN2_PIN, OUTPUT);
}
void loop() {
// Set PWM speed and direction for the motor
int inputPWM = 150; // Example PWM value (adjust as needed, 0-255)
// Set motor direction and speed
analogWrite(ENA_PIN, inputPWM);
digitalWrite(IN1_PIN, HIGH);
digitalWrite(IN2_PIN, LOW);
// Read current from INA219
float current_mA = ina219.getCurrent_mA();
Serial.print("Current: ");
Serial.print(current_mA);
Serial.println(" mA");
// Delay for stability and to see the output
delay(1000);
}
when i am changing the delay to 1ms, then only i am able to see some values, for slower sampling rate, i see no response. Also the values are fluctuating. for the same pwm and without load