Raspberry Pi Pico Digital Weighing Scale with HX711, Load Cell and OLED (MicroPython)

Make a Raspberry Pi Pico digital weighing scale in MicroPython with HX711, load cell, SSD1306 OLED and tare button. Wiring table, tested code with built-in HX711 driver, calibration steps and Hindi explanation.

  • DifficultyIntermediate
  • Build time2–4 hours
  • Board / MCURaspberry Pi Pico (RP2040)
  • Parts8 items
  • CodeMicroPython

Need it ready-made? Buy Ready Project

Raspberry Pi Pico digital weighing scale on a breadboard with an HX711, load cell, OLED display and tare button

A kitchen scale, a parcel scale or a beehive monitor all work on the same principle: a load cell bends very slightly under weight and an amplifier converts that tiny change into a number. In this project you will build a digital weighing scale with Raspberry Pi Pico, HX711 and a load cell, programmed in MicroPython, with the weight shown on a 0.96-inch OLED and a tare button to zero the scale with a container on it.

The code includes a small HX711 driver written from scratch (no extra driver file to hunt for), smoothing to stop the last digit from jumping, automatic switching between grams and kilograms and a clear calibration procedure. It runs on both the Raspberry Pi Pico and Pico W. You will get the parts list, a pin-to-pin wiring table, syntax-checked MicroPython code, build steps, troubleshooting, FAQ and a simple Hindi explanation.

How a Load Cell and HX711 Work

A bar-type load cell is an aluminium block with four strain gauges glued to it and connected as a Wheatstone bridge. When you put weight on the free end, the block bends by a few micrometres and the bridge output changes by only a few millivolts. That is far too small for the Pico’s analog input. The HX711 is a dedicated 24-bit analog-to-digital converter with a built-in amplifier (gain 128) designed exactly for this job.

The HX711 does not use I2C or SPI. Instead it has a simple two-wire interface: when a new reading is ready, it pulls DOUT low; the microcontroller then sends 24 clock pulses on SCK and reads one data bit after each pulse. A 25th pulse selects channel A with gain 128 for the next reading. Our MicroPython class does exactly this, converts the 24-bit two’s-complement value to a signed number, subtracts the tare offset and divides by a calibration factor to get grams.

Components Required

  • Raspberry Pi Pico or Pico W (with headers) – 1
  • HX711 load cell amplifier module – 1
  • Bar load cell, 1 kg / 5 kg / 10 kg (4 wires: red, black, white, green) – 1
  • 0.96″ SSD1306 I2C OLED (128×64) – 1
  • Tactile push button – 1 (tare)
  • Two rigid plates (wood/acrylic, about 10×10 cm) and M4/M5 screws to mount the load cell
  • Breadboard, jumper wires, micro-USB cable
  • A known reference weight for calibration (e.g. a 500 g pack of sugar, or coins weighed on a kitchen scale)

Wiring Table (Pin-to-Pin)

ModuleModule PinPico PinNotes
Load cellRed (E+)HX711 E+Excitation +
Load cellBlack (E–)HX711 E–Excitation –
Load cellWhite (A–)HX711 A–Signal – (swap white/green if weight reads negative)
Load cellGreen (A+)HX711 A+Signal +
HX711VCC3V3(OUT) – pin 36HX711 works from 2.6 to 5.5 V; 3.3 V keeps logic levels safe
HX711GNDGND – pin 38
HX711DT (DOUT)GP14 – pin 19HX_DOUT = Pin(14)
HX711SCKGP15 – pin 20HX_SCK = Pin(15)
SSD1306 OLEDVCC / GND3V3(OUT) / GND
SSD1306 OLEDSDAGP4 – pin 6I2C0 SDA
SSD1306 OLEDSCLGP5 – pin 7I2C0 SCL
Push buttonLeg 1 / Leg 2GP16 – pin 21 / GNDInternal pull-up; pressed = 0 → tare

Mount the load cell between the two plates in a “Z” shape: one end screwed to the base plate, the other end to the top plate, with spacers so the cell can bend freely. The arrow printed on the load cell should point down (direction of the force).

Libraries and Files Used (with Licenses)

  • MicroPython firmware for Raspberry Pi Pico / Pico W – github.com/micropython/micropython – MIT license.
  • ssd1306.py OLED driver from micropython-lib – github.com/micropython/micropython-lib – MIT license. Copy it to the Pico (or on a Pico W run import mip; mip.install("ssd1306") after connecting to Wi-Fi).
  • The HX711 class and the main program below are original code written for this article (no external HX711 driver is needed).

