SCALE HX711 LOAD CELL

scale

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/HX711.zip

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin,BACKLIGHT_PIN,POSITIVE);
LCD *myLCD = &lcd;
#include “HX711.h”

#define DOUT 3 // DT
#define CLK 2 // SCK
#include <avr/interrupt.h>
#include <avr/eeprom.h>
int addr1 = 1;
int pos;
const int buttonPin1 = 5;
int buttonState1 = 0;
const int buttonTare = 4;
int buttonTareState = 0;
HX711 scale;

int calibration_factor;
float units;
float ounces;

void setup() {
Serial.begin(9600);
pinMode(16, INPUT);
pinMode(17, INPUT);
pinMode(buttonPin1, INPUT);
digitalWrite(buttonPin1, HIGH);
pinMode(buttonTare, INPUT);
digitalWrite(buttonTare, HIGH);
scale.begin(DOUT, CLK);
lcd.begin(16, 2);
scale.set_scale();
scale.tare(); //Reset the scale to 0

long zero_factor = scale.read_average();
}

void loop() {

buttonState1 = digitalRead(buttonPin1);
buttonTareState = digitalRead(buttonTare);
calibration_factor = eeprom_read_word((uint16_t*)addr1);
scale.set_scale(calibration_factor); //Adjust to this calibration factor
units = scale.get_units(), 10;
lcd.setCursor(0, 0);
lcd.print(units);
lcd.setCursor(6, 0);
lcd.print(” grams”);
lcd.setCursor(7, 1);
lcd.print(calibration_factor);

if (buttonState1 == LOW) {
calib();
while (!eeprom_is_ready());
cli();
if(eeprom_read_word((uint16_t*)addr1) != pos) {
eeprom_write_word((uint16_t*)addr1, pos);
}
sei();
}
if (buttonTareState == LOW) {
scale.tare();
}
else{
action();
}
}
void calib() {
pos= eeprom_read_word((uint16_t*)addr1);
while (digitalRead(16) == HIGH) {
pos++;
delay(50);
}
while (digitalRead(17) == HIGH) {
pos–;
delay(50);
}
}

void action() {
calibration_factor = eeprom_read_word((uint16_t*)addr1);
scale.set_scale(calibration_factor); //Adjust to this calibration factor
units = scale.get_units(), 10;
lcd.setCursor(0, 0);
lcd.print(units);
lcd.setCursor(6, 0);
lcd.print(” grams”);
lcd.setCursor(7, 1);
lcd.print(calibration_factor);
}

Balance

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s