Detecting When a DC Motor Stalls

Hi! I'm working on a project that essentially controls a DC motor and only stops once the motor has exceeded a certain angle to which it then stalls. I know limit switches and DC motors with encoders exist, but those aren't ideal (at least how I'm working on the project). I had bought one of these ACS712 current sensor modules believing they'd be able to show any difference when a DC motor stalls:


unfortunately, nothing really came out of using these (probably should've done more research regarding them). Anyway, is there any other simple approach to detecting when a DC motor stalls? I really just want to detect when a motor stalls like the following:

while(analogRead(SENSOR_PIN) <= someNormalCurrentVal);
// DC motor has stalled, now execute code to stop DC motor

Many thanks! : )

EDIT:

Components in use:

  • 5A version of the ACS712
  • L298N motor driver
  • 12V DC motor
  • Arduino Nano

Here's a simple piece of code for what I'm trying to do:

// ---- MACROS/PINS ----
#define ENA        3
#define IN1        4
#define IN2        5
#define SENSOR_PIN A0

// ---- FUNCTIONS ----
void setup(){
  pinMode(ENA, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(SENSOR_PIN, INPUT);
  
  analogWrite(ENA, 255);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);

  while(analogRead(SENSOR_PIN) <= someVal); // Repeat until DC motor stalls
  digitalWrite(IN1, LOW); // DC motor stops
}

void loop(){}

Here's how I have the ACS712 connected:

When a DC motor stalls, the current rises to its maximum value.

I don't know why your current sensor was unable to detect this. You haven't provided enough details.

Some motor driver modules/chips can detect the motor current and allow the Arduino to measure it with an analog input.

1 Like

To answer your question we need to know which current sensor you have. We also need to know more about your DC motor and powersupply.

My off hand thought is your current sensor may be designed for very high currents and you DC stall current is too low to be read. OR the sensor is not connected correctly.

1 Like

Unfortunately, DC motors briefly draw the full stall current every time they start moving. In my experience, 10 milliseconds is the typical duration of the startup current surge.

2 Likes

There are three versions of the ACS712, 5, 20 and 30 Amp, which one are you using?
What is the motor's full load (not stalled) current?

1 Like

The stall current will vary over time because the brushes and the armature both wear and the armature copper oxidizes.

1 Like

What does this statement say?
When the sensor pin value (motor current) is LOWER THAN OR EQUAL TO the normal current then DC motor is stalled?
Is it?

Shouldn't it be;
When the sensor pin value (motor current) is GREATER THAN the normal current then DC motor is stalled?

Can you please post your complete test code?
Did you put Serial.print statements in your code to help debug your code?

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

What model Arduino are you using?

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

HI Sorry for the late reply, I've since provided more details. : )

Hi! Sorry for the late reply, I'm using the 5A version, some more details are provided above, along with the values when the DC motor is stalled and not stalled. : )

Hi! More information has been posted above, including the components, in use as well as some sample code. : )

According to the Arduino Reference, analogRead will always return a value between 0 and 1023. So the above condition is always true. So your while loop will never end.

And, what is this for?

I don't know that was the max value. I just put that value as a placeholder based on the values I was getting. But thanks for letting me know! : )

Oh, that's simply there to control the DC motor's speed.

Hi,
Please when adding new information, do it in a NEW post, that way the flow of the thread will be logical.
Adding at the start makes all the following requests for information look out of place.

If you have updated your code, please post it in a new post.

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

I think your approach is all wrong. After allowing for the start up current surge, you need to rapidly read and AVERAGE the current. When the average suddenly peaks, then the motor is truly stalled. otherwise the current pulses that occur as the armature turns from segment to segment will give false readings if a reading happens to find the moment where current is going to two windings at the same time.

You have not posted a diagram showing your connections, but I suspect you cannot control the motor's speed using SENSOR_PIN (A0).

Oh wait I just realized that my apologies, that was supposed to be "ENA" haha, thanks for pointing that out! : )

Interesting, I did see some people mention this in regards to using this device but I wasn't sure if it related to what I was doing, but now that you mention it it does sound like something I should've been checking. I'll definitely look into this! : )

Hi! I posted this problem a while ago, and I got my Arduino Nano to detect when my DC motor stalls using an ACS712; however, it doesn't always work (i.e. it sometimes stops even though the motor hasn't actually been stopped). Which gives me the feeling that there's a proper way to do it. As such, I'm here to ask if there is, in fact, a better way to detect when a DC motor stalls using an ACS712 based on my approach. Thanks in advance! : )

Circuit components:

  • 5A ACS712
  • 3-12V DC motor
  • Arduino Nano
  • L298N motor drive controller

Additional info:

  • DC motor current with no load = ~520 mA
  • DC motor current with load = ~577 mA

Code:

// ---- MACROS/PINS ----
#define ENA        3
#define IN1        4
#define IN2        5
#define SENSOR_PIN A0

// ---- FUNCTIONS ----
void setup(){
  pinMode(ENA, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(SENSOR_PIN, INPUT);

  Serial.begin(9600);
  
  analogWrite(ENA, 255);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);

  while(analogRead(SENSOR_PIN) < 577); // Repeat until DC motor stalls
  digitalWrite(IN1, LOW); // DC motor stops
  Serial.print("Stopped!");
}

void loop(){}

I am missing something in this. You are saying the DC motor current with no load exceeds the motor current when the motor is under load? Shouldn't that be the other way around? The unloaded current exceeds the loaded current by 57 mA?

I may have this wrong but on a L298 motor controller doesn't IN1 and IN2 control motor direction for Motor 1?

Ron

Know that DC motors draw quite some extra current when started.
Your code measures this inrush current and that's not telling about stalled or not. All motors draw stall current in the start.
Maybe averaging for some hundred milliseconds would work better?
There's no code in loop......