Build it step by step
0 of 6 doneMount the cells
Fix one end of each bar to the shelf and the other end to a tray.
Wire the amplifiers
Connect each cell to its HX711 and the HX711s to the ESP32.
Tare
With the trays empty send t1 and t2.
Calibrate
Put a known weight on a tray and send c1 followed by its mass in grams.
Set the item weight
Weigh one item and send u1 with its mass.
Open the page
Read the IP address and view the counts in a browser.
How do you build a shop shelf stock monitor?
Load cells under shelf trays tell a shopkeeper when stock is low, shown on a small web page. You need ESP32 DevKit V1, Load cell 5 kg (bar type) × 2, HX711 load cell amplifier × 2 and 5 V 2 A USB adapter. It takes 6 steps and about 180 minutes.
- Level
- Intermediate
- Time
- About 180 min
- Parts
- 4
Parts list
- Development BoardsBuyESP32 DevKit V1 × 1
- SensorsBuy
- SensorsBuy
- PowerBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Load cell 1 four wires | HX711 board 1 E+, E-, A+, A- | Shelf one |
| Load cell 2 four wires | HX711 board 2 E+, E-, A+, A- | Shelf two |
| HX711 1 DT, SCK | ESP32 GPIO16, GPIO17 | Data and clock |
| HX711 2 DT, SCK | ESP32 GPIO18, GPIO19 | Data and clock |
| Both HX711 VCC, GND | ESP32 3V3, GND | Power |
| 5 V USB adapter | ESP32 USB | Power |
Code
Arduino IDE with the ESP32 boards package, board "ESP32 Dev Module". Install "HX711" by bogde. Put your own Wi-Fi details in the placeholders. Mount each bar-type cell with one end fixed and the shelf tray on the free end, leaving the cell free to flex, and never load it beyond 5 kg. With the empty tray in place, send t1 or t2 to tare, then c1 500 with a known weight, and u1 with the weight of a single item. Counts are only as accurate as the item weights are consistent.
Runs on a virtual ESP32 Dev Module 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 <WiFi.h>
#include <WebServer.h>
#include <HX711.h>
#include <Preferences.h>
const char* WIFI_NAME = "YOUR_WIFI_NAME";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";
HX711 scale[2];
Preferences prefs;
float unitGrams[2] = { 100, 100 }; // weight of one item, set with the u command
int lowLimit[2] = { 5, 5 };
WebServer server(80);
int countOf(byte i) {
float grams = scale[i].get_units(5);
return max(0, (int)round(grams / unitGrams[i]));
}
void page() {
String html = "<meta http-equiv='refresh' content='30'><body style='font-family:sans-serif'><h2>Shelf stock</h2>";
for (byte i = 0; i < 2; i++) {
int c = countOf(i);
html += "<p>Shelf " + String(i + 1) + ": " + String(c) + " items";
if (c < lowLimit[i]) html += " <b>(low, reorder)</b>";
html += "</p>";
}
server.send(200, "text/html", html);
}
void setup() {
Serial.begin(115200);
scale[0].begin(16, 17); scale[1].begin(18, 19);
prefs.begin("shelf", false);
for (byte i = 0; i < 2; i++) {
scale[i].set_scale(prefs.getFloat(("cal" + String(i)).c_str(), 1.0));
unitGrams[i] = prefs.getFloat(("unit" + String(i)).c_str(), 100);
scale[i].tare();
}
WiFi.begin(WIFI_NAME, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) delay(500);
Serial.println(WiFi.localIP());
server.on("/", page);
server.begin();
}
void loop() {
server.handleClient();
// Serial commands: t1 tares shelf 1; c1 500 calibrates with a 500 g known weight; u1 120 sets item weight to 120 g
if (Serial.available()) {
char cmd = Serial.read(); int s = Serial.parseInt() - 1; float v = Serial.parseFloat();
if (s < 0 || s > 1) return;
if (cmd == 't') scale[s].tare();
if (cmd == 'c' && v > 0) { scale[s].set_scale(); float f = scale[s].get_units(10) / v; scale[s].set_scale(f); prefs.putFloat(("cal" + String(s)).c_str(), f); Serial.println(f); }
if (cmd == 'u' && v > 0) { unitGrams[s] = v; prefs.putFloat(("unit" + String(s)).c_str(), v); }
}
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual ESP32 Dev Module with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
192.168.1.42
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Empty trays | 0 items |
| Ten items of 100 g | About 10 items |
| Below the limit | Page says low, reorder |
| Reboot | Calibration is remembered |
If it does not work
Counts jump
Keep the tray still and use bars that are firmly mounted.
Negative or zero
Check the wire colours and that the load is in the arrow direction.
Wrong count
Re-weigh a single item and reset u.
Page not found
Check the IP address on the Serial Monitor.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the shop shelf stock monitor?
ESP32 DevKit V1, Load cell 5 kg (bar type) × 2, HX711 load cell amplifier × 2 and 5 V 2 A USB adapter.
How long does the shop shelf stock monitor take to build?
About 180 minutes for a intermediate maker, in 6 steps.
How do I know the shop shelf stock monitor works?
Empty trays: 0 items. Ten items of 100 g: About 10 items. Below the limit: Page says low, reorder.
Counts jump: what should I check?
Keep the tray still and use bars that are firmly mounted.
Negative or zero: what should I check?
Check the wire colours and that the load is in the arrow direction.
Wrong count: what should I check?
Re-weigh a single item and reset u.
Page not found: what should I check?
Check the IP address on the Serial Monitor.
