Please help me with my hx711/stepper motor code

Hey all! I am trying to control a stepper motor using a strain sensor and HX711 chip. I can successfully control the stepper motor independently and weigh objects accurately but ran into issues when I tried to combine the two programs.

I think the issue is that the read and serialprint is interfering with the stepper steps but I don't know how to stop it or change the frequency. While the output is nice, I don't need near as many data points or really even need to see it on the serial monitor. I believe the getunits comes from the serial feed though rather than from the hx711 directly.

I can light an LED using this code logic but the stepper motor is too much for it a it doesn't even try to move.

Thanks for any help you may be able to offer!

/*
 Example using the SparkFun HX711 breakout board with a scale
 By: Nathan Seidle
 SparkFun Electronics
 Date: November 19th, 2014
 License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

 This example demonstrates basic scale output. See the calibration sketch to get the calibration_factor for your
 specific load cell setup.

 This example code uses bogde's excellent library:"https://github.com/bogde/HX711"
 bogde's library is released under a GNU GENERAL PUBLIC LICENSE

 The HX711 does one thing well: read load cells. The breakout board is compatible with any wheat-stone bridge
 based load cell which should allow a user to measure everything from a few grams to tens of tons.
 Arduino pin 2 -> HX711 CLK
 3 -> DAT
 5V -> VCC
 GND -> GND

 The HX711 board can be powered from 2.7V to 5V so the Arduino 5V power should be fine.

*/

#include "HX711.h"
#include <Stepper.h>

#define calibration_factor 212050.0 //This value is obtained using the SparkFun_HX711_Calibration sketch

#define LOADCELL_DOUT_PIN  3
#define LOADCELL_SCK_PIN  2
const int stepsPerRevolution = 2048;  // change this to fit the number of steps per revolution
const int rolePerMinute = 10;         // Adjustable range of 28BYJ-48 stepper is 0~17 rpm


//initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);

HX711 scale;

void setup() {
 myStepper.setSpeed(rolePerMinute);
  Serial.begin(115200);
  Serial.println("HX711 scale demo");

  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0

  Serial.println("Readings:");
}

void loop() {
  Serial.print("Reading: ");
  Serial.print(scale.get_units(), 1); //scale.get_units() returns a float
  Serial.print(" lbs"); //You can change this to kg but you'll need to refactor the calibration_factor
  Serial.println();

 if (scale.get_units() > 1.8) {
  myStepper.step(stepsPerRevolution);
  delay(500);
  
 }
  
}

How is the stepper connected?

Try this:

Thank you! This is exactly what I needed.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.