Reading current draw of a stepper motor

Hello! I am trying to read the current draw of a Nema 17 Stepper Motor (controlled by a Seeed Studio Motor Shield) with an ACS712 Hall Effect Current Sensor Module. The thing is that I want to read the current draw during the steps times not between them. So basically I want to send the command to the stepper to rotate but in the same time to read the current draw of it and if the current exceed a certain limit to stop the stepper rotation (for example if the load of the stepper rise). Is there any possibility of doing this?

Here is the basic code of controlling the stepper and reading the current:

//Stepper control
#include <Stepper.h>
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 8,11,12,13);

//Current reading
const int analogIn = A0;
int mVperAmp = 185;
int RawValue= 0;
int ACSoffset = 2500; 
double Voltage = 0;
double Amps = 0;

void setup() {
  //Stepper control
  myStepper.setSpeed(60);
  Serial.begin(9600);
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  digitalWrite(9,HIGH);
  digitalWrite(10,HIGH);
}
 
void loop() {
  //Stepper control
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  
  //Current reading
  RawValue = analogRead(analogIn);
  Voltage = (RawValue / 1023.0) * 5000;
  Amps = ((Voltage - ACSoffset) / mVperAmp);
  Serial.println(Amps,3);
}

Thank you!

bogdan90:
command to the stepper to rotate but in the same time to read the current draw of it and if the current exceed a certain limit to stop the stepper rotation

I think there is a fundamental misunderstanding here. A stepper motor does not draw more current when under load in the same way that a DC motor does. A stepper motor generates a certain amount of torque (varies with speed) and if the load exceeds that torque the motor just misses steps).

A specialized stepper driver (such as a Pololu DRV8825) monitors the current during each step and prevents it from exceeding a preset limit. It would be quite impractical to expect an Arduino to be able to do that fast enough to be useful.

...R
Stepper Motor Basics

I am trying to read the current draw of a Nema 17 Stepper Motor

But what color is it?

The thing is that I want to read the current draw during the steps times not between them.

A stepper motor steps pretty quick. The step operation is a matter of swapping which coil has power. That, from the Arduino's point of view, is an atomic operation. How can you expect it to read the current while it is switching the state of two pins (or one, if the actual stepping happens using a proper stepper driver)?

I should mention that I'm a beginner in electronics. The reason of trying to stop the stepper under a certain load is because I want to design a gripper witch stops and hold a certain position when an object is picked by reading the current draw. I thought that the current draw will rise when the object is picked. I chosen stepper because unlike a simple DC motor, it can hold his position. Obviously I made a mistake with this concept. I wonder, is other possibility to do this without using force sensors?

You could put a rotary encoder on the stepper shaft which would allow you to detect the fact that the stepper was not moving even though you were sending step pulses.

I think there are stepper drivers that can report missed steps but I don't think the usual (cheap) drivers that are normally used with the Arduino can do so.

I presume your gripper does not move through as much as 270deg so maybe you could put a potentiometer on the hinge of the gripper and use changes in the resistance (or not) to signify that an object in the jaws.

Note that it is not easy (very difficult ?) to vary the force applied by a stepper motor whereas it would be very easy with a geared DC motor. It is also easy to read the current draw of a DC motor. If you use a DC motor to drive through a worm gear it will hold position without any electric power.

...R

The worm gear idea is great! It solve all the problems because I can use a simple DC motor. Thank you!