ESP32 Scale
A high-precision digital scale powered by an ESP32, HX711 load cell amplifier, and an SSD1306 OLED display. Optimized for milligram-level accuracy and hardware stability.
Parts and sourceBefore you start
Check the exact OLED display configuration against the upstream wiring or parts list.
Upstream README
esp32-Scale
A high-precision digital scale powered by an ESP32, HX711 load cell amplifier, and an SSD1306 OLED display. Optimized for milligram-level accuracy and hardware stability.
✨ Features
- High Precision: 24-bit resolution with dual decimal place output (0.01g).
- Smart UI: Optimized 0.96" OLED interface for real-time weight monitoring.
- Reset Button: Fast and easy zero-setting (Tare) with one click.
🛠️ Hardware
- Controller: ESP32 DevKit V1
- Sensor: HX711 Load Cell Amplifier
- Display: SSD1306 128x64 I2C OLED
| Component | Image | Recommended Link |
|---|---|---|
| ESP32 DevKit V1 | ![]() |
Buy here |
| HX711 Amplifier | ![]() |
Buy here |
| Load Cell (100g) | ![]() |
Buy here |
| SSD1306 OLED (I2C) | ![]() |
Buy here |
| Push Button | ![]() |
Buy here |
🔌 Pin Connections
The ESP32 acts as the brain of the scale. Below is the wiring diagram for all components.
1. HX711 (Load Cell Amplifier) to ESP32
| HX711 Pin | ESP32 Pin | Description |
|---|---|---|
| VCC | 3.3V / VIN | Power Supply |
| GND | GND | Ground |
| DT | GPIO 18 | Data Pin |
| SCK | GPIO 19 | Clock Pin |
2. SSD1306 OLED Display (I2C) to ESP32
| OLED Pin | ESP32 Pin | Description |
|---|---|---|
| VCC | 3.3V | Power Supply |
| GND | GND | Ground |
| SCL | GPIO 22 | I2C Clock |
| SDA | GPIO 21 | I2C Data |
3. Tare Button
| Button Pin | ESP32 Pin | Description |
|---|---|---|
| (S) | GPIO 4 | Signal Pin (Input Pullup) |
| (-) | GND | Ground |
4. Load Cell to HX711
- Red: E+
- Black: E-
- White: A-
- Green: A+ (Note: Colors might vary depending on your specific load cell model)
🛠 Soldering 🛠
To make the scale durable and prevent loose connections (especially for the precise HX711), I soldered all components together.
💡 Soldering Tips
- Use Thin Wires: I used thin, strippable wires to connect everything without making a huge mess.
- Keep it Small: Solder the components directly or onto a small prototype board (Perfboard) to save space.
- Double-Check: Before you plug it into power, check all connections again to make sure you have no short circuits between 3.3V and GND!
🔍 Code Insights & Logic
Here is a breakdown of the core logic used in this project to ensure stability and precision.
🔌 1. Boot Stability (Setup)
The ESP32 can be picky with power. This setup ensures everything initializes correctly.
- Safety Buffer:
delay(2000)prevents crashes during boot if the power supply has a slow voltage ramp-up. - I2C Pin Definition:
Wire.begin(21, 22)manually sets the pins for the OLED to avoid conflicts with default ESP32 configurations. - Calibration: The
set_scalefactor that converts raw sensor data into grams.
⚡ 2. Speed-Tare (Interrupt Logic)
The reset button is handled via a Hardware Interrupt for instant response.
- IRAM_ATTR: This attribute forces the function into the ESP32's internal RAM. This means the CPU doesn't have to fetch it from flash memory, making the button response lag-free.
- Software Debouncing: We check
millis()to ensure the scale only tares once every 500ms, ignoring "ghost clicks" from the physical button.
⚖️ 3. Precision Measurement (Loop)
- Average Sampling:
get_units(5)takes five quick readings and calculates the mean to filter out electronic noise and vibrations. - Display Formatting:
dtostrfis used to force exactly 2 decimal places. Standardprintfunctions often struggle with precision formatting on microcontrollers.
💻 Software & IDE Setup ⚙️
To upload the code to your ESP32, follow these steps in the Arduino IDE:
1. ESP32 Board Setup
- Open File > Preferences.
- Paste this URL into "Additional Boards Manager URLs":
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json - Go to Tools > Board > Boards Manager and search for
esp32. - Recommended: Install the official version by Espressif Systems. It’s the most stable one for this project.
- Open File > Preferences.
- Paste this URL into "Additional Boards Manager URLs":
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json - Go to Tools > Board > Boards Manager and search for
esp32. - Recommended: Install the official version by Espressif Systems. It’s the most stable one for this project.
-
2. Choosing the Board
Select this board to make sure the pins work:
- Board:
DOIT ESP32 DEVKIT V1 - Upload Speed:
115200 -
- Port: Select the COM port where your ESP32 is plugged in.
3. Required Libraries
You need to install these libraries via the Library Manager (Tools > Manage Libraries):
- HX711 Arduino Library (by Bogdan Necula)
- U8g2 (by oliver) - for the OLED display
4. Get the Code & Flash it
You have two options here:
- Use my Code (Easy): Just download the
.inofile from this repository. It’s already optimized and ready to go. - DIY: You can also use the code as a base and add your own features if you like.
Steps to Flash:
- Connect the ESP32 via USB.
- Open the file in Arduino IDE.
- Hit Upload.
- Pro-Tip: If the console says "Connecting...", just hold the BOOT button on your ESP32 for a second until the upload starts.




