Projects / Blue Pill kitchen scale

Blue Pill kitchen scale

Intermediate2.8 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. STM32++674 g

    Mount the load cell

    One end fixed to a base, the other end carrying a small platform, with spacers so it can flex.

  2. STM32ST

    Wire the programmer

    SWDIO, SWCLK, GND and 3.3V.

  3. STM32+676 g

    Wire the amplifier

    DT to PA0, SCK to PA1, power at 3.3 V.

  4. STM32++677 g

    Wire the load cell

    Red to E+, black to E-, white to A-, green to A+.

  5. STM3215.7 mASSD1306

    Wire the display and button

    OLED on PB7 and PB6, button on PB12 to GND.

  6. STM32+679 gSSD1306

    Install the libraries

    HX711, Adafruit SSD1306 and Adafruit GFX.

  7. STM32++680 g

    Upload and calibrate

    With the platform empty press tare, put the known weight on, type c500 in the Serial Monitor.

In short

How do you build a blue Pill kitchen scale?

A Blue Pill reads a 5 kg bar load cell through an HX711 amplifier, tares on a button and shows grams on an OLED, with a serial command to calibrate against a known weight. You need STM32 Blue Pill (STM32F103C8T6), ST-Link V2 programmer (clone), HX711 load cell amplifier, Load cell 5 kg (bar type), SSD1306 OLED Display, Tactile push button 6 mm and Breadboard 830 Tie Points. It takes 7 steps and about 170 minutes.

Level
Intermediate
Time
About 170 min
Parts
7

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
ST-Link GNDBoard GNDGround
ST-Link SWDIOBoard DIODebug data
ST-Link SWCLKBoard DCLKDebug clock
ST-Link 3.3VBoard 3.3 pinPower from the programmer (do not also plug in USB)
HX711 VCC and OLED VCCBlue Pill 3.3 pinPower at 3.3 V
HX711 GND and OLED GNDBlue Pill GNDCommon ground
HX711 DTBlue Pill PA0Data from the amplifier
HX711 SCKBlue Pill PA1Clock to the amplifier
Load cell red wireHX711 E+Excitation positive (check your cell's sheet)
Load cell black wireHX711 E-Excitation negative
Load cell white wireHX711 A-Signal negative
Load cell green wireHX711 A+Signal positive
OLED SDA and SCLBlue Pill PB7 and PB6I2C data and clock
Tare buttonBlue Pill PB12 and GNDSets zero

Code

A load cell is a metal bar with strain gauges glued on it. When you press on it the bar bends by a tiny amount and the gauges change resistance, which unbalances a small bridge circuit and gives a voltage of only a few millivolts. The HX711 is a 24-bit converter with a built-in amplifier made for exactly this, and it sends the result to the board over two wires, a data line and a clock line. The program reads a raw count, and the count is proportional to the weight once you subtract the empty reading, which is what the tare button does. To turn counts into grams you need one number, counts per gram. You find it by putting a known weight on the scale and typing it in; the program works out the factor and uses it from then on. Note the factor and put it in the sketch so it survives a restart. Mount the bar so that one end is fixed to the base and the other end carries the platform, with small spacers so the bar can flex, and never load it beyond its 5 kg rating.

Runs on a virtual STM32 Blue Pill in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

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

const int DT = PA0, SCK_PIN = PA1, TARE_BTN = PB12;

HX711 scale;
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
float factor = 420.0;                              // counts per gram, replaced when you calibrate
unsigned long lastDraw = 0;

void showGrams(float g) {
  oled.clearDisplay();
  oled.setTextColor(SSD1306_WHITE);
  oled.setTextSize(1);
  oled.setCursor(0, 0);
  oled.print("Load cell scale");
  oled.setTextSize(3);
  oled.setCursor(0, 24);
  oled.print(g, 0);
  oled.setTextSize(2);
  oled.print(" g");
  oled.display();
}

void setup() {
  Serial.begin(115200);
  pinMode(TARE_BTN, INPUT_PULLUP);
  Wire.begin();                                    // I2C1 uses PB7 for SDA and PB6 for SCL
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { while (true) {} }
  scale.begin(DT, SCK_PIN);
  scale.set_scale(factor);
  while (!scale.is_ready()) { delay(50); }
  scale.tare();                                    // start with nothing on the scale
  Serial.println("Type c and the weight in grams, for example c500, with that weight on the scale.");
}

void loop() {
  if (digitalRead(TARE_BTN) == LOW) {
    scale.tare();
    delay(300);
  }

  if (Serial.available()) {
    String line = Serial.readStringUntil('\n');
    if (line.length() > 1 && line[0] == 'c') {
      float known = line.substring(1).toFloat();
      float raw = scale.get_value(10);             // reading minus the tare offset
      if (known > 0 && raw != 0) {
        factor = raw / known;
        scale.set_scale(factor);
        Serial.print("Calibration factor ");
        Serial.println(factor, 2);                 // note this number to use as the starting value
      }
    }
  }

  if (millis() - lastDraw >= 250 && scale.is_ready()) {
    lastDraw = millis();
    float g = scale.get_units(3);
    if (fabs(g) < 0.5) g = 0;                      // hide tiny noise around zero
    showGrams(g);
  }
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Empty platformShows 0 g after tare
Known weight on the platformShows its weight within a few grams after calibration
Weight removedReturns to about 0 g
Press tare with a cup on the platformShows 0 g, then the contents of the cup when you add water
Press down on the platform by handReading rises, release and it returns

If it does not work

Reading goes negative when you add weight

Swap the green and white wires at A+ and A-.

Reading drifts

Let the board warm up for a few minutes and keep the cell out of draughts and sunlight.

Reading jumps around

Keep the wires short and away from the display wires, and check the cell is firmly fixed at the fixed end.

Weight is wrong by a constant ratio

Calibrate again with a known weight.

Nothing on the display

Check the I2C wires and that the OLED address is 0x3C.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the blue Pill kitchen scale?

STM32 Blue Pill (STM32F103C8T6), ST-Link V2 programmer (clone), HX711 load cell amplifier, Load cell 5 kg (bar type), SSD1306 OLED Display, Tactile push button 6 mm and Breadboard 830 Tie Points.

How long does the blue Pill kitchen scale take to build?

About 170 minutes for a intermediate maker, in 7 steps.

How do I know the blue Pill kitchen scale works?

Empty platform: Shows 0 g after tare. Known weight on the platform: Shows its weight within a few grams after calibration. Weight removed: Returns to about 0 g.

Reading goes negative when you add weight: what should I check?

Swap the green and white wires at A+ and A-.

Reading drifts: what should I check?

Let the board warm up for a few minutes and keep the cell out of draughts and sunlight.

Reading jumps around: what should I check?

Keep the wires short and away from the display wires, and check the cell is firmly fixed at the fixed end.

Weight is wrong by a constant ratio: what should I check?

Calibrate again with a known weight.