Complete MicroPython Code (main.py)

Validated on the box with python3 -m py_compile and the official mpy-cross compiler (no syntax errors). Save it on the Pico as main.py so it starts automatically.

# Raspberry Pi Pico / Pico W - Digital Weighing Scale
# HX711 + load cell + 0.96" SSD1306 I2C OLED + tare button (MicroPython)
# OLED driver: ssd1306.py from micropython-lib (MIT) - copy it to the Pico first
from machine import Pin, I2C
import time
import ssd1306

# ---------- pin setup (matches the wiring table) ----------
HX_DOUT = Pin(14, Pin.IN, pull=Pin.PULL_UP)   # HX711 DT  -> GP14
HX_SCK = Pin(15, Pin.OUT)                     # HX711 SCK -> GP15
TARE_BTN = Pin(16, Pin.IN, Pin.PULL_UP)       # button GP16 -> GND
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000)  # OLED SDA GP4, SCL GP5
oled = ssd1306.SSD1306_I2C(128, 64, i2c)

# Change this after calibration (see the article). Raw counts per gram.
CALIBRATION_FACTOR = 420.0


class HX711:
    """Minimal HX711 driver: channel A, gain 128."""

    def __init__(self, dout, sck):
        self.dout = dout
        self.sck = sck
        self.sck.value(0)
        self.offset = 0

    def is_ready(self):
        return self.dout.value() == 0

    def read_raw(self):
        t0 = time.ticks_ms()
        while not self.is_ready():          # wait for conversion
            if time.ticks_diff(time.ticks_ms(), t0) > 500:
                raise OSError("HX711 not responding")
        value = 0
        for _ in range(24):                 # clock out 24 data bits, MSB first
            self.sck.value(1)
            self.sck.value(0)
            value = (value << 1) | self.dout.value()
        self.sck.value(1)                   # 25th pulse -> channel A, gain 128
        self.sck.value(0)
        if value & 0x800000:                # two's complement to signed
            value -= 0x1000000
        return value

    def read_average(self, times=10):
        total = 0
        for _ in range(times):
            total += self.read_raw()
        return total / times

    def tare(self, times=15):
        self.offset = self.read_average(times)

    def get_grams(self, factor, times=5):
        return (self.read_average(times) - self.offset) / factor


def show(line1, line2, line3=""):
    oled.fill(0)
    oled.text("Pico Scale", 0, 0)
    oled.hline(0, 10, 128, 1)
    oled.text(line1, 0, 20)
    oled.text(line2, 0, 36)
    oled.text(line3, 0, 54)
    oled.show()


scale = HX711(HX_DOUT, HX_SCK)
show("Remove all", "weight...", "Taring")
time.sleep(2)
scale.tare()
show("Ready!", "Place an item")

smoothed = 0.0
while True:
    try:
        if TARE_BTN.value() == 0:           # button pressed -> zero the scale
            show("Taring...", "")
            scale.tare()
            smoothed = 0.0
            time.sleep_ms(300)

        grams = scale.get_grams(CALIBRATION_FACTOR)
        smoothed = 0.7 * smoothed + 0.3 * grams   # simple low-pass filter
        shown = 0.0 if abs(smoothed) < 1.0 else smoothed   # hide +/-1 g noise

        if abs(shown) >= 1000:
            show("Weight:", "{:.3f} kg".format(shown / 1000), "GP16 = Tare")
        else:
            show("Weight:", "{:.1f} g".format(shown), "GP16 = Tare")
        print("Raw avg: {:.0f}  Weight: {:.1f} g".format(scale.read_average(1) - scale.offset, shown))
    except OSError as e:
        show("HX711 error", "Check wiring")
        print(e)
    time.sleep_ms(200)

Code Explanation

  • HX711.read_raw() waits until DOUT goes low (data ready, timeout 500 ms), clocks out 24 bits MSB-first, sends one extra pulse to keep gain 128, and converts the result to a signed integer.
  • read_average() averages several readings; tare() stores the average with nothing on the scale as the zero offset.
  • get_grams() = (average − offset) ÷ CALIBRATION_FACTOR. The factor is the number of raw counts per gram for your specific load cell.
  • Smoothing: smoothed = 0.7 × old + 0.3 × new is a simple low-pass filter; values within ±1 g are shown as 0 to hide noise.
  • Display: below 1000 g the OLED shows grams with one decimal; above that it switches to kilograms with three decimals.
  • Tare button on GP16 re-zeros the scale at any time, e.g. after putting a bowl on it.
  • If the HX711 stops responding, the OLED shows “HX711 error / Check wiring” instead of crashing.

