Contents — 26 sections
Project Overview
Weight-sensing shelves that always know how much stock is left and flag a shelf the moment it runs low — turning empty shelves into pre-empted restocks.
An empty shelf is a lost sale and an unhappy customer, and in most shops it is discovered only when a member of staff happens to walk past or a customer complains — by which point the product has already been out of stock for hours. The root problem is that shelves have no idea what is on them. This project fixes that by making the shelf itself a sensor: a weight-sensing shelf continuously measures the load on it, infers how many units remain, and flags the shelf the moment stock falls low — so restocking is triggered before the shelf empties, not after a customer finds it bare.
The method is elegantly simple: put the shelf (or a section of it) on a load cell — the same strain-gauge sensor used in electronic scales — read the weight through an HX711 amplifier, and divide by the known weight of one unit to estimate the count remaining. As shoppers take items the measured weight steps down, and when the estimated count (or weight) crosses a low-stock threshold, the shelf raises an alert for restocking. Networked, every shelf reports its stock live to a back-office dashboard, so staff see exactly which shelves need attention across the whole store.
The value is turning restocking from reactive to proactive: low stock is caught early and continuously, staff are directed to the specific shelves that need them, and out-of-stocks (and the lost sales they cause) drop. It is honest that weight-based counting is an estimate — it assumes reasonably uniform unit weights, needs taring and calibration, and is confused by mixed products or misplaced items — and that real retail also uses barcodes, RFID and vision. But as a self-sensing, low-stock-alerting weight shelf, it gives retail the one thing bare shelves never have: continuous awareness of their own stock, early enough to act on.
What this project does
- Continuously weighs a shelf to sense how much stock remains
- Estimates unit count from weight ÷ per-unit weight
- Flags a shelf the moment stock falls below a threshold
- Reports live stock per shelf to a back-office dashboard
- Directs staff to the specific shelves needing restock
- Triggers restocking before the shelf empties
- Cuts out-of-stocks and the lost sales they cause
Real-World Applications
| Setting | How it is used |
|---|---|
| Retail shelf replenishment | Proactive restocking of shelves before they empty. |
| Warehouse bin monitoring | Weight-based counts of parts/bins for reorder. |
| Vending / micro-market stock | Knowing remaining stock without opening the unit. |
| Inventory awareness | Continuous per-location stock for any uniform-weight product. |
Deployment contexts where a build of this kind earns its keep.
Features & Capabilities
- Load-cell + HX711 weight sensing
- Weight-to-count estimation with taring/calibration
- Low-stock threshold alerting
- Live per-shelf stock reporting
- Store-wide restock dashboard
- Sale/refill event detection from weight steps
- Honest about weight-estimate limits (uniform units)
Difficulty, Time & Required Skills
| Attribute | Value |
|---|---|
| Difficulty level | Intermediate |
| Estimated completion time | 10–16 hours |
| Indicative build cost | ₹1,200 – ₹2,500 per shelf |
| Primary discipline | Retail |
| Reference platform | ESP32 DevKit V1 (ESP-WROOM-32) |
Skills you should have (or will pick up)
- Load-cell + HX711 weight measurement
- Taring, calibration and weight-to-count conversion
- Threshold alerting and event (sale/refill) detection
- Networked per-shelf reporting
- Handling weight-estimate error and drift
Bill of Materials
Every part below is commonly available from Indian and international hobby-electronics suppliers. Prices are indicative 2026 retail figures in Indian rupees and will drift — treat them as a budgeting guide, not a quotation.
| Component | Key specification | Qty | Approx. cost |
|---|---|---|---|
| ESP32 DevKit V1 (ESP-WROOM-32) Wi-Fi transmit bursts peak near 500 mA — size the regulator accordingly. | Dual-core Xtensa LX6 @ 240 MHz, 520 KB SRAM, 4 MB flash, Wi-Fi 802.11 b/g/n + BLE 4.2, 34 GPIO, 18× 12-bit ADC, 2× 8-bit DAC | 1 | ₹450 |
| 5 kg load cell + HX711 24-bit ADC Mechanical mounting dominates accuracy — bolt it to a rigid plate, not plastic. | Strain-gauge bridge, 1.0 mV/V output, HX711 128× gain, 10/80 SPS | 1 | ₹320 |
| 0.96″ SSD1306 OLED display Static images burn in — invert or scroll the screen periodically. | 128 × 64 monochrome, 1.3–3.3 V logic, 100 kHz–400 kHz I²C | 1 | ₹250 |
| 18650 Li-ion cell 3400 mAh + holder Never charge below 0 °C; always use a protected cell or a BMS. | 3.7 V nominal, 4.2 V full, 3400 mAh, ~12.6 Wh, 2 C discharge | 1 | ₹450 |
| Load cell + HX711 The weight sensor | Strain-gauge load cell(s) + HX711 24-bit amplifier per shelf | 1 | ₹350 |
| Shelf mounting | Mount the shelf/section on the load cell(s) | 1 | ₹300 |
| Network + power | Wi-Fi to the dashboard, powered per shelf/gondola | 1 | ₹200 |
| Status indicator | LED/e-ink low-stock indicator on the shelf edge | 1 | ₹150 |
Estimated total: ₹2,470, excluding tools, shipping and consumables.
Tools and consumables
- Soldering iron (temperature controlled, 350 °C) with 0.8 mm 60/40 or lead-free solder
- Digital multimeter — continuity, DC volts and current ranges
- Wire strippers, flush cutters and a small set of precision screwdrivers
- Heat-shrink tubing and a heat gun (or a lighter, carefully)
- A laptop with a USB port and the toolchain listed above
Hardware Specifications
| Part | Specification | Supply | Interface | Reference |
|---|---|---|---|---|
| ESP32 DevKit V1 (ESP-WROOM-32) | Dual-core Xtensa LX6 @ 240 MHz, 520 KB SRAM, 4 MB flash, Wi-Fi 802.11 b/g/n + BLE 4.2, 34 GPIO, 18× 12-bit ADC, 2× 8-bit DAC | 3.3 V logic / 5 V USB | UART, SPI, I²C, I²S, CAN, PWM | Datasheet |
| 5 kg load cell + HX711 24-bit ADC | Strain-gauge bridge, 1.0 mV/V output, HX711 128× gain, 10/80 SPS | 2.6–5.5 V | 2-wire serial (bit-banged) | Datasheet |
| 0.96″ SSD1306 OLED display | 128 × 64 monochrome, 1.3–3.3 V logic, 100 kHz–400 kHz I²C | 3.3–5 V | I²C (0x3C) | Datasheet |
| 18650 Li-ion cell 3400 mAh + holder | 3.7 V nominal, 4.2 V full, 3400 mAh, ~12.6 Wh, 2 C discharge | 3.0–4.2 V | Holder / spot-welded tabs | Datasheet |
Consolidated electrical and interface specifications for every active part in the build.
Power Budget & Supply Sizing
Add up the typical active current of every part, then size the supply with at least 50 % headroom so transmit bursts and motor inrush never brown out the controller.
| Load | Supply rail | Typical current (mA) | Notes |
|---|---|---|---|
| ESP32 DevKit V1 (ESP-WROOM-32) | 3.3 V logic / 5 V USB | 160 | Wi-Fi transmit bursts peak near 500 mA — size the regulator accordingly. |
| 5 kg load cell + HX711 24-bit ADC | 2.6–5.5 V | 1.5 | Mechanical mounting dominates accuracy — bolt it to a rigid plate, not plastic. |
| 0.96″ SSD1306 OLED display | 3.3–5 V | 20 | Static images burn in — invert or scroll the screen periodically. |
Summed typical draw is 181.5 mA. With a 1.5× design margin the supply should deliver at least 300 mA continuously at the stated rail voltage.
Software Requirements & Development Environment
Reference toolchain: Arduino IDE 2.3.x with the ESP32 board package 3.x (or PlatformIO on VS Code). Anything newer normally works; anything older may lack the board definitions used here.
- Install the Arduino IDE 2.3.x (or PlatformIO if you prefer a real editor and dependency locking).
- Add
https://espressif.github.io/arduino-esp32/package_esp32_index.jsonunder File → Preferences → Additional Board Manager URLs, then install esp32 from the Boards Manager. - Set the correct port under Tools → Port. On Linux add yourself to the
dialoutgroup:sudo usermod -aG dialout $USERand log out and back in. - Open the Serial Monitor at 115200 baud — every sketch here logs its state there.
- Keep File → Preferences → Show verbose output during: compilation switched on while you are debugging build errors.
Required libraries
| Library | Why it is needed | Install |
|---|---|---|
| WiFi (ESP32 core) bundled | Station/AP connection management for the ESP32. | Bundled with the ESP32 Arduino core |
| HX711 0.7.x | Bit-banged 24-bit ADC read with tare and calibration factor. | Library Manager → "HX711" by Bogdan Necula |
| PubSubClient 2.8 | Lightweight MQTT 3.1.1 client for constrained devices. | Library Manager → "PubSubClient" by Nick O'Leary |
| Adafruit SSD1306 + GFX 2.5.x | Framebuffer and text/graphics primitives for the OLED. | Library Manager → "Adafruit SSD1306" |
| ArduinoJson 7.x | Zero-allocation JSON serialisation and parsing. | Library Manager → "ArduinoJson" by Benoit Blanchon |
Block Diagram
The block diagram shows the functional decomposition of the system — what senses, what decides, what acts, and where the data ends up.
Circuit Diagram & Wiring
Every signal line in the build is shown below, followed by a pin-by-pin connection table you can work through with a multimeter in hand.
| Peripheral | Peripheral pin | Controller pin | Signal |
|---|---|---|---|
| HX711 | DT/SCK | GPIO 16/17 | Weight (load cell) |
| OLED | SDA/SCL | GPIO 21/22 | Count/status |
| Low-stock LED | IN | GPIO 25 | Shelf indicator |
| Wi-Fi | onboard | — | Dashboard link |
| Supply | 5V | 5V | Power |
| Tare button | IN | GPIO 26 | Zero/refill |
Wire one row at a time and tick it off — most "it does not work" reports trace back to a single swapped pair.
Wiring explanation
- Mount the shelf (or a section) on the load cell(s) so the product weight bears cleanly on them.
- Read the load cell via the HX711 24-bit amplifier; keep wiring short and stable to reduce noise.
- Provide a tare/refill action to zero the shelf and register a restock.
- Network to the back-office dashboard; add an on-shelf low-stock indicator.
- Isolate the load cell from vibration/knocks that would add weight noise.
System Architecture
Read the stack from the bottom up: physical hardware, the firmware that drives it, the transport that moves data off the device, and the software a human actually looks at.
Working Principle
Out-of-stocks are expensive and, in most stores, invisible until too late — because a shelf is a dumb surface that reports nothing about what sits on it. The insight of the smart shelf is to give the shelf a sense of its own contents, continuously, so the store learns a product is running low while there is still time to restock rather than after a customer finds it gone. Weight is the ideal sense for this: it is continuous, needs no per-item tagging, and directly tracks how much product remains.
The measurement chain is the same as any electronic scale. A load cell is a metal element with strain gauges bonded to it; under load it flexes microscopically, the gauges change resistance in proportion, and this tiny change is read as a weight. Because the signal is minute, it is amplified and digitised by a dedicated 24-bit converter, the HX711, giving a stable, high-resolution weight reading. Put the shelf on the load cell and you have a continuous measurement of the total product weight on it — the raw signal everything else is derived from.
Turning weight into stock count requires two calibrations and a division. Taring subtracts the fixed weight of the empty shelf and fixtures so only the product weight remains. Calibration establishes the scale factor (raw units per gram) using a known weight. Then, dividing the net product weight by the known weight of one unit gives the estimated number of units remaining. As shoppers remove items, the weight steps down in unit-sized decrements, and the count follows; a sudden jump up is a refill. This is also how the shelf can infer sale and refill events — from the direction and size of weight steps — not just a static count.
The action is threshold alerting and store-wide visibility. When the estimated count (or net weight) falls below a low-stock threshold, the shelf raises a restock flag — on an edge indicator and, networked, on a back-office dashboard that shows every shelf's live stock, so staff are directed to exactly the shelves that need them. Restocking becomes proactive and targeted instead of reactive and store-walking. The design is honest about the method's limits: weight-based counting is an estimate that assumes reasonably uniform unit weights, so it is confused by mixed products on one sensor, items placed on the wrong shelf, or highly variable unit weights; it needs periodic re-taring and calibration to counter drift; and precise, per-SKU retail inventory also uses barcodes, RFID and vision. But for the specific, high-value job of knowing when a shelf of a uniform product is running low, early and continuously, a weight-sensing shelf gives retail exactly the awareness that bare shelves have always lacked.
The maths behind it
Weight to count
net_weight = raw_reading × scale − tare
count ≈ round( net_weight / unit_weight )
Tare removes the empty-shelf weight; scale (from calibration)
converts raw units to grams; unit_weight turns grams into
number of items.
Low-stock alert
low if count ≤ COUNT_MIN (or net_weight ≤ WEIGHT_MIN)
Set COUNT_MIN so restocking is triggered with enough lead
time to refill BEFORE the shelf empties.
Sale / refill from weight steps
Δ = net_weight(now) − net_weight(prev)
Δ ≈ −k·unit_weight (k>0) → k units SOLD
Δ ≈ +m·unit_weight (m>0) → m units REFILLED → clear alert
Ignore |Δ| below a noise floor (hands, knocks).
Program Flowchart
The firmware is a single cooperative loop. Nothing blocks for long, so networking, sensing and the user interface all stay responsive.
Assembly Instructions
Build on a breadboard first and only commit to solder once the whole system has run for an hour without a fault.
Mount the shelf on load cells and read weight
Mount the shelf/section on the load cell(s) so product weight bears cleanly, and read it through the HX711 with stable, short wiring.
Tare, calibrate and convert to count
Tare the empty shelf, calibrate the scale factor with a known weight, and divide net weight by the per-unit weight to estimate count.
Add alerting and reporting
Set the low-stock threshold, raise restock flags, detect refills to clear them, and report live stock to the dashboard.
Step-by-Step Implementation Guide
Work through these in order. Each step ends in something you can observe, so a failure is always localised to the step you just finished.
Estimate count and detect sale/refill
Convert the net weight to a unit count, and infer sale/refill events from the size and direction of weight steps.
cppshelf.inofloat scale = 420.0; // raw units per gram (from calibration) long tare = 0; // empty-shelf zero float unitWeight = 250.0; // grams per unit (known) float prevNet = 0; const int COUNT_MIN = 3; float netWeight(long raw){ return (raw - tare) / scale; } // grams int countFrom(float net){ return (int)roundf(net / unitWeight); } // Infer a stock event from the weight step since last reading. const char* stockEvent(float net){ float d = net - prevNet; if (fabs(d) < unitWeight * 0.4) return nullptr; // noise floor int units = (int)roundf(fabs(d) / unitWeight); prevNet = net; return d < 0 ? "sold" : "refilled"; // + = refill } bool lowStock(float net){ return countFrom(net) <= COUNT_MIN; }float netWeight(long raw){ return (raw - tare) / scale; } // gramsTaring and the calibrated scale turn the raw HX711 reading into the actual product weight on the shelf.int countFrom(float net){ return (int)roundf(net / unitWeight); }Dividing net weight by the known per-unit weight estimates how many units remain — the core weight-to-count step.if (fabs(d) < unitWeight * 0.4) return nullptr; // noise floorA noise floor ignores small wobbles (a hand resting, a knock) so only real unit-sized changes register as events.return d < 0 ? "sold" : "refilled"; // + = refillThe direction of a weight step tells sale from refill — a jump up clears the low-stock alert.Alert low stock and report per shelf
Flag the shelf when the count crosses the low threshold, clear it on a refill, and report live stock to the back-office dashboard so staff go to the right shelves.
Complete Source Code
The listing below is complete and compiles as written — there are no elided sections. Read the annotations under each block before you upload it.
/* ═══════════════════════════════════════════════════════════════
Smart Shelf Stock Sensor — ESP32 + load cell (HX711)
Weighs a shelf continuously, estimates units remaining from weight,
flags low stock BEFORE the shelf empties, detects sale/refill from
weight steps, and reports live per-shelf stock to a dashboard.
Weight counting is an estimate — assumes fairly uniform units.
══════════════════════════════════════════════════════════════════ */
#include "HX711.h"
HX711 scaleADC;
const char* SHELF = "A12";
float scale = 420.0, unitWeight = 250.0, prevNet = 0;
long tare = 0;
const int COUNT_MIN = 3;
bool alerted = false;
float netWeight(){ return (scaleADC.read_average(5) - tare) / scale; }
int count(float net){ return (int)roundf(net / unitWeight); }
void report(const char* event, float net, int c){
char m[160];
snprintf(m,sizeof m,
"{\"shelf\":\"%s\",\"grams\":%.0f,\"count\":%d,\"event\":\"%s\"}",
SHELF, net, c, event ? event : "none");
mqttPublish("shelf/stock", m); // live to dashboard
}
void setup(){
scaleADC.begin(16,17);
tare = scaleADC.read_average(20); // zero the empty shelf
wifiConnect(); mqttConnect();
}
void loop(){
float net = netWeight();
int c = count(net);
// sale/refill from the weight step
float d = net - prevNet; const char* ev = nullptr;
if (fabs(d) >= unitWeight*0.4){
ev = d < 0 ? "sold" : "refilled"; prevNet = net;
if (d > 0) alerted = false; // refill clears the alert
}
if (c <= COUNT_MIN && !alerted){ // low: flag BEFORE empty
digitalWrite(25, HIGH); // on-shelf indicator
report("low_stock", net, c);
alerted = true;
} else if (c > COUNT_MIN){
digitalWrite(25, LOW);
}
report(ev, net, c); // continuous stock report
delay(2000);
}
Configuration & Calibration
Configuration steps
- Configure the HX711 pins, scale factor and per-unit weight per shelf/product.
- Configure the tare/refill action and the low-stock threshold.
- Configure the dashboard link and per-shelf reporting.
- Configure the weight-step noise floor for sale/refill detection.
Calibration procedure
An uncalibrated sensor produces confident, precise, wrong numbers. Do this once per physical unit and record the constants.
Scale calibration
Calibrate the scale factor with a known weight so grams are accurate.
Taring
Tare the empty shelf and re-tare after fixture changes; guard against drift.
Unit weight
Set the per-unit weight accurately; verify the count matches a manual count at a couple of levels.
Network Architecture & Connectivity
Communication protocol
Shelves publish live stock and sale/refill events; the dashboard aggregates them into a store-wide restock view.
| Topic / endpoint | Direction | Payload |
|---|---|---|
shelf/stock | shelf → dashboard | shelf, grams, count, event |
shelf/alert | shelf → staff | low-stock flag |
shelf/refill | shelf → dashboard | restock confirmation |
Message contract between the device and the broker.
Cloud platform configuration
A back-office dashboard shows live stock per shelf, low-stock alerts, and out-of-stock/replenishment KPIs across the store.
Dashboard setup
A store map/list of shelves with live counts, low-stock flags and a prioritised restock list.
Mobile app integration
Restock alerts to staff with the specific shelves needing attention.
Security considerations
- Authenticate shelves; secure stock telemetry.
- Stock data is operational — protect against tampering.
- Weight counting is an estimate; combine with barcodes/RFID for precision.
Testing Procedure & Expected Output
Test from the bottom up. Confirm power, then each sensor in isolation, then the integrated loop — the first failing step tells you exactly where to look.
| Test | What you should see |
|---|---|
| Place a known number of units | Count matches (calibration good) |
| Remove one unit | Count drops by one; "sold" event |
| Draw down to threshold | Low-stock flag + dashboard alert |
| Refill the shelf | Count rises; "refilled"; alert clears |
| Rest a hand on the shelf | Below noise floor — no false event |
| Mix in a different product | Count off — note uniform-weight limit |
Bench-test checklist. If a row fails, stop and fix it before moving on.
Expected output
Live per-shelf stock, low-stock flags before shelves empty, and sale/refill events — on the shelf and on a store dashboard.
{
"shelf": "A12",
"grams": 720,
"count": 3,
"event": "sold",
"state": "low_stock"
}
Shelf A12 is down to 3 units after a sale and has flagged low stock — the restock is triggered with units still on the shelf, before any customer finds it empty.
Troubleshooting: Common Errors & Fixes
Performance Optimisation
- Tare and calibrate so counts are accurate; re-tare against drift.
- Use a noise floor so only real unit changes register.
- Alert with restock lead time, before the shelf empties.
- Report live per-shelf so staff are directed precisely.
- Replace every
delay()with amillis()comparison — blocking delays are the single most common cause of dropped readings. - Sample sensors on a fixed cadence and publish on a slower one; you almost never need to transmit at the sampling rate.
- Move networking into its own FreeRTOS task so a slow DNS lookup cannot stall the control loop.
- Use
uint8_t/uint16_twhere the range allows; on an 8-bit AVR a 32-bit add costs four times as much. - Batch several samples into one MQTT publish. Radio time, not CPU time, dominates the energy budget.
- Set the MQTT keep-alive to a value that matches your reporting interval so the broker does not churn reconnections.
- For battery builds use deep sleep between samples: an ESP32 drops from ~160 mA awake to about 10 µA asleep, which is the difference between days and months of runtime.
Safety Precautions
- Weight counting is an estimate — do not treat it as exact per-SKU inventory; combine with barcodes/RFID where precision matters.
- Mount shelves and sensors so a failure cannot drop stock or injure.
- Secure the network and dashboard against stock-data tampering.
- Re-calibrate/tare regularly to keep alerts trustworthy.
- Lithium cells vent and burn when abused. Only use protected cells or a proper BMS, never charge below 0 °C, and never leave a charging pack unattended on a wooden desk.
- Wear eye protection when soldering or cutting, and solder in a ventilated space — rosin flux fumes are a respiratory irritant.
- Power the circuit through a bench supply with a current limit while you are testing. A 300 mA limit turns a wiring mistake into a beep instead of a dead board.
- Disconnect power before changing any wiring. Hot-plugging a sensor onto a live bus is the fastest way to lose a controller.
Maintenance
- Re-tare and re-calibrate periodically to counter drift.
- Update per-unit weights when products/packaging change.
- Check load-cell mounting and wiring for noise.
- Review alert timing so restocks stay proactive.
- Re-check every screw terminal and header after the first week — thermal cycling loosens connections that felt tight on day one.
- Log pack voltage. When resting voltage after a full charge drops below about 4.0 V, the cell is near end of life — replace it.
- Keep the broker and dashboard containers patched, and rotate device credentials at least once a year.
- Recalibrate at the interval given in the calibration section, and keep the constants in a text file next to the firmware — not only in flash.
- Keep a short logbook of firmware versions and what changed. Six months later you will not remember why that constant is 1.083.
Future Improvements & Upgrades
A working v1 is a platform, not a finish line. These are the upgrades that add the most capability for the least rework.
- Combine weight with barcode/RFID for per-SKU accuracy.
- Add demand/auto-reorder from sale-rate trends.
- Add planogram compliance (right product on the shelf).
- Add e-ink shelf labels showing live stock/price.
- Design a proper PCB. Once the breadboard version has run for a month, moving to a two-layer board removes the intermittent-contact failures that dominate prototype faults.
- Add over-the-air firmware updates so you never have to physically reach a deployed node again.
- Add persistent local storage (microSD or the on-chip flash) so a network outage does not create a hole in your data.
- Move configuration out of the source: a captive-portal setup page or a JSON config file makes the build reusable without a recompile.
- Add a battery and solar option so the unit survives a power cut and can be sited away from a socket.
- Write a small test harness that feeds synthetic sensor values through the decision logic, so you can validate thresholds without physically triggering the event.
Frequently Asked Questions
References & Learning Resources
These are the primary sources worth reading in full. Manufacturer datasheets always outrank forum posts when the two disagree.
- Load cell / strain gaugeReference
- HX711 24-bit ADCDatasheet
- Retail out-of-stockReference
- Inventory managementReference
- Smart shelfReference