Machine scans and sorts peanut candies by density

Oct 26, 2026 Last reply: 17 hours ago 3 Replies
Jump to replies (3)

The toughest-looking piece of this build has to be turning a small spinning candy into a reliable volume number. Harrison McIntyre tackles it by sweeping a green line laser across the candy while it rotates a full 360 degrees on a stepper-driven turntable, then working out 3D coordinate contours through trigonometry to arrive at the volume. That is a genuinely satisfying way to solve the problem, and the calibration figure of 15.118 pixels per millimetre shows the kind of precision this approach demands.



The overall design leans heavily on a Raspberry Pi laser scanner project from Instructables, and it is built up from a Raspberry Pi plus an Arduino microcontroller, a camera module, and a 100g beam load cell with an HX711 amplifier for the weighing step. Two servo motors do the moving around: one pushes the scanned candy onto the load cell to record its mass in milligrams, and a second routes it down one of two chutes once the density, mass divided by volume, has been computed. Inside a black painted wooden box with a hinged lid there are cooling fans, lever wire nuts, a circuit board and tidy wire bundles. A delta 3D printer produced the custom brackets and chutes, and a laser cutter cut stencils along the way.



The touches that stand out to me are the labelled chutes reading Peanut and Solid, feeding external ceramic bowls marked Peanut and Chocolate, so the output is readable at a glance. A worked example on screen, 2100 mg divided by 1559 mm3 giving 1.35 mg/mm3, makes the method easy to follow.



As for results, out of roughly 200 scans the solid chocolate variant turned up 3.4% of the time, and sorting accuracy came in at 71.4% for solid candies and 75% for peanut ones. Those numbers leave room to grow. The maker has noted that a regression using density together with candy shape would likely be the next step if the project resumes, and the code is already on a Github repository for anyone who wants to dig in.



Project by Harrison McIntyre. Watch it on their YouTube channel:

formatting link


Calibrating the scanner to three decimal places, 15.118 pixels per millimetre, strikes me as exactly the right amount of care here. Volume feeds straight into the density result, so I reckon any sloppiness in the pixel scale would wash straight through to the sort decision. It reads as deliberate engineering rather than guesswork.

One thing I keep wondering about: when the second servo sends a candy down a chute, does the machine need any pause or reset before the next candy can be scanned, or can it run back-to-back? A candy sitting in the wrong spot at scan time seems like it would spoil the contour data.

A concrete idea for a next iteration: run the captured scan images through the volume tool in ImageJ and compare its output against the trigonometry-derived volumes. It is an open source image processing package, and a cross-check from an independent method could show whether the remaining errors come from the volume side or the mass side of the density division.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required