When I compile my code the only output I receive is "Sketch uses 5532 bytes (17%) of program storage space. Maximum is 32256 bytes. Global variables use 477 bytes (23%) of dynamic memory, leaving 1571 bytes for local variables. Maximum is 2048 bytes." I made sure that my board and the port were selected properly in Tools. The code should be displaying weight values in pounds(lbs). My arduino uno is connected to a hx711, and a load cell is connected to the hx711. here is my code:
#include <HX711.h>
//Calibrating load cell
const int LOADCELL_DOUT_PIN = A4;
const int LOADCELL_SCK_PIN = A5;
HX711 scale;
Compiling is the first step. If successful (which it looks like it was) uloads the code to the- board. You then have to open the Serial Monitor to see what your program is displaying with all those Serial.print() statements. Make sure it it configured the same as your sketch (9600 baud)
As said before, it works as programmed.
You put the calibration in the main loop, so each program cycle starts with calibration of the current load as zero point...
You also never read the scale after calibrating it. Your code prints "Reading" but never actually does.
Things that need to be done once (like calibration/tare/etc) should go inside the setup() function, which runs 1 time.
Things that run repeatedly, like actually measuring things, go inside loop() since that function gets calls repeatedly. Look at some of the examples that come with the HX711 library.
your code seems to be messed up by being incompletely copied together from possibly well-coded sketches ...
You can change your code to become useful but that requires that you understand the general process of using it. Here are some sources that may assist:
#include <HX711.h>
//define pins
const int stepPin = 5;
const int dirPin = 2;
const int enPin = 8;
const int LOADCELL_DOUT_PIN = A4;
const int LOADCELL_SCK_PIN = A5;
HX711 scale;
//define calibration factor
float calibration_factor = 15;
float load;
void setup() {
Serial.begin(9600); //Stats serial communication in 9600 baud rate
//Initiate pins as output
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(enPin, OUTPUT);
digitalWrite(enPin, LOW);
Serial.println("Initializing scale calibration."); //Prints user commands
Serial.println("Please remove all weight from scale.");
Serial.println("Place known weights on scale");
Serial.println("Press '+' to increase calibration factor by 10");
Serial.println("Press '-' to decrease calibration factor by 10");
Serial.println("Press 'C' for tare");
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN); //Initializes scaling process
//Used pins are A4 & A5
scale.set_scale();
scale.tare(); //reset scale to 0
}
void loop() {
digitalWrite(dirPin, HIGH); //Determining the number of steps the motor will take.
for(int x = 0; x < 1400; x++) { //1400 steps for small, 1200 for medium, 800 for large
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
if (x%274 == 0) //Incrementing load readings every 274 steps.
{ //Increments of 274 steps for Small, Inc. of 213 steps for Medium
//Inc. of 160 steps for Large
scale.set_scale(calibration_factor); //Adjusts the calibration factor
Serial.print("Reading: "); //Prints weight readings in 2 decimal places, in lbs.
Serial.print(scale.get_units(),2);
Serial.println("lbs");
Serial.print("Calibration factor: "); //Prints calibration factor
Serial.println(calibration_factor);
}
load = scale.get_units(); //Storing load value collected from force reading
if (load >= 50) { //testing if load is >= 50lbs. If true, the loop will be broken
break; //And pulses will stop being sent to the motor stopping it
}
}
if(Serial.available()) //calibration process starts if there is a serial connection present
{
char temp = Serial.read(); //Reads users keyboard inputs
if(temp == '+') //Increases calibration factor by 10 if '+' key is pressed
calibration_factor += 10;
else if(temp == '-') //Decreases calibration factor by 10 if '-' key is pressed
calibration_factor -= 10;
else if(temp == 'c' || temp == 'C')
scale.tare(); //Reset scale to zero if 'C' key is pressed
}
scale.power_down(); //Puts scale to sleep mode for 5 seconds.
delay(5000);
scale.power_up();
}
I'm noticing that the reading will be 0.00lbs, then when I apply a load it reads 0.001 lbs so I'm not sure if the load actually being read or not.
Ok, your sketch now includes also a stepper motor.
Would you mind telling us what the intended use of the complete equipment is?
In general it is advisable to make a single setup of the different components, get them to work as expected and then integrate them step by step. It is much easier to identify bugs ...
I second @TomGeorge's concerns about the wires and soldering. If you use smaller wires they'll still work but they are much easier to handle and to avoid unwanted shortcuts.
I am still getting a value of 0 when reading the load with the HX711. I wanted to ask if there is a test code I can run to see if there is a hardware problem. I am getting a multimeter tomorrow to help narrow down the issue. Here is my code, connections, schematic, and spec sheet for the load cell.
#include <HX711.h>
//define pins
const int stepPin = 5;
const int dirPin = 2;
const int enPin = 8;
const int LOADCELL_DOUT_PIN = A4;
const int LOADCELL_SCK_PIN = A5;
HX711 scale;
//define calibration factor
float calibration_factor = 15;
float load;
void setup() {
Serial.begin(9600); //Stats serial communication in 9600 baud rate
//Initiate pins as output
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(enPin, OUTPUT);
digitalWrite(enPin, LOW);
Serial.println("Initializing scale calibration."); //Prints user commands
Serial.println("Please remove all weight from scale.");
Serial.println("Place known weights on scale");
Serial.println("Press '+' to increase calibration factor by 10");
Serial.println("Press '-' to decrease calibration factor by 10");
Serial.println("Press 'C' for tare");
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN); //Initializes scaling process
//Used pins are A4 & A5
scale.set_scale();
scale.tare(); //reset scale to 0
}
void loop() {
digitalWrite(dirPin, HIGH); //Determining the number of steps the motor will take.
for(int x = 0; x < 1400; x++) { //1400 steps for small, 1200 for medium, 800 for large
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
if (x%274 == 0) //Incrementing load readings every 274 steps.
{ //Increments of 274 steps for Small, Inc. of 213 steps for Medium
//Inc. of 160 steps for Large
scale.set_scale(calibration_factor); //Adjusts the calibration factor
Serial.print("Reading: "); //Prints weight readings in 2 decimal places, in lbs.
Serial.print(scale.get_units(),2);
Serial.println("lbs");
Serial.print("Calibration factor: "); //Prints calibration factor
Serial.println(calibration_factor);
}
load = scale.get_units(); //Storing load value collected from force reading
if (load >= 50) { //testing if load is >= 50lbs. If true, the loop will be broken
break; //And pulses will stop being sent to the motor stopping it
}
}
if(Serial.available()) //calibration process starts if there is a serial connection present
{
char temp = Serial.read(); //Reads users keyboard inputs
if(temp == '+') //Increases calibration factor by 10 if '+' key is pressed
calibration_factor += 10;
else if(temp == '-') //Decreases calibration factor by 10 if '-' key is pressed
calibration_factor -= 10;
else if(temp == 'c' || temp == 'C')
scale.tare(); //Reset scale to zero if 'C' key is pressed
}
scale.power_down(); //Puts scale to sleep mode for 5 seconds.
delay(5000);
scale.power_up();
}