// Calibrating the load cell
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include "HX711.h"
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 8;
const int LOADCELL_SCK_PIN = 9;
HX711 scale; //define scale
void setup() {
Serial.begin(115200); //begin serial output
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN); //initialize scale
tare(); //tare scale
}
void loop() {
long reading = scale.get_units(10); //get scale reading
display.print(reading); //display reading on OLED
display.print("g");
}
void tare(){
if (scale.is_ready()) {
scale.set_scale();
Serial.println("Tare... remove any weights from the scale.");
delay(5000);
scale.tare();
Serial.println("Tare done...");
Serial.print("Place a known weight on the scale...");
delay(5000);
long reading = scale.get_units(10);
Serial.print("Result: ");
Serial.println(reading);
}
else {
Serial.println("HX711 not found.");
}
delay(1000);
}
//calibration factor will be the (reading)/(known weight)
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include "HX711.h"
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 8;
const int LOADCELL_SCK_PIN = 9;
HX711 scale; //define scale
#define CALIBRATION_FACTOR 21.3636363 //enter calibration factor from code 1
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(OLED_RESET);
void setup() {
Serial.begin(115200); //begin serial output
display.begin(SSD1306_SWITCHCAPVCC,0x3C); //begin OLED display
display.clearDisplay();
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN); //initialize scale
scale.set_scale(CALIBRATION_FACTOR); // calibrates the scale
scale.tare(); // reset the scale to 0
}
void loop() {
long reading = scale.get_units(10); // gets reading from the scale
Serial.print("Result: ");
Serial.println(reading);
delay(1000);
display.clearDisplay();
display.setTextSize(4); // set OLED text size and color
display.setTextColor(WHITE);
display.setCursor(0,0); //location of reading on OLED
display.print(reading); // display the current reading
display.print("g");
display.display();
delay(1000);
}