How to run stepper motor NEMA 17 driver L298n and load cell HX711 simultaneously

As lead screw moves up through motor the load cell gives reading as it displaces up. The arrangement is like the elastic rod one end attached to load cell and other end is hanged on with load weights and the elastic rod wrapped over rigid cylinder. So, as the motor runs the lead screw helps to move up the arrangement through step revolution and rod slides as it moves up, which generates tension in thread which attached to load cell so it gives reading continously while motor runs.
I want to make a graph between load vs displacement.
Hardware I am using:
NEMA 17 stepper motor
L298n motor driver
HX711 Load cell
Arduino UNO
I tried to do with this But not able to get right code to get both readings simultaneously. Either I have to change arduino or driver else other stuff like code.
please help me out.


Post your sketch, well formated, with well-tempered comments and in so called code tags "</>" and schematic to see how we can help.

That's the size of the base plate. 1.7 inch.
How about the model number (electrical specs).

Poor or even impossible choice for most stepper motors.

What is the motor supply voltage.
Leo..

The boat anchor L298 is an ancient and inefficient DC motor driver. It is totally inappropriate for a modern biploar stepper.

If you post a data sheet for the motor, we can help you to choose an appropriate driver.

Pololu has a good line of stepper drivers. They have great documentation for each of their products.

Post your well formatted code in a code block. We can't help with code we can't see. Desctibe what the code actually does and how that differs from what you want.

Moving the nut up / down will not change tension on the load cell, the weight will move 1/2 the the distance the nut moves.


code for load cell.



code for stepper motor

Hi, @rokub97

To add code please click this link;

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

#include <HX711.h>
#include <AccelStepper.h>

// Define pins for the load cell and L298N driver
#define LOADCELL_DOUT_PIN 2
#define LOADCELL_SCK_PIN 3
#define STEPPER_STEP_PIN 4
#define STEPPER_DIR_PIN 5
#define STEPPER_EN_PIN 6
#define L298N_IN1_PIN 7
#define L298N_IN2_PIN 8
#define L298N_IN3_PIN 9
#define L298N_IN4_PIN 10

// Define calibration factor for the load cell
const float CALIBRATION_FACTOR = -705.0;

// Create objects for the load cell and stepper motor
HX711 loadCell(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
AccelStepper stepper(AccelStepper::FULL4WIRE, STEPPER_IN1_PIN, STEPPER_IN3_PIN, STEPPER_IN2_PIN, STEPPER_IN4_PIN);

void setup() {
  // Set up serial communication for debugging
  Serial.begin(9600);

  // Set up load cell and stepper motor pins
  pinMode(STEPPER_STEP_PIN, OUTPUT);
  pinMode(STEPPER_DIR_PIN, OUTPUT);
  pinMode(STEPPER_EN_PIN, OUTPUT);
  pinMode(L298N_IN1_PIN, OUTPUT);
  pinMode(L298N_IN2_PIN, OUTPUT);
  pinMode(L298N_IN3_PIN, OUTPUT);
  pinMode(L298N_IN4_PIN, OUTPUT);

  // Set up load cell
  loadCell.set_scale(CALIBRATION_FACTOR);
  loadCell.tare();
}

void loop() {
  // Read load cell data
  float load = loadCell.get_units();
  Serial.print("Load: ");
  Serial.println(load);

  // Move stepper motor based on load cell data
  if (load > 0) {
    digitalWrite(L298N_IN1_PIN, HIGH);
    digitalWrite(L298N_IN2_PIN, LOW);
    digitalWrite(L298N_IN3_PIN, LOW);
    digitalWrite(L298N_IN4_PIN, HIGH);
  } else {
    digitalWrite(L298N_IN1_PIN, LOW);
    digitalWrite(L298N_IN2_PIN, HIGH);
    digitalWrite(L298N_IN3_PIN, HIGH);
    digitalWrite(L298N_IN4_PIN, LOW);
  }
  stepper.setSpeed(abs(load));
  stepper.runSpeed();
}

CODE for simultaneously run but i couldn't dir pin, step pin, en pin in arduino and driver

Hi!
I'm currently working with the AccelStepper library and can give you some tips.

  1. When instantiating the stepper its already initiating the pins as outputs no need to do it on the setup.

  2. You are using the enable pin but not modifying it. Did you try to digitalWrite(STEPPER_EN_PIN, LOW); in the setup? I recommend you make a sepparate program to try to test the stepper motor.

  3. You might be using the functions wrong: Move one step it if a step is due (as described above), implementing a constant speed as set by the most recent call to setSpeed().

You have to specify how many steps you want then run the command, i'm doing something like this:

stepper.MoveTo(pos);
stepper.runToPosition();

You probably want to use different functions, this link helped me a lot understand the library.

Hope this helps,

Domenec.

The stepper motor from post#6 can't be driven by the L298 from post#11.
You will burn the driver or the motor.

Try a DRV8825 with a 12volt motor supply.
Leo..

^ This. I don't see where the tension applied to the load cell is going to change with travel? You are just dragging your elastic strap over a fulcrum and in doing it that way creating a drag coefficient. Why not just use a pulley? The tension will just be whatever your slotted weights add up to. I just do not see tension changing? Unless I am missing something.

Next, you have a stepper motor which rotates 1.8 degrees per step. One complete revolution will be 200 steps so with the thread pitch of the lead screw known yes, you can calculate travel.

So what exactly is the goal here? You want to run a plot of tension against travel? Tension and travel on which axis?

Finally the L298, as has been covered is not a good choice for driving a stepper motor. Another consideration is your stepper rotational speed. Normally in a design like you posted you use a stepper motor with a gear reduction so as to get a nice smooth transition of steps to actual travel.

What exactly is your final goal?

Ron

When setting up your DRV8825 stepper driver, don't forget to set the current limit correctly. Pololu has a good video.

which motor driver would be best ?
A4988
TB6560
or other

Tension is changing as it goes up.
I code for separately run both and took reading. But Professor wants it to be continuous and taken simultaneously as it moves up.

I have attached code please look at it and help.

Why are you not using STEPPER_STEP_PIN when instantiating the AccelStepper? Where does the STEPPER_IN1_PIN come from?