Hi, my load cell is not reading any values. It is giving me '0 g'. I am using Arduino Mega, HX711, 1kg load cell.
void weightControl(float desiredWeight) {
lcd.setCursor(0, 0);
lcd.print("Measuring Weight");
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN );
scale.set_scale(1590.153);
scale.tare();
float weight = scale.get_units(10); // Read the average of 10 measurements for better stability
Serial.print("Measured Weight: ");
Serial.println(weight, 2);
lcd.setCursor(0, 1);
lcd.print("Weight: ");
lcd.print(weight, 1); // Display weight with one decimal place
lcd.print (" g");
while (weight < desiredWeight) {
// Rotate motor until the target weight is reached
digitalWrite(relayPin, LOW);
}
// Stop the motor
digitalWrite(relayPin, HIGH);
delay(1000);
lcd.clear();
}
Welcome to the forum
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination
https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum
1 Like
Hi @3marie_butterfly
welcome to the arduino-forum.
You should post your code inside so called code-tags as a code-section
The code you have posted is not a complete sketch.
Here is a tutorial how to post code as a code-section
Hi newcomer,
This thread wants to show you how you can speed-up getting helpful answers with small effort.
If you manage at least to post this way. You have the sympathy of the experienced users.
If you are willing to invest another 20 minutes these 20 minutes extra-time will save you a minimum of 200 minutes to finish your project.
always
post your full sketch. As a
code-section
from the very first to the very last line
A code-section has a small height => keeps your posting "short" but eā¦
This is a demo-code for HX711 based loadcells which prints to the serial monitor.
to what IO-pins do you have connected clock and datapin of the HX711-module?
post a hand drawn schematic what is connected to what
//
// FILE: HX_kitchen_scale.ino
// AUTHOR: Rob Tillaart
// PURPOSE: HX711 demo
// URL: https://github.com/RobTillaart/HX711
#include "HX711.h"
HX711 scale;
uint8_t dataPin = 6;
uint8_t clockPin = 7;
void setup() {
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("LIBRARY VERSION: ");
Serial.println(HX711_LIB_VERSION);
Serial.println();
scale.begin(dataPin, clockPin);
Serial.print("UNITS: ");
Serial.println(scale.get_units(10));
Serial.println("\nEmpty the scale, press a key to continue");
while(!Serial.available());
while(Serial.available()) Serial.read();
scale.tare();
Serial.print("UNITS: ");
Serial.println(scale.get_units(10));
Serial.println("\nPut 1000 gram in the scale, press a key to continue");
while(!Serial.available());
while(Serial.available()) Serial.read();
scale.calibrate_scale(1000, 5);
Serial.print("UNITS: ");
Serial.println(scale.get_units(10));
Serial.println("\nScale is calibrated, press a key to continue");
// Serial.println(scale.get_scale());
// Serial.println(scale.get_offset());
while(!Serial.available());
while(Serial.available())
Serial.read();
}
void loop()
{
Serial.print("UNITS: ");
Serial.println(scale.get_units(10));
delay(250);
}
Welcome! Can you post an annotated schematic showing exactly how you wired it, be sure to show all connections, parts, power, ground and power sources.
system
Closed
August 29, 2024, 5:46pm
5
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.