Stepper Motor Direction via Flow Amps
When motors stuck their current draw increases, you can sense that increase in the current and then change the rotation of the motor. The simplest way to measure current is with using a shunt resistor, for sensing high currents, current sensors based on hall effect sensors is usually used. ACS712 is one example.

How to sense current using a shunt?

Basically we're measuring the voltage drop over a resistor (RS), but the voltage drop is too small for Arduino to measure so we need an opamp to "amplify" the input:







simulate this circuit &ndash; Schematic created using CircuitLab

The schematic above is the simplest way to measure the voltage drop at "LOW SIDE", there is differential mode and "HIGH SIDE" measurement methods.

The gain of opamp can be set with resistors and this formula:

VOUT = (1 + R2/R1) * V1

The output of opamp then can be calculated to get current using ohm's law:

I = V / R

A simple code to calculate current:

int rawAnalog;
float voltageDrop;
int resistor = 0.1;
float current;

void setup() {
  pinMode(A0, OUTPUT);
}

void loop() {
  rawAnalog = analogRead(A0); // Read A0 input
  voltageDrop = (rawAnalog * 5) / 1024; // Convert the raw value to voltage
  current = voltageDrop / resistor; // calculate the current
}


Bonus: INA219 is an easy to use high-side I2C module which can measure both current and voltage.