Step-by-Step Build and Calibration

  1. Flash MicroPython onto the Pico: hold BOOTSEL, plug in USB, and drag the latest Pico (or Pico W) .uf2 file from micropython.org onto the RPI-RP2 drive.
  2. Install Thonny, select the interpreter “MicroPython (Raspberry Pi Pico)”.
  3. Wire the load cell to the HX711 and the HX711, OLED and button to the Pico as in the table.
  4. Upload ssd1306.py to the Pico (File → Save as → Raspberry Pi Pico).
  5. Open main.py from this article in Thonny and save it to the Pico as main.py. Press Run.
  6. With nothing on the scale, it tares itself and shows “Ready!”.
  7. Calibrate: place your known weight (e.g. 500 g). In the Thonny shell, note the “Raw avg” value (this is the raw reading minus the offset). Calculate CALIBRATION_FACTOR = raw ÷ 500.
  8. Enter the new factor in the code, save and run again. Check with a second known weight – it should now read within a few grams.
  9. Press the button with an empty bowl on the plate to tare it, then add ingredients.

सरल हिंदी में समझें (Simple Hindi Explanation)

लोड सेल एक धातु का टुकड़ा है जिस पर strain gauge लगे होते हैं। वज़न रखने पर यह बहुत थोड़ा मुड़ता है और इसका आउटपुट कुछ मिलीवोल्ट बदलता है। इतना छोटा सिग्नल Pico सीधे नहीं पढ़ सकता, इसलिए HX711 मॉड्यूल इसे बढ़ाकर (amplify) 24-bit डिजिटल नंबर में बदल देता है। Pico दो तारों (DT और SCK) से यह नंबर पढ़ता है।

शुरुआत में स्केल खाली रहते हुए “tare” यानी zero सेट किया जाता है। फिर एक जाना-पहचाना वज़न (जैसे 500 ग्राम) रखकर calibration factor निकाला जाता है: Raw वैल्यू ÷ 500। इसके बाद OLED पर सही वज़न ग्राम या किलोग्राम में दिखता है। GP16 वाला बटन दबाकर आप किसी भी समय स्केल को zero कर सकते हैं – जैसे कटोरी रखकर।

Troubleshooting

ProblemFix
OLED shows “HX711 error”Check DT → GP14 and SCK → GP15 and HX711 power. Some cheap HX711 boards have poor solder joints on the header – re-solder them.
Weight is negativeSwap the white and green wires (A– / A+), or use a negative calibration factor.
Reading drifts slowlyLet the load cell warm up for a minute, avoid drafts, and make sure nothing touches the top plate. Re-tare before weighing.
Reading jumps by several gramsMount the load cell firmly with spacers; loose screws cause noise. Increase averaging in get_grams(…, times=10).
ImportError: no module named ssd1306Copy ssd1306.py to the Pico’s root folder.
OSError: [Errno 5] EIO on the OLEDCheck SDA/SCL on GP4/GP5. Run print(i2c.scan()) – the OLED should appear as 60 (0x3C).

Ideas to Extend the Project

  • Pico W: publish the weight to a web page or MQTT – useful for a beehive or a gas-cylinder level monitor.
  • Add a buzzer that beeps when a target weight is reached (portion control).
  • Use four half-bridge load cells for a bathroom scale.
  • Log weight over time to an SD card or Google Sheets.

Frequently Asked Questions

Which load cell capacity should I buy?

Choose one a little above the maximum you need. A 1 kg cell gives better resolution for kitchen use; a 5 kg or 10 kg cell suits parcels.

How accurate will this scale be?

With good mounting and calibration, around ±1 g on a 1 kg cell and ±2–5 g on a 5 kg cell.

Can I use the Arduino C++ core for the Pico instead?

Yes – the Earle Philhower RP2040 core with the “HX711” Arduino library works too. This article uses MicroPython because it needs no compiling and is easy to edit.

Can I power the HX711 from 5 V (VBUS)?

You can, but its DOUT line would then output 5 V logic, which is not safe for the Pico’s 3.3 V GPIO. Keep it on 3.3 V.

Why does the scale need calibration?

Every load cell and HX711 has slightly different sensitivity, so the raw-counts-per-gram factor must be measured once with a known weight.

Related Projects

Browse more Raspberry Pi Pico on Arduino Project Hub.

2 thoughts on “Raspberry Pi Pico Digital Weighing Scale with HX711, Load Cell and OLED (MicroPython)”

Leave a Comment