FluxBench.AIShared project · read-only

HX711 Digital Scale

ESP32 DevKit (WROOM-32)·Arduino C++·Updated Jul 27, 2026·by FluxBench TeamIncludes Lab + Schematic

A working kitchen scale: an HX711 load-cell amplifier is read with the standard HX711 library (set_scale + tare), and the weight is shown in big digits on a 128x64 OLED in grams and ounces. Click the HX711 on the bench and drag its weight slider while the sketch runs - the display follows, the red LED on GPIO 4 lights with an OVERLOAD warning above 500 g, and pressing the button on GPIO 26 tares (zeroes) the scale so you can weigh into a container.

sketch.ino
// HX711 Digital Scale - a working kitchen scale on the OLED.
// Click the HX711 on the bench and drag its weight slider while the sketch
// runs - the OLED shows grams and ounces, and the red LED warns above 500 g.
// Press the button to tare (zero) the scale.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "HX711.h"

#define DT_PIN 14
#define SCK_PIN 27
#define TARE_PIN 26
#define ALERT_PIN 4
#define CAL_FACTOR 420.0
#define MAX_GRAMS 500.0

Adafruit_SSD1306 display(128, 64, &Wire, -1);
HX711 scale;

void setup() {
  Serial.begin(115200);
  pinMode(TARE_PIN, INPUT_PULLUP);
  pinMode(ALERT_PIN, OUTPUT);
  Wire.begin();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.display();
  scale.begin(DT_PIN, SCK_PIN);
  scale.set_scale(CAL_FACTOR);
  scale.tare();
  Serial.println("Scale ready - drag the HX711 weight slider");
}

void loop() {
  if (digitalRead(TARE_PIN) == LOW) {
    scale.tare();
    Serial.println("Tared - scale zeroed");
    delay(300);
  }

  float grams = scale.get_units(5);
  if (grams > -1.0 && grams < 1.0) grams = 0;
  float oz = grams / 28.3495;
  bool over = grams > MAX_GRAMS;
  digitalWrite(ALERT_PIN, over ? HIGH : LOW);

  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.print("DIGITAL SCALE");
  display.setTextSize(3);
  display.setCursor(0, 18);
  display.print((int)(grams + 0.5));
  display.setTextSize(2);
  display.print(" g");
  display.setTextSize(1);
  display.setCursor(0, 48);
  display.print(oz, 2);
  display.print(" oz");
  if (over) {
    display.setCursor(72, 48);
    display.print("OVERLOAD!");
  }
  display.display();

  Serial.print("Weight: ");
  Serial.print(grams, 1);
  Serial.print(" g  (");
  Serial.print(oz, 2);
  Serial.println(" oz)");
  delay(250);
}

Built with FluxBench.AI — the AI workbench for embedded projects.