Andrew Shirley
Published © GPL3+

How to Weigh Multiple Items With a Microcontroller

Weighing objects with a microprocessor is explained, including using a multiplexer to weigh multiple items.

IntermediateWork in progress30 minutes324
How to Weigh Multiple Items With a Microcontroller

Things used in this project

Story

Read more

Schematics

Diagram of an ESP32 Connected to four HX711 Boards Through A Multiplexer

For the article found at https://andrewshirley.tech/how-to-weigh-stuff-with-a-microcontroller/

Code

For Platform.ini

JSON
; for Platform.io
lib_deps =
      bogde/HX711 @ ^0.7.5

ESP32 reading an HX711 Through a Multiplexer

C/C++
For the article at https://andrewshirley.tech/how-to-weigh-stuff-with-a-microcontroller/
#include "HX711.h"

// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 18;
const int LOADCELL_SCK_PIN = 19;
const long LOADCELL_OFFSET = 7135;
const long LOADCELL_DIVIDER = 207;
const int Mux_S0 = 5;
const int Mux_S1 = 23;          // HX711 Clock Pin

HX711 scale;

void setup() {
  Serial.begin(115200);

  pinMode(Mux_S0, OUTPUT);                            // Set S0 S1 to input/output 0
  digitalWrite(Mux_S0,0);
  pinMode(Mux_S1, OUTPUT);
  digitalWrite(Mux_S1,0);

  Serial.printf("\n\nTaring Scale\n");
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN, 32);    // Set gain to 32, uses B- and B+ on the HX711 Board
  //scale.set_gain(32);
  scale.tare(10);                      // Set ZERO using an averaged 10 readings
  scale.set_scale(LOADCELL_DIVIDER);   // Reads out in grams, approximately (for my test setup)
}

// CALCULATING SCALE:  ( scale.read() - scale.offset ) / KnownWeight
// Example:              ( 34811 - (-7209) ) / 203g = (  34811 + 7209  )  / 203g =  206
// scale.set_scale(206);

void loop() {

    Serial.printf("Raw:%ld Offset:%ld Scale:%f Corrected:%f\n",scale.read(), scale.get_offset(), scale.get_scale(), scale.get_units(5) );

}

Credits

Andrew Shirley
1 project • 0 followers
I've spent 23 years in Telecom. On the side, I program microprocessors and build electronics projects.
Contact

Comments

Please log in or sign up to comment.