This tutorial outlines how to use an Arduino Uno microcontroller (or equivalent device) and load cell sensors to measure the weight of objects on a shelf. Being able to measure weight in this way is more efficient than weighing each item individually on a scale and calculating the total. Additionally, setting up these sensors and creating a “smart shelf” allows users to make inferences about the shelf’s capacity from a distance. This could be particularly helpful for folks in charge of keeping refrigerators, pantries, or other supply shelves stocked. NOTE: This tutorial is written for load cell sensors with maximum force measures of 5kg or 11lbs. The power source will need to be adjusted for other forces.
Parts List
- Arduino Uno (or equivalent)
- Arduino-to-USB cable
- The power supply of 5V
- Breadboard (optional)
- Load Cell (max force of 5kg or 11 lbs; pictured below)
- HX711 module
- 4 Male-Female jumper wires
- 4 Male-Male jumper wires
- Method of attachment for a particular use (i.e. screw and screwdriver, electrical tape, freezer tape, etc.)
Hardware Setup
A circuit diagram is included at the end of step 2 to assist with setup.
To connect the load cell sensor to Arduino, an HX711 module converter chip is used to provide a bridge voltage at a low cost while maintaining high precision. In this tutorial, a breadboard is used to stabilize the connection of the jumper wires to the module, but this step is not completely necessary.
Step 1: Connect the load cell wires to the HX711 module using 4 Male-Female jumper wires. NOTE: you may need to strip the load cell wires for them to fully connect.
The wires should be configured as such:
- Red E+
- White E-
- Black A-
- Green A+
Step 2: Connect the HX711 module to the Arduino microcontroller using 4 Male-Male jumper wires.
The wires should be configured as such:
HX711 Module | Arduino Uno |
Gnd | Gnd |
DT | Digital 3 |
SCK | Digital 2 |
Vcc | 5V |
Circuit Diagram
Step 3: Position the load cell.
Typically, there is an arrow on the load cell indicating the force direction. Attach the load cell to the bottom of the shelf with the arrow pointing down.
Attaching the load cell can be tricky depending on the shelf. Space is required between the load cell and the shelf in order for it to function properly. This is best achieved by attaching the load cell with a screw if possible. However, an easy way to avoid creating holes in your shelf is to use tape and/or a styrofoam piece to maintain the gap while still being able to attach the load cell to the shelf.
Arduino Configuration
Once everything is in place, it is time to set up the Arduino to properly take weight measurements. Think of this step as “zeroing out” a scale.
Step 1: Calibrating the HX711 module and initializing the weight at 0.
NOTE: you will need the HX711 library which can be downloaded as a zip file here under the “Schematics” section.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
/* Title: HX711 Calibration Description: The following code calibrates the HX711 module to the load cell's specific calibration factor. This sketch should be run WITHOUT a weight on the shelf. Code modified from: Hanie Kiani( https://electropeak.com/learn/) and Arduino Project Hub(https://create.arduino.cc/projecthub/electropeak/digital-force-gauge-weight-scale-w-loadcell-arduino-7a7fd5) */ #include "HX711.h" const int LOADCELL_DOUT_PIN = 3; const int LOADCELL_SCK_PIN = 2; HX711 scale; float calibration_factor = 40; // this calibration factor must be adjusted according to your load cell float units; void setup(){ Serial.begin(9600); scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN); Serial.println("HX711 calibration sketch"); Serial.println("Remove all weight from scale"); Serial.println("After readings begin, place known weight on scale"); Serial.println("Press + or a to increase calibration factor"); Serial.println("Press - or z to decrease calibration factor"); scale.set_scale(calibration_factor); //Adjust to this calibration factor scale.tare(); //Reset the scale to 0 long zero_factor = scale.read_average(); //Get a baseline reading Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects. Serial.println(zero_factor); } void loop(){ Serial.print("Reading"); units = scale.get_units(), 5; if (units < 0) { units = 0.00; } Serial.print("Weight: "); Serial.print(units); Serial.print(" grams"); Serial.print(" calibration_factor: "); Serial.print(calibration_factor); Serial.println(); if(Serial.available()) { char temp = Serial.read(); if(temp == '+' || temp == 'a') calibration_factor += 1; else if(temp == '-' || temp == 'z') calibration_factor -= 1; } if(Serial.available()) { char temp = Serial.read(); if(temp == 't' || temp == 'T') scale.tare(); //Reset the scale to zero } } |
Step 2: Measuring the weight of objects on a shelf. Place a few lightweight items on the shelf and then upload the following sketch to Arduino. The measured weights will print to the serial monitor.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
/* Title: Digital Weighing with Load Cell Description: The following code allows weight readings from a load cell to be printed to the Arduino serial monitor. Code from: Hanie kiani(https://electropeak.com/learn/) and Arduino Project Hub(https://create.arduino.cc/projecthub/electropeak/digital-force-gauge-weight-scale-w-loadcell-arduino-7a7fd5) */ #include "HX711.h" //You must have this library in your arduino library folder #define DOUT 3 #define CLK 5 HX711 scale; float calibration_factor = 40.00; // this calibration factor must be adjsuted according to your load cell float units; void setup() { Serial.begin(9600); scale.set_scale(calibration_factor); //Adjust to this calibration factor; } void loop() { units = scale.get_units(), 5; if (units < 0) { units = 0.00; } Serial.print("Weight: "); Serial.print(units,5); //displays the weight in 4 decimal places only for calibration Serial.print("grams"); // this may be adjusted according to your load cell if(Serial.available()) { char temp = Serial.read(); if(temp == 't' || temp == 'T') scale.tare(); //Reset the scale to zero } } |
Have fun!
Once you have weight measurements, the possibilities are endless! Measurements from the serial monitor can be exported to a log for safekeeping, combined with measurements from another sensor on the same or different shelves, or can even be displayed on a digital display.
References
Last Updated by Kristin Chang on April 03, 2022.
One reply on “Monitor shelf capacity with Arduino and load cell sensors”
Good