Build a Parcel Billing Station With 8x8 LiDAR and UNIHIKER K10
by Jaychouu in Circuits > Sensors
535 Views, 3 Favorites, 0 Comments
Build a Parcel Billing Station With 8x8 LiDAR and UNIHIKER K10
At a courier drop-off point during peak season, I watched staff repeat the same loop for every parcel. They put the parcel on a scale, measured length, width and height with a ruler, then guessed the billable weight. It was slow, and manual readings were easy to get wrong. I wanted to fold all of that into one device. So I built an automated parcel measurement station on the UNIHIKER K10. A parcel goes on the platform, an 8x8 matrix LiDAR ToF sensor above measures length, width and height, and a load cell below reads the actual weight. The system computes volumetric weight and reference billable weight, then shows a shipping-cost estimate on a built-in web page. No manual weighing, no ruler, no paperwork. You will build the same station and get all the numbers from one placement.
Supplies
1 x UNIHIKER K10
1 x Matrix Laser Distance Measurement Sensor (8x8)
1 x HX711 I2C weight sensor / load cell
1 x Gravity: I2C HUB
Wiring Connections
Use a 4-pin cable to connect the I2C Extensions module to the I2C interface on the UNIHIKER K10. Use Dupont wires to connect the 8x8 matrix tof 3D distance sensor and the HX711 weight sensor to the I2C Extensions module respectively.
Install the Two Libraries
First download and install Arduino IDE, and complete the Arduino development environment configuration for the UNIHIKER UNIHIKER K10. Only after installing the BSP corresponding to the UNIHIKER UNIHIKER K10 can the Arduino IDE recognize the UNIHIKER UNIHIKER K10 and complete program compilation and upload. For the specific installation process, refer to: https://www.unihiker.com.cn/wiki/k10/ArduinoIDE_prepare.
I start by installing the two libraries from Attachments into my Arduino libraries folder. The files are DFRobot_MatrixLidar.zip and DFRobot_HX711_I2C-master.zip. These are the official DFRobot releases for the Sensor and the weight sensor. Without them the sketch will not compile.
Parcel Dimension Measurement
First use the distance measurement function of the 8×8 matrix laser distance measurement Sensor to obtain distance information for 64 positions within the measurement area. The UNIHIKER UNIHIKER K10 then processes this depth data to determine the parcel's location and calculate length, width, and height. To make the measurement process more intuitive, the UNIHIKER K10 screen also displays the 8×8 detection area and the currently measured dimensions in real time. After completing this part, the system can automatically obtain the parcel's three-dimensional dimensions without using a ruler.
The entire dimension measurement is actually divided into two parts: height is obtained from the difference between the empty platform distance and the box top distance, while length and width are obtained from the parcel boundary position in the 8×8 depth map, combined with the field of view and box top distance for geometric projection.
Empty Scene Learning
Before placing a parcel, the system needs to perform an empty scene learning session to record the baseline distance from the Sensor to the empty platform. After the program starts, the 8\*8 matrix laser distance measurement Sensor continuously collects multiple frames of depth data and records the distances for 64 measurement zones respectively, obtaining a relatively stable background depth through median processing. After learning is complete, these 64 background distances serve as reference data for subsequently determining whether a parcel has appeared and calculating parcel height.
Converting Depth Distance to Length, Width, and Height
After completing empty scene learning, place the parcel on the platform. The system measures the distance from the Sensor to the top center of the parcel, for example 13.8 in. Compared with the previously learned empty platform distance of 500 mm, the parcel height can be directly obtained from the difference: 5.9 in.
Then, find the parcel's left, right, top, and bottom boundaries from the 8×8 depth data, and convert the boundary positions in the Sensor field of view into corresponding angles. For example, the left and right boundaries relative to the center are approximately \-15\.9° and 15\.9°, and the box top center distance is 13.8 in. Using trigonometric projection, the width can be calculated as approximately 7.9 in. Similarly, when the top and bottom boundaries relative to the center are approximately \-23\.2° and 23\.2°, the length can be calculated as approximately 11.8 in.
After the hardware connection is complete, connect the UNIHIKER K10 to the computer via USB cable, select UNIHIKER K10 as the development board in the Arduino IDE, select the corresponding serial port, then open the complete dimension measurement program and upload it.
After uploading the code, click the right arrow icon to start running and uploading
Complete Code for Dimension Measurement
The program first extracts the parcel area based on the difference between background depth and current depth, and retains the largest connected component to reduce noise interference. It then calculates the horizontal and vertical confidence distributions separately, and obtains the parcel's left, right, top, and bottom boundaries in the 8×8 grid through edge interpolation. Combined with the Sensor's 60° field of view, the grid boundaries are converted into spatial angles, and the measured parcel top distance is used to calculate the actual length and width through trigonometric projection. Parcel height is obtained from the difference between the empty platform background distance and the current parcel top distance. Finally, the larger horizontal dimension is taken as length, the smaller as width, and the three measurement results of length, width, and height are output.
Running Results :
Based on the data measured by the 8x8 matrix tof 3D distance sensor, the depth distance converted to length, width, and height is (12.0 in x 6.3 in x 5.9 in). The actual dimensions of the package are (11.8 in x 7.9 in x 5.9 in), both maintaining minimal error, demonstrating real-world reliability.
Adding Weight Detection Previously
The 8x8 matrix tof 3D distance sensor was used to complete automatic measurement of the package's length, width, and height. However, in the actual shipping process, dimension data alone is not enough to determine the final billable weight. This is because shipping billing typically also requires considering the actual weight of the package. For packages that are large in volume but light in weight, volumetric weight may also be used for calculation. Therefore, the next step is to add weight detection on top of the existing dimension measurement functionality, allowing the UNIHIKER K10 to obtain the actual weight of the package while measuring length, width, and height, and then combine the dimension and weight data to complete the calculation of volumetric weight and billable weight.
The weight detection part uses an I2C weight sensor. After the program starts, it first completes sensor initialization and no-load tare, then periodically reads weight data. Considering that the scale platform is affected by mechanical vibration and sensor noise, a single reading is prone to fluctuation. Therefore, the program first takes multiple samples from the sensor, then uses a 5-point median filter to remove instantaneous outliers, and also sets a zero dead zone to directly zero out fluctuations less than 5 g, thereby obtaining a more stable actual weight.
Weight sensor code:
An actual express shipping billing, there are volumetric weight and actual weight. The volumetric weight is obtained by first converting the measured package "length, width, height" units into feet, then calculating the package volume (unit: in3), then dividing the package volume by the volumetric divisor 166, and then comparing it with the actual weight of the package (unit: lb), taking the larger one as the billable weight, and then rounding up according to the set billing rules.
Billable weight source code:
Running Results
After adding the weight sensor, the measured actual weight of the package is 1.91 lb, while the measured package dimension data is (11.6 in x 6.7 in x 6.0 in) (each measurement may have slight fluctuations due to different placement positions, but this does not affect the final estimated charge). Therefore, the volumetric weight is (11.6 x 6.7 x 6 / 166) = 2.81 lb.
Serve the Web Interface
We have completed the automatic collection of the package's length, width, height, and actual weight, and the UNIHIKER K10 can also directly display the measurement results on the screen. In actual express shipping, it is also necessary to fill in sender and recipient information, select a courier company, and further estimate the shipping fee based on package dimensions and weight. Therefore, after completing dimension and weight detection, I used HTML, CSS, and JavaScript to add a real-time webpage. The data collected by the UNIHIKER K10 is sent to the computer via USB serial, and the webpage uses the browser's Web Serial API to directly read and parse the serial data, then displays the measurement results in real time on the page. The user then fills in the sender and recipient addresses and selects a courier company, and the webpage matches preset first-weight, additional-weight, and regional pricing rules based on the billable weight to calculate the estimated shipping fee.
We can download the HTML file (Attachment 3), double-click to open it, then click serial connection (at this time, the serial port in the Arduino IDE must be closed), and then the real-time data from the UNIHIKER K10 will be displayed on this interface. Then we can fill in the sender and recipient addresses and user information, and select the courier carrier and service mode.
Understand the Measurement Pipeline
Based on the regular shipping quotes published by common courier company platforms, a corresponding price table is created, corresponding to different charging standards, using the first-weight and additional-weight standard, with the first weight being 1KG. When the first weight is exceeded, the additional weight is charged. The additional weight fee varies depending on different carriers and the distance between the sender and recipient addresses. Any additional weight less than 1KG is calculated as 1KG. When the user selects the courier company to ship with, the system automatically calculates the corresponding estimated quote.
The current project is mainly used for prototype verification, so a local price table is used to simulate quotations. In the future, it can be further integrated with courier companies' official interfaces or third-party logistics APIs to enable real shipping cost queries and order placement. This extends the entire Project from "automatic measurement" to a complete workflow of "measurement + information entry + shipping cost estimation."
Final Vedio
The demo video is hosted on YouTube rather than committed here, to keep the repository small. It shows the full flow: empty-platform boot, parcel placement, and the web page updating with dimensions, weight and cost estimate.
Conclusion
This build taught me that an 8x8 ToF array is not about reading 64 distance values. It is about turning those discrete readings into meaningful dimensional information through empty-field learning, depth filtering, background subtraction, boundary extraction and triangular projection. Next I would add camera-based visual recognition for parcel shape, and I would integrate real logistics quotation interfaces. One pitfall: the platform must stay empty during startup, because the boot sequence learns the empty background and cannot measure correctly without it.