Open Source Coffee Sorter Machine Design (V1.0)

This topic is a linked part of a larger work: “Open source optical coffee sorter project”.

Contains documentation for version 1 of the Open Source Coffee Sorter machine, from a user point of view (parts to get, assembly, usage etc.). All design decisions and the development process are documented in the project topic instead.


1. Overview

2. Usage

3. Bill of Materials


5. Assembly

1. Overview

We have arrived at a first, rough machine design, to be discussed / explored / improved. Note that this is still in the design / planning stage: no machine has been built yet, but we’re close to that now as the planning work below is nearly finished.

3D view of the structural parts (in the current state of the design work):

And a quick sketch of the machine parts and a description of their function:

The numbered parts and their function:

  1. Feed funnel. Coffee beans “flow” easily, so a simple funnel is enough to feed them in. No vibration is needed if the vertical tube after the funnel has a large enough diameter (50 mm is for sure enough). A grid sieve to keep out large foreign objects (such as branch pieces) is needed to protect the interior of the machine.

  2. Slow conveyor. The feed tube ends ca. 10 mm above a first conveyor belt. It is wide but moves slowly, moving 1-2 layers of beans.

  3. Guide funnel. Guides the beans to the center of the fast conveyor as they fall off the slow conveyor.

  4. Fast conveyor. To separate the beans, they fall off the slow conveyor onto a fast-moving one that is only wide enough for one bean at a time (assume 25 mm so there is enough space for the occasional foreign object, such as branch pieces). By moving faster and catching the falling beans from the slow one, beans will be spread out one after another on this conveyor. For a target of 100 beans per second and an average two-bean distance between beans, the speed of the conveyor would have to be 300 bean lengths per second, so 300 cm for an average bean length of 10 mm. 3 m/s is equivalent to 10.8 km/h. Might be too fast for a simple machine, in which case the capacity would be lower. But if we can achieve 100 beans / second this way, it would be equivalent to a throughput of 1.5 tons per day (see here, section 4.2).

  5. Linear solenoids. They move sideways across the fast conveyor and have brushes attached to a lever by which they can move the beans into destination bins. This setup allows for any number of bins, unlike when directing the beans into an upper or lower bin when they fall off the end of the conveyor. In our case, we want three solenoids (of which only one is shown in the sketch). This allows four bins together with the end of the conveyor belt as final destination. Normal usage: (1) bad beans, (2) undecidable beans, (3) low-quality beans, (4) high quality beans.

  6. Output funnel. Guides the beans to one of the output bins. Similar to the bean guides after the solenoids, but this time for the end of the conveyor belt.

  7. Camera. Captures images of the beans while they are moving on the slow conveyor. An LED flasher will help to keep the images sharp even though the beans are moving with quite some speed.

For illustration, a 3D sketch of the path of the coffee beans through the machine:

Electrical schematics for the coffee sorter by @mmajdeb (components roughly as in the side view drawing above):

2. Usage

Programs planned for the “version 1.0” machine:

  • Standard program. The standard program sorts coffee beans into “bad, good and great” coffee beans. There are multiple versions or configurations, accessibly form a menu and sorted by coffee plant variety, country and growing altitude. It uses a quick, color based decision algorithm (targeting 100 beans / second), which is adequate for “normal commercial coffee” but not as exact as it can be with the coffee sorter’s hardware. This is the only program that will be available in the “version 1.0” machine, but

  • Standard training program. Training the machine with ones own beans will allow the most accurate sorting, but it needs manually sorted beans as input (good and bad ones) and some CPU time. A program on the Raspberry Pi will receive image data and calculate the configuration parameters for the color sorting algorithm.

Programs planned as later additions: The coffee sorter is also able to run other programs for specialized purposes and higher requirements. We can think of at least the following, which will be prepared in the software architecture of the version 1.0 machine, but implemented later:

  • Maximum accuracy sorting. In contrast to the quick standard program that relies on color sorting, this program can also rely on an AI image classifier when unsure, or even exclusively, then using the AI image classifier for every bean. It would achieve a throughput of ≤10 beans per second; while that is much slower than the 100 beans per second of the color sorting algorithm, it is still acceptable as the people using it for this purpose can invest 3000 EUR to run 10 machines in parallel, again achieving 100 beans per second (equiv. 1.5 t/day).

  • Training program for maximum accuracy sorting. This is effectively about training a neural network model. It requires a network connection and a server (on the local network or the Internet) that will receive the image data and calculate the neural network model, then offering it for download. This cannot be done on the Raspberry Pi, as it would simply take too long. Using the server on the Internet will be free of charge, but in exchange the coffee bean images and the resulting model will be open source licensed.

  • Flavor sorting. This is a hypothetical use case: with some cupping experiments, it should be possible to train an AI image classifier to sort beans by flavor profile, using combinations of attributes / hints that are not obvious to the human eye.

  • Size sorting. In larger quantities, sorting by size will be done with sieves, but for small farms, the optical coffee sorter can easily take over that task as well. With its four outputs, it can separate three sizes and a remainder, which is then fed back in to separate out another three sizes and so on.

Serial operation. When running a special program with many different output types (esp. size sorting), one can feed back the remainder into the same machine to separate out additional output types or (faster) feed it right into the input funnel of another, identical machine. The machine dimensions and the funnels will be designed to allow this.

Scaling. The machine has a narrow format (only 5-10 cm wide), because the idea is to operate many machines in parallel if there is a need. All would be fed from the same feed tube, if necessary with a steep slope to cover longer distances. Similarly, the four outputs can be collected by parallel sloped tubes running under the bottom of these machines.

Redundancy. Operating multiple machines in parallel has the advantage of high redundancy, as the machines operate independently. So when one machine breaks, one can simply keep operating the others without issue, while taking out and repairing the broken one and putting it back in. Of course the output will be lower while not all machines are active, but the idea with redundancy is that the highest capacity should be more than required. Redundancy is a better way to deal with failure than having a spare machine around: having a spare machine would need investment costs for twice the required processing capacity, while redundancy requires only (say) 120% processing capacity in the case of six mutually redundant machines. In addition, redundancy can deal with multiple failures (“four of six machines broken”), and when spare parts are not readily available, allows to combine broken machines with complementary defects into working ones.

3. Bill of Materials

  • funnel assembly

    • CNC cut parts, plywood or plastic
  • casing
    We want the casing (without the funnel) to fit inside a typical 600×400 mm Euro container made from plastic. It will allow for simple and cheap transport on pallets, protect the machine during any transport and protect it during storage against rain, dust, humidity etc… Due to the standardized internal dimensions of Euro containers, the machine’s side face should not exceed 540×360 mm in size. The width of the machine is rather unrestricted as Euro containers come in various heights. However, 10 cm width seems a reasonably achievable limit.

    • CNC cut parts, plywood or plastic
    • nuts and bolts, stainless steel
  • upper conveyor assembly

    • 1 belt, 25 - 75 mm wide
    • 2 axles, with bearings
    • 1 stepper motor, 5 V DC
      We use a stepper motor instead of a simple DC motor to create more opportunities to improve the machine using better software. Among stepper motors, a 5 V motor seems best: they are readily available and can work with a cheap motor driver board without current limiting, such as the Adafruit 2348 board we have selected. And using 5 V products has the advantage that it can be the standard voltage of the machine, introduced by the requirement of the Raspberry Pi (“4.75 - 5.25 V”). So we will only need one 5 V power supply for the whole machine, reducing costs.
        Examples of suitable motors: Minebea 17PM-K031-02V (here and here), Nippon Pulse Motor PF35T-48 (here), generic 5 V / 416 mA stepper (here).
    • CNC cut parts, plywood or plastic
  • lower conveyor assembly

    • 1 belt, 25 mm wide
    • 2 axles, with bearings
    • 1 stepper motor, 5 V DC
      A 5 V stepper motor seems best, see above.
    • CNC cut parts, plywood or plastic
  • gates assembly

    • 3 linear solenoids, 5 V DC
      Linear solenoids are a common type of electromagnetic actuator (introduction). Among them, 5 V solenoids are quite common and cheap, and suitable for the light task here of “just moving one coffee bean”. Using 5 V products has the advantage that it can be the standard voltage of the machine, introduced by the requirement of the Raspberry Pi (“4.75 - 5.25 V”). So we will only need one 5 V power supply for the whole machine, reducing costs. Suitable example products: 1, 2, 3, 4.
    • CNC cut parts, plywood or plastic
  • camera assembly

    • 1 camera, UVC interface, not yet chosen, a camera for testing is available by using an Android phone and software that provides UVC access to its camera
    • 1 LED flasher, white LEDs, ca. 6000 K color temperature (“cool white”), for camera imaging of the coffee beans in motion. Current proposal is the Adafruit 2433 DotStar LED Strip, or the same LEDs bought individually and mounted on suitable breakout boards. In both cases, the LEDs are addressable, so can be individually dimmed and switched on / off. Communication with these DotStar LEDs uses 2-wire SPI, so does not create realtime requirements for the microprocessor. As controlling these LEDs seems simple, it seems a good capability of the machine. Because with the same technique, other additional LEDs could be added and controlled as well lateron, extending the lighting setup to multi-spectral and IR imaging.
  • electronics

    • 1 AC adapter, 5 V DC, ≥8 A, Adafruit 658 (25 USD)
      Only one AC adapter is needed, as the whole machine will run on 5 V DC (Raspberry Pi, stepper motors, solenoid, camera. This reduces cost, complexity and points of failure. We currently have a “Rydges SpeedPower 100-240 V to 5 V 2.5 A” available that is sufficient for the Raspberry Pi, but will need a more powerful one for the whole machine: about 2.5 A for the Raspberry Pi incl. camera, 1 A per stepper motor, 1 A per solenoid. This power is normally never needed all at the same time, but over-dimensioning this does not hurt, as it makes the AC adaptor last longer.
    • 1 Raspbery Pi 3, available
    • 2 motor driver boards, I2C interface, Adafruit 2348 “DC & Stepper Motor HAT for Raspberry Pi”, also known as “Adafruit Motor HAT” and “Adafruit DC and Stepper Motor HAT” (see). Available.
        These boards come with: product info page, support page, manual, open source PCB schematics, Python library (only depending on a GPIO library), demo program in C#. There seems to be no C library, but Adafruit has a very similar board for Arduino (“Adafruit Motor Shield v2”), which comes with a C++ library.
        The Adafruit 2348 motor HAT has no integrated current limiting, so it cannot be used with some types of stepper motors that require this. (Proof: The manual (p. 6) mentions that the board uses the TB6612 MOSFET driver. And in another document, Adafruit mentions that this chip has no current limiting.)
        We intend to use these boards both for controlling the motors and the linear solenoids, instead of a relay board for the latter. This should be possible, as Adafruit mentions for a board using the same TB6612 MOSFET driver that it can “fire four solenoids, spin two DC motors or step one … stepper with 1.2A per channel”. After all, PWM output with 100% duty cycle is the same output as a relay would provide. Note that circuits with solenoids have to be protected against inductive kickbacks, but the TB6612 already includes built-in kick-back diodes (see here, p. 4) so no special protection has to be added.
        One four-channel board is only enough for the two stepper motors, so we need two; the second would be able to fire up to eight solenoids (somehow). The advantage of two boards is redundancy (between machines) and fewer spare parts to organize. Also this way, there are several unused output channels for future uses or user-made changes. In addition, we get a MOSFET based design instead of relays, which should increase reliability by having fewer mechanical parts.


All data associated with the project is available on Github:

There is no software to control the machine yet, but a few useful bits and pieces:

5. Assembly



Very good Job.

As the price should be quite low, maybe one of each producer would want to have its own sorter. It is better to have one’s own sorter at home, as you don’t have to move a distance to sort your beans. Redundancy would be achieved by lending machines in between producer in the case one is broken.
Small producers don’t have a big amount of beans.

My friend only produces between 100 to 400kg a year, so he would use in priority the slow motion in order to achieve best quality.

Thanks for the job.


Great idea about lending the machines for redundancy. I had not thought about that yet. I think to facilitate this, we should design the machine so that it can be easily disconnected from inlet and outlets, which would stay in place. You’d just exchange the machine like a cartridge.

And yes, having a small machine at home or moving the machine around is indeed better than moving the beans. We experienced the same issue among the coffee farmers from Hansapur, Nepal that we work with. There is a coffee pulper in the next village but due to the steep terrain (3 km by air, 2 hours on foot …) it is not accessible to them. So they do even the pulping by hand so far … fortunately a pulper is only 250 USD, so this can be solved relatively easily …

@matthias would PULP ( & GitHub - pulp-platform/pulpino: An open-source microcontroller system based on RISC-V ) be an interesting alternative for your electronic architecture?

I suspect this would require that you leave behind the most basic cameras, and look into the near infrared spectroscopy → Application of infrared spectral techniques on quality and compositional attributes of coffee: An overview - ScienceDirect

Oh … that’s a great hint, @markomanka. Thank you!

We may even have luck with a normal digital camera module in the near infrared spectrum. Seems promising enough to try some experiments. Compare for example this IR illuminated image taken by a the “official” Raspberry Pi v1 camera module. (Listed here, with more test images and some background info.)

Indeed, most photographic CMOS sensors are far more sensitive in the IR spectrum than in the visible light… if you remove the filters placed by producers, you should get good IR images… Most modern CMOS should also allow you to do reasonably good spectrometry…

You will have to consider whether it is more cost-effective to have a high end CMOS, with higher precision and pixel density for statistical purposes, or whether you would rather invest in light sources (timed strobing, spectrum balance, …) and then put the software on steroids (compressive sensing)…

1 Like

Great work, @matthias!

How does sorting into three categories mesh with classifiers, that are binary by definition? Are you planning on sorting the bad beans out first, then reclassifying the non-bad ones into good and great?

Classifiers can do more than binary decisions. You give them an image, and (depending on their training of course) they give you a list of categories and probabilities of a match for each (online demo).

We interpret the category with the highest probability as the match (“what the software sees”), except the probability is too low (say <0.9) or there is too little difference between the match and the opposite category (e.g. “good bean: 0.96, bad bean: 0.91”). In these cases, the bean goes into the “unsure” bin, to be used for additional training after manual sorting.

I know, Matt. But the statistical properties of multivariate dependent variables are way less favorable than those of bivariate ones. You buy granularity, at the expense of a lot of explanatory power (lower pseudo-R squares).

Again, I am thinking statistics (multilogit vs. sequenced multiple logits) rather than neural networks, of whose unbiasedness/consistency properties I know nothing. But that kind of stuff is fundamental; when you change the tool, the trouble manifests differently, but it does not go away.

@imake I added a proposal for the programming language(s) of the project above, in section “4.1. Programming language”. See if you agree, feedback welcome. We can start with actual development once this is settled.

I could take on the C development part. Until a minimal machine control part in C is ready, you might want to work on some type of user interface beyond the obvious “start / stop button”. Maybe a web-based interface would work best, accessible with users’ smartphones? Not sure …

1 Like

Sounds good to me. If we are to go with a web-based interface then we either need the sorter to create its own wifi network or connect to an existing wifi network. Bluetooth + mobile app could be another option as well, but that might be more time consuming to develop. Let’s talk more about what’s necessary in that interface offline.

1 Like

Let me congratulate you on your quest to make technology available to probably the least researched industry in the world: coffee. I am a coffee farmer in El Salvador and I’ve been in the market for some time for a optical coffee sorter only to find that it will take me several years of hard work to pay for such a machine. I have a few inputs
try to make some of the inner parts with 3d printers so parts could be printed locally and also try to make the machine with different price points maybe the premium products could sponsor other more simple units locally, your 300 usd price is great! but the price difference between an industrial machine of 20,000 usd to 300 allows for maybe a 3000 usd model that has more intricate cameras to allow a better process or larger capacity. In your proposal i read that one of the reasons for the project is to improve the quality of the coffee so people could get payed more, the machine will help but up to a point, maybe people that obtain the design rights should also commit to sharing knowledge of specialty coffee buyers, because you might have the best coffee in the world but if no one knows about it people will continue to sell it to the large exporter. what ever info you need about coffee or to try the machine please count me in.


Hi @matthias

I had a serendipitous conversation with a specialised technician from Transforming how we obtain, use and reuse our planet's resources - TOMRA

He confirmed me that they use near-infrared for fruit and coffee applications (it’s better at identifying, among else, humidity and cracks), and ultraviolet when it comes to colour sorting… they rely on pulsed lasers, to avoid “cooking” the target during the exploration, and to minimise noise and meaningless interferences… you could use maybe pulsed LED…

He stressed how also camera positioning takes them quite a deal of optimisation when changing targets and work cycle … so maybe thinking of setting your own detectors on a movable frame, that is separated from the portion of the installation that would be affected by mechanical vibrations (conveyor belt) could be considered in your design, to reduce the number of tuning/setting intervention during the working cycle.

I could not obtain much more… intellectual property, you know…

Hope this helps!

1 Like

Thank you @markomanka, this helps for sure :slight_smile:

So it seems that coffee does not fall under the “color sorting” process in their terminology (makes sense, as indeed there are other products where simply the average color of the whole object is the decision criterion, such as with rice grains). That also means for us that (1) we can probably ignore UV, and (2) it’s a good idea to include infrared imaging relatively early. So in addition to the white LED flasher we plan to use, we’d also include flashing infrared LEDs, and prepare the camera for near-infrared imaging by removing some filter …

Interesting data point as well. I am quite astonished that they build relatively universal sorting machines – their machine for coffee sorting also covers 29 other types of food products. Our machine will only work with coffee, avoiding this re-tuning. However, it also offers the inspiration that the machine could also sort other items of similar size (hazelnuts, corn, beans, …). So yes, placing the camera on a movable frame is a good idea, we’ll do that.

As @abdobelk howed interest in helping us with 3D modeling and visualization, here are our current challenges and tasks with relation to that:

  1. Creating a FreeCAD model of the machine design. FreeCAD is the only reasonable open source CAD solution right now, so that choice of software is quite simple.

    A screenshot of an existing 3D model (in a proprietary file format) is shown at the top of this topic, and @ahmedmajdoub can supply the source files and exported versions of that one. However, as quite some changes are needed anyway, we can also start from scratch with a FreeCAD model. The major constraints are a max size of 540×360 mm for the large side of the machine (see BoM in the first post), and to only use rectangular sheet material pieces in the next version of the design. This allows manufacturing with a table saw, no CNC etc. needed. Connecting the wood / plastic sheet material pieces would be done with L profile angles or similar (which do not have to be put into the model in the first version).

  2. Publishing that model on P3D. This allows visitors to inspect the design in 3D in the browser in various modes (textured and shaded, textured only, wireframe, x-ray etc.). The challenge, as always with browser based 3D content, is how to efficiently make the model a low-poly one.

    When doing this task, we’d also like the process documented in a tutorial :slight_smile: (Publishing the tutorial as open content on a suitable Stack Exchange platform is usually a good idea; here the platform seems the most suitable).

  3. Build instructions in 3D. Not sure about this one and / or how it can be done, but it would sure be nice :slight_smile:


This is a great project to work on!

My 3D skills converge more toward visualization and photorealistic rendering. I can however work with industrial CAD files in order to create appealing visuals.

Attached are samples of my 3D renders:

From an industrial point of view: The Coffee Sorter should be functioning, cost-effective to manufacture and doing its task.

From a marketing/selling point of view: It should have an appealing look & feel, good build quality and having a nice aesthetic look. Some people buy into the look & brand more than into the functioning. Think Apple, Sennheiser…

This is my opinion, feel free to correct me :slight_smile:


Hmmm … nice rendering skills! :astonished: For the coffee sorter project, this is too early though … we’d want to go through at least two product releases with a simple, box-shaped machine before adding any design that deserves a rendering.

(This is a machine for farmers in outback Nepal, India, Ethiopia etc. … I don’t expect them to attach much value to the form when this machine is the only one worldwide to relieve them of manual sorting …)

However, have a look at the Bitcut “open source furniture” project by @m_tantawy and team. You can read more about it and offer to help with renderings in this topic. Hope you like that project, too!


Oh thank you :slight_smile:
I understand, so far the coffee sorter is about functioning. But you never know, if you ever need visualization, I’m here!

I’ll have an eye on the “Open Source Furniture”, thank you @matthias for the guiding :slight_smile: