An automatic Nespresso capsule dispenser

An automatic Nespresso capsule dispenser

When one gets a Nespresso coffee machine, the first question that comes to mind is how to organize the different colors of coffee capsules. While chatting with friends about the existing solutions to this "problem", we have been challenged to build an automatic coffee capsule dispenser. Of course, we could not resist...

We'd better be frank with you: the aim is simply to show off a little when friends come over for a coffee at home. This dispenser is more expensive, more complex, and probably less convenient than a simple bowl with all the capsules mixed up.

This automatic coffee capsule dispenser uses an old Android tablet and several servomotors controlled by a Yocto-Servo. The tablet runs a native application listing the available coffees. When the coffee is selected, the application activates a servomotor that frees a capsule of the selected coffee.

Here is our automatic coffee capsule dispenser
Here is our automatic coffee capsule dispenser

The mechanics: the dispenser

The dispenser is made of 5 distribution rails. The rails are positioned vertically. The capsules are inserted at the top of the rails and come out at the bottom. Each distribution rail is activated by a single servomotor and can contain up to 10 capsules. The 5 rails are connected to the 5 Yocto-Servo outputs.

The main difficulty in this project was the distribution rail design, more particularly the mechanism enabling the dispenser to free one capsule at a time.

At the bottom of the rail, there is a cam that a servomotor moves. In idle state, the cam blocks the end of the rail and prevents the capsules to come out. When you activate the servomotor, the cam rotates by 150 degrees, frees the bottom capsule while blocking the other ones.

When the cam rotates, it frees only one capsule

When the capsule has fallen, the cam comes back to its idle state and all the remaining capsules move down by one position.

A detailed view of a distribution rail A detailed view of a distribution rail
A detailed view of a distribution rail

You can download the files needed to build this capsule dispenser on Thingiverse.

The connection: USB or Wifi

In our case, we used an Acer A200 tablet that has both a USB port and a charging socket. Therefore, we connected the Yocto-Servo directly on the tablet USB port with a USB cable that is a meter long. The Yocto-Servo is powered directly by the tablet which is powered through its charging cable.

In our example, we used a USB connection
In our example, we used a USB connection

However, most recent tablets use the USB port to charge. In this case, there are two options: The first one is to use a Y cable available from some providers.

The second is to use a YoctoHub to connect the Yocto-Servo to your local network. The application then communicates with the Yocto-Servo by using the local network instead of a USB connection. The application code doesn't change. You must simply give the IP address of your YoctoHub as parameter instead of the "USB" keyword to the YAPI.RegisterHub() method.

You can also use a Wifi connection
You can also use a Wifi connection

The software: the Android application

The Android application is very simple and draws largely from the FragmentStatePagerAdapter example of the Android documentation. The application displays several pages presenting the available coffees. Each page contains a button freeing a capsule from the dispenser.

A screenshot of the application
A screenshot of the application

All the code controlling the dispenser is gathered in the DispenserInterface class. This class is a singleton implementing 4 methods:

  1. Get(Context ctx) returns the singleton
  2. startUsage() initializes the connection with the Yocto-Servo
  3. stopUsage() frees the resources used for the connection with the Yocto-Servo
  4. distributeCapsule(int index) sends the commands to the Yocto-Servo to distribute a capsule

The startUsage() and distributeCapsule(int index) methods trigger a communication with the module which may provoke a delay (for instance if the Yocto-Servo is disconnected). Therefore, the code for these two methods is run as a background task using an AsyncTask.

Note: As our module is always connected by USB, we could run the startUsage method from the main thread, but this would freeze the interface during the code execution. In any way, under Android, it is recommended to run IO operations in the background to keep the application reactive.

The code freeing a capsule contains a YServo object which enables interaction with one of the Yocto-Servo outputs. It changes the position of the servomotor, waits for a second, and restores the previous position. Instead of directly using the set_position method, we use the move command allowing us to define the number of milliseconds to reach the final position. This makes the cam movement smoother.

public class YoctopuceInterface implements YAPI.LogCallback {

  private class DistributeCapsule extends AsyncTask<Integer, Void, String> {

    protected String doInBackground(Integer... params) {
      int index = params[0];
      String hwid = String.format("%s.servo%d", _serial, index+1);
      YServo servo = YServo.FindServo(hwid);
      try {
        servo.move(UP_POSITION, 300);
        servo.move(DOWN_POSITION, 300);
      } catch (YAPI_Exception e) {
        return e.getLocalizedMessage();
      } catch (InterruptedException e) {
      return null;

    protected void onPostExecute(String error) {
      if (error != null) {
        Log.e("YAPI", error);
        _lastError = error;

  public synchronized void distributeCapsule(int tubeIndex) {
    new DistributeCapsule().execute(tubeIndex);

The rest of the code is not detailed in this article because it is either code that we detailed in previous posts, or code to manage the interface. The Android Studio project of the application is available on GitHub for the more curious among you.


Show off time!

We are not going to lie to you: this dispenser wasn't built in 5 minutes. Design, 3D printing, plexiglass cutting, and assembly took several evenings :-) But if we put aside the mechanical part, the remainder took only a few hours. The connections are obvious (we didn't even need a soldering iron), and the code managing the servomotors fits in a 150 line class. This project is a good example of what we try to do at Yoctopuce: provide modules that are easy to use so that the user doesn't lose time on the electronic part and can concentrate on everything else.

1 - jenyay Saturday,september 17,2016 18H52

Thanks for detailed guidelines. I wonder if there is a mistake in last 2 DXF files. The models are way bigger than should be. The first file is make sense - around 10x18 cm, but the last ones are about few meters.

2 - seb (Yocto-Team)Monday,september 26,2016 14H15

@jenyay: The files seems correct to me. All files are designed and exported in mm. Did you have imported these files in inch?

3 - moshew Friday,february 17,2017 6H51

Hi, how to connect entretoise_servo to the servo arm (0.8 mm)?

4 - martinm (Yocto-Team)Friday,february 17,2017 7H08

@Moshew: we used a M2.5 screw and force screwed in the entretoise_servo part. The servo is a Hitech HS55, which is sold with several arms. One of then is large enough to have the holes widened to 2.5mm.

5 - phikachu Thursday,november 08,2018 17H03

I've just ordered an Yocto-Servo to try and build this.

I've 3D printed the parts and I'm now trying to laser cut the acrylic. How thick is the acrylic?

Also, can you tell me the lengths of M2.5 screws I will need please.


6 - seb (Yocto-Team)Monday,november 12,2018 8H46

@phikatchu: Hi, we used 3mm acrylic sheets, and M2x10mm screws.

7 - kaskachi Wednesday,may 10,2023 7H04

For automatic nespresso capsule dispenser, that's good dispenser.

Prior to build it, ask you one thing below;

when choose the capsule( 5 row in above capsule line), can dispenser fallen selected capsule through programming? I want to make the dispenser fallen for selected capsule. is it control the servo motor for selected capsule?

thanks in advance.


8 - seb (Yocto-Team)Wednesday,may 10,2023 9H50

@kaskachi: I'm not sure to fully understand your question. But, yes each servo motor is controlled programmatically.

Yoctopuce, get your stuff connected.