0% found this document useful (0 votes)
2 views

Load cell

Load cell calibration

Uploaded by

Segun Oladimeji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Load cell

Load cell calibration

Uploaded by

Segun Oladimeji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

#include <Wire.

h>

#include <HX711.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F, 16, 2); // Adjust the I2C address for your LCD module

const int loadCellDoutPin = 2;

const int loadCellSckPin = 3;

const int tareButtonPin = 4;

const int calibrationButtonPin = 5;

const int unitSwitchButtonPin = 6;

const int unitSwitchPin = 7; // Connect your unit switch (e.g., a toggle switch) to this pin

HX711 scale;

float calibrationFactor = 1.0;

float knownWeight = 10000.0; // 10kg known weight (adjust as needed)

boolean useKg = true; // Start with kg as the default unit

void setup() {

lcd.init();

lcd.backlight();

lcd.setCursor(0, 0);

lcd.print("Weight: ");
scale.begin(loadCellDoutPin, loadCellSckPin);

pinMode(tareButtonPin, INPUT_PULLUP);

pinMode(calibrationButtonPin, INPUT_PULLUP);

pinMode(unitSwitchButtonPin, INPUT_PULLUP);

pinMode(unitSwitchPin, INPUT_PULLUP);

Serial.begin(9600);

void tareScale() {

scale.tare();

void calibrateScale() {

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("Place 10kg weight");

lcd.setCursor(0, 1);

lcd.print("Press calibrate button");

// Wait for calibration button press

while (digitalRead(calibrationButtonPin) == HIGH) {

delay(100);

}
// Calculate the calibration factor

float weight = scale.get_units(10);

calibrationFactor = knownWeight / weight;

// Print the calibration factor

Serial.print("Calibration Factor: ");

Serial.println(calibrationFactor);

// Display "Calibrated" on the LCD

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("Calibrated!");

delay(2000);

lcd.clear();

void toggleUnit() {

useKg = !useKg;

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("Unit: ");

if (useKg) {

lcd.print("kg");

} else {

lcd.print("lb");
}

delay(1000);

lcd.clear();

void loop() {

// Check if the tare button is pressed

if (digitalRead(tareButtonPin) == LOW) {

tareScale();

// Check if the calibration button is pressed

if (digitalRead(calibrationButtonPin) == LOW) {

calibrateScale();

// Check if the unit switch button is pressed to toggle units

if (digitalRead(unitSwitchButtonPin) == LOW) {

toggleUnit();

// Read weight from HX711

float weight = scale.get_units(10) * calibrationFactor;

// Display weight in the selected unit on the LCD


lcd.setCursor(0, 0);

lcd.print("Weight: ");

if (useKg) {

lcd.print(weight, 2); // Display two decimal places for kg

lcd.print(" kg ");

} else {

lcd.print(weight * 2.20462, 2); // Convert to pounds and display two decimal places

lcd.print(" lb ");

delay(100);

}
#include <Wire.h>

#include <HX711.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F, 16, 2); // Adjust the I2C address for your LCD module

const int loadCellDoutPin = 2;

const int loadCellSckPin = 3;

const int tareButtonPin = 4;

const int calibrationButtonPin = 5;

const int unitSwitchButtonPin = 6;

const int unitSwitchPin = 7; // Connect your unit switch (e.g., a toggle switch) to this pin

HX711 scale;

float calibrationFactor = 1.0;

float knownWeight = 10000.0; // 10kg known weight (adjust as needed)

boolean useKg = true; // Start with kg as the default unit

void setup() {

lcd.init();

lcd.backlight();

lcd.setCursor(0, 0);

lcd.print("Weight: ");
scale.begin(loadCellDoutPin, loadCellSckPin);

pinMode(tareButtonPin, INPUT_PULLUP);

pinMode(calibrationButtonPin, INPUT_PULLUP);

pinMode(unitSwitchButtonPin, INPUT_PULLUP);

pinMode(unitSwitchPin, INPUT_PULLUP);

Serial.begin(9600);

void tareScale() {

// Read the current weight and set it as the tare offset

float tareOffset = scale.get_units(10);

scale.set_scale(); // Reset the scale factor to 1.0

scale.tare(); // Tare the scale

// Apply the tare offset as the new zero point

scale.set_scale(calibrationFactor);

scale.set_offset(tareOffset);

void calibrateScale() {

// Calibration code remains the same as previous examples

// ...

}
void toggleUnit() {

// Unit switching code remains the same as previous examples

// ...

void loop() {

if (digitalRead(tareButtonPin) == LOW) {

tareScale();

if (digitalRead(calibrationButtonPin) == LOW) {

calibrateScale();

if (digitalRead(unitSwitchButtonPin) == LOW) {

toggleUnit();

float weight = scale.get_units(10);

lcd.setCursor(0, 0);

lcd.print("Weight: ");

if (useKg) {

lcd.print(weight, 2);

lcd.print(" kg ");
} else {

lcd.print(weight * 2.20462, 2);

lcd.print(" lb ");

delay(100);

You might also like