Load cell
Load cell
h>
#include <HX711.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 16, 2); // Adjust the I2C address for your LCD module
const int unitSwitchPin = 7; // Connect your unit switch (e.g., a toggle switch) to this pin
HX711 scale;
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.setCursor(0, 1);
delay(100);
}
// Calculate the calibration factor
Serial.println(calibrationFactor);
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() {
if (digitalRead(tareButtonPin) == LOW) {
tareScale();
if (digitalRead(calibrationButtonPin) == LOW) {
calibrateScale();
if (digitalRead(unitSwitchButtonPin) == LOW) {
toggleUnit();
lcd.print("Weight: ");
if (useKg) {
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 unitSwitchPin = 7; // Connect your unit switch (e.g., a toggle switch) to this pin
HX711 scale;
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.set_scale(calibrationFactor);
scale.set_offset(tareOffset);
void calibrateScale() {
// ...
}
void toggleUnit() {
// ...
void loop() {
if (digitalRead(tareButtonPin) == LOW) {
tareScale();
if (digitalRead(calibrationButtonPin) == LOW) {
calibrateScale();
if (digitalRead(unitSwitchButtonPin) == LOW) {
toggleUnit();
lcd.setCursor(0, 0);
lcd.print("Weight: ");
if (useKg) {
lcd.print(weight, 2);
lcd.print(" kg ");
} else {
lcd.print(" lb ");
delay(100);