DC motor current measurement

I need a help for the connection of ACS712 sensor to measure current of dc motor and L298N module, Arduino UNO

Get a ACS712 breakout board and connect it to GND, VCC and any analog input.

Hint: modern motor driver boards have integrated current measurement feature.

Thank you for the suggestion

My diagram shows the generic ACS712 breakout board

Thank you so much, as i got confused earlier. But know its clear
i am using this breakout board

Thank you so much once again, really appreciated :smiley:

Also one more thing, can you please verify my code, if any changes is required?

const int ACS712_PIN = A0;
const float ACS712_SENSITIVITY = 0.185;

void setup() {
Serial.begin(9600);
}

void loop() {
int sensorValue = analogRead(ACS712_PIN);
float voltage = sensorValue * (5.0 / 1023.0);
float current = voltage / ACS712_SENSITIVITY;

Serial.print("Current: ");
Serial.print(current, 2);
Serial.println(" A");

delay(1000); }

this is only for current measurement


const int ACS712_PIN = A0;
const float ACS712_SENSITIVITY = 0.185;
int sensorValue;

void setup() {
  Serial.begin(9600);
  sensorValue = analogRead(ACS712_PIN); // dummy read
}

void loop() {
  // Read it twice and take the average (divide by 2)
  sensorValue = analogRead(ACS712_PIN);
  sensorValue = sensorValue + analogRead(ACS712_PIN);
  sensorValue = sensorValue - 1024; // Subtract out the midpoint (512 x 2)
  float voltage = sensorValue * (5.0 / 2048.0); // (5.0 / 1024.0) / 2.0
  float current = voltage / ACS712_SENSITIVITY;

  Serial.print("Current: ");
  Serial.print(current, 2);
  Serial.println(" A");

  delay(1000);
}

Does not work if PWM is used

Okay.
I have to use PWM for the motor, so what can i do next, if this is not applicable

You can still use the ACS712 but the software becomes somewhat complicated.
It might make more sense to use a different driver with a current monitor output.
What motor are you using?

It is 12V brush motor with encoder

You will need to build a little filter circuit like this

You will need two 3.3K ohm resisors and two 1uF capacitors.

Okay, Understood.
do the code described above needs any changes?

No.
FYI: The current can be positive or negative depending on the motor direction

Noted!

I have found this thread useful. I have been contemplating using an Arduino or Nano to measure DC current across the rails (ie presence of a motor) of a model railway to be able to activate signals. All I need to detect current.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.