stepper motor running while collecting load cell data..?

hello everyone... little help from your arduino knowledge is needed... this is my project brief...there are number of sliding mechanisms with a sliding range of the each one need around 0.8N to 1.5N of Static friction to be marked as a OK (approved) i have to measure them one by one..i could do it with a newton meter, but it will be a painstaking i made a simple machine using arduino with a stepper motor is functioning as a linear actuator, a mechanical holder is fixed on the moving part (to hold the sliding mechanism) ..and at end of the linear actuator, a load cell is fixed(vertically, to measure friction force)..what this set up suppose do is when you placed the sliding mechanism on the holder, stepper actuates it and the sliding mechanism makes contact with the load cell and slides..then the motor will stop.. and the reading is given to the lcd display...This is the design of the machine... so my problem is how to get readings from the HX711 without interrupting the stepper motor... ?

i want measure the friction of the whole sliding range to get an maximum value.. thank you

OP's image. See this Simple Image Posting Guide


It's an interesting project but I don't see a question in your Original Post.

If you are asking whether it would be possible to read the sensor between motor steps then we would need a link to the datasheet for the sensor. With some sensors you can ask for a new reading and come back later to collect the value - rather than hanging around for a long time waiting while it figures out the value.

I wonder if a geared DC motor would be a better choice as it would give smoother motion - maybe the steps of the stepper motor would interfere with the force readings?


thank you… my problem is how can i get load cell reading while the stepper motor is running…? if i had to the arduino would run the two processes separately… therefore the stepper runs first then it gets the load cell reading… i’m using drv8825 to control my stepper motor… therefore i had to use a code like this

for(int i = 0; i < stepsPerRevolution; i++)
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
digitalWrite(stepPin, LOW);

i want to get the load cell reading within this motor movement… how can i do it??


Please read the post at the start of any forum , entitled "How to use this Forum".
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you post your complete code and a schematic of you project please?

Thanks.. Tom... :slight_smile:

To get your brain started, get rid of the delay()s, and replace with millis() timing.
When you understand that, you’ll see ways to interleave your strain gauge measurements, but a couple of things come to mind.

As Robin2 suggested, the motor steps may be detected by the sensor.
and/or If each sensor measurement takes ‘too long’, that may interfere with the stepping symmetry.

For both reasons, I’d be thinking about a DC motor and h-bridge to turn the worm gear.

i want to get the load cell reading within this motor movement… how can i do it??

Have a look at the second example in this Simple Stepper Code - it uses micros() and millis() for non-blocking step timing.

Also, don’t use a FOR loop as that also blocks until it completes. Use an IF with a count variable and allow loop() to do the repetition.

Have a look at how the code is organized in Several Things at a Time

Note how each function runs very briefly and returns to loop() so the next one can be called. None of the functions tries to complete a task in one call. And there may be dozens of calls to a function before it is actually time for it to do anything.

From the programming point of view a DC motor would be much simpler.


Fortunately, you are using a driver which needs only a pwm signal to run the motor. The pwm signal should can have a 50% duty cycle and the frequency determines the motor speed. So you can't use the analogWrite() function but you may be able to use the tone() function. The frequency needs to be around 833Hz based on your code above (1.2ms period).

So to start the motor, use

tone(stepPin, 833);

and stop it later with


You will need to use a pwm capable pin for stepPin.

tone() will continue to run while your code is reading from the sensor.

If you get too much vibration from the motor, you could try using the half-stepping, quarter-stepping etc modes and 2x/4x the pwm frequency.

Good idea using tone() to drive the stepper driver.
That certainly takes the timing out of loop()’s control...
Nice thinking.

Fortunately, you are using a driver which needs only a pwm signal to run the motor. The pwm signal should have a 50% duty cycle

There is no need for a 50% duty cycle. Most stepper motor drivers are content with a very short pulse of (say) 10 microsecs. IIRC the A4988 is happy with a 1 µsec pulse.


@Robin2 the OP is using drv8825, but I'm sure you're right about the duty cycle.

Thanks, I missed that. The DRV8825 datasheet says the minimum pulse width is 1.9 µsecs