Introduction: Automatic Bartender

Hello everyone,

In these instructables, we are going to present you how to do an automatic bartender.

The purpose is to be able to order cocktails thanks to an android application.

You are going to need :

- a raspberry pi 3 to do the acquisition of the orders and send the quantities to an Arudino

- an Arduino to recieve the quantities from the raspberry pi 3 and then command the pumps

- 5 pumps (peristaltic if you have a sufficient budget)

- 5 electrical relays

- a breadboard

- some electric cables

- power supplies for the raspberry, the Arduino and the pumps

- wooden plank

- some pipes

- some screws

- five bottles of liquid

We hope you are going to be able to do it yourself.

The CoktailTeam.

Step 1: Set Up Your Raspberry-pi 3 :

1. Install Raspbian

2. Create the data-base

  • Connect to the internet
  • Open the command prompt :

--> sudo apt-get update

--> sudo apt-get upgrade

--> sudo apt-get install mysql-server -y

--> ENTER Password : COCKTAIL

--> sudo apt-get install python-mysqldb -y

--> sudo apt-get install python-mysql.connector -y

--> Mysql -u root -p

--> Enter Password

     Mysql > CREATE DATABASE cocktail;
     Mysql > USE cocktail;
     Mysql > CREATE USER ‘cocktailteam’@’localhost’ IDENTIFIED BY ‘COCKTAIL’;
     Mysql > GRANT ALL PRIVILEGES ON cocktail.* TO ‘cocktailteam’@’localhost’;
     Mysql > quit;

--> Mysql -u cocktailteam -p

--> Enter Password

     Mysql > USE cocktail;
     Mysql > CREATE TABLE cocktail_table (
           > ID int usigned auto_increment primary key,
           > Tname varchar (30),
           > Tl1 Tinyint,
           > Tl2 Tinyint,
           > Tl3 Tinyint,
           > Tl4 Tinyint,
           > Tl5 Tinyint);
     Mysql > quit;</p>

3. Set up the webserver and fill the database with the variables stored in the URL

--> Sudo apt-get install apache2 -y

--> Sudo apt-get install php5 libapache2-mod-php5 -y

--> Sudo rm /var/www/html/index.html

--> Sudo nano /var/www/html/index.php

In the file "index.php", write the following code (explanations of the code are in comments):


// Get the values stored in the url

$name = $_GET['tname'];
$l1 = $_GET[tl1];
$l2 = $_GET[tl2];
$l3 = $_GET[tl3];
$l4 = $_GET[tl4];
$l5 = $_GET[tl5];

//Connect to the db

$bdd=new PDO('mysql:host=localhost;dbname=cocktail','cocktailteam','COCKTAIL');

catch(Exception $e)

//We add the values to the db

$req = $bdd->prepare('INSERT INTOcocktail_table(Tname,Tl1,Tl2,Tl3,Tl4,Tl5) VALUES(:name,:l1,:l2,:l3,:l4,:l5)');
'name' => $name,
'l1' => $l1,
'l2' => $l2,
'l3' => $l3,
'l4' => $l4,
'l5' => $l5


The url must look like that :


X is representing the quantities of liquid.

You can try it by replacing X by numbers and see if the database is filling up.

4. Python 2: make the database and the Arduino communicate

Create a script and enter the following code (explanations of the code are in comments):

# -*-coding: utf-8 -*-

import mysql.connector

import time

import serial

#connectto the arduino

ser =serial.Serial('/dev/ttyACM0', 9600)

# the ttyACM0 is the port, if you’re using another port, you have to adapt the code

#connect to the database

conn = mysql.connector.connect(host="localhost",user="cocktailteam",password="COCKTAIL", database="cocktail")

cursor = conn.cursor()

#Find the last ID of the database

cursor.execute("SELECT max(ID) FROM cocktail_table")

response = cursor.fetchone()

ID = response[0]

ID = ID+1

#create a loop

while True:


conn = mysql.connector.connect(host="localhost",user="cocktailteam",password="COCKTAIL", database="cocktail")

cursor = conn.cursor()

#try to reach the ID after the last ID executed

cursor.execute("SELECT ID,Tl1,Tl2,Tl3,Tl4,Tl5 FROM cocktail_table WHERE ID = %s", (ID, ))

response = cursor.fetchone()

# Get the quantities from the database

liq1 = str(response[1])

liq2 = str(response[2])

liq3 = str(response[3])

liq4 = str(response[4])

liq5 = str(response[5])

# Send the quantities to the arduino :

ser = serial.Serial('/dev/ttyACM0', 9600)

# the ttyACM0 is the port, if you’re using another port, you will have to adapt the code



# time.sleep are to let the time for the arduino to get the value (the delay has to be important to work properly)









# time to do the cocktail

ID = ID +1



# If there isn’t anything in the next ID, retry


5. Before starting to use the all device

When you've done all the steps, you will have to run the python code on the raspeberry pi to make the all device working.

Step 2: Create the Android Application :

1. Download and install visual studio community :

Follow this link :

Launch the .exe file and select all the patches for Android Xamarin.

2. Download the solution :

You can download the solution that we've made by following this link :!Amk6rfKJaqK3icoyS0wQHpSO1uBwYg

It's the cocktail.rar file.

3. Modify the code :

You can understand the code thanks to the comments in it.

In the class cocktail.cs, you have to change the URL by replacing the IP adress of my raspberry pi by the IP adress of your raspberry pi.

You can also :

- Change the values that you want for the programmed cocktails

- Add programmed cocktails

- Change the visual aspect of the application

- Add liquids (be carefull, if you do that you will have adapt all the codes, the database,...)

- ...

4. Try your application :

You can try your application on your phone thanks to the developer mode by following this tutorial :

Step 3: The Arduino Code

1. Install Arduino IDE on your desktop or your raspberry :

On the raspberry pi, enter the following command in the command prompt :

--> sudo apt-get install arduino

On your desktop, follow this link :

2. Write the Arduino code :

Open Arduino and enter the following code :

byte l1;
byte l2;
byte l3;
byte l4;
byte l5;

int Pin_p1 = 2;
int Pin_p2 = 3;
int Pin_p3 = 4;
int Pin_p4 = 5;
int Pin_p5 = 6;

void setup()
// start the communication with the python program

pinMode(Pin_p1, OUTPUT);
pinMode(Pin_p2, OUTPUT);
pinMode(Pin_p3, OUTPUT);
pinMode(Pin_p4, OUTPUT);
pinMode(Pin_p5, OUTPUT);
// set the pins as outputs

void loop()
l1 = 0;
l2 = 0;
l3 = 0;
l4 = 0;
l5 = 0;

if (Serial.available()>0)
l1 = Serial.parseInt();
delay (3000);
// delay to get the data properly from the python program

l2 = Serial.parseInt();
delay (3000);

l3 = Serial.parseInt();
delay (3000);

l4 = Serial.parseInt();
delay (3000);

l5 = Serial.parseInt();
delay (3000);


if (l1 != 0)
digitalWrite(Pin_p1, HIGH);
// we didn’t have the budget for the right pumps, so we need time to initiate the pumps (0,1s)
// you have to try the pumps to find the time/centiliter ratio. Here, the pump debits 1 centiliter in 0,3s
digitalWrite (Pin_p1, LOW);

if (l2 != 0)
digitalWrite (Pin_p2, HIGH);
digitalWrite (Pin_p2, LOW);

if (l3 != 0)
digitalWrite (Pin_p3, HIGH);
digitalWrite (Pin_p3, LOW);

if (l4 != 0)
digitalWrite (Pin_p4, HIGH);
digitalWrite (Pin_p4, LOW);

if (l5 != 0)
digitalWrite (Pin_p5, HIGH);
digitalWrite (Pin_p5, LOW);

Then, connect your device to the arduino thanks to the serial cable. Choose the right card (here we've used an uno) and the right port. Upload your code.

Step 4: Building the Frame

  1. Then we can start with the first step that is to build the body frame of the machine. For this, you can use recovered wooden board or other.
  2. Shape all the boards into rectangle and join them together with several screws. Size the length of the structure to make it long enough for the quantity of bottles you will insert in it.
  3. When the body frame was fixed to make one piece, cut a piece of rigid cardboard and fixe it behind the structure.
  4. After place a wooden board in front to block the bottles and make sure that it is not possible for them to go out of the structure.
  5. Once this job has been carried out, it is time to add some wooden boards to realize the axle support for the conveyor. After you have to perforate them and to incorporate the shaft to allow the conveyor to work properly. At this point you can also put a little piece placed on the top of the body frame to create a fixation point for all the piping providing the drink.
  6. To come back on the shaft support, they are made by inserting à steel pipe surrounded by a PVC one. The diameter of the PVC pipe is slightly wider than the other. That make it free to rotate around the steel pipe. The rotation is possible thanks to the glide between the steel and the PVC.
  7. The next step is to think about the stabilisation of the glass on the conveyor. You can cut a thin wooden board with a jigsaw and fix it in the front of the structure.
  8. Before inserting the electric motor for the conveyor on the structure, take a MDF plate and screw the existing structure on it. Thanks to this, the structure is reinforced by its fixation on the plate.
  9. After this, the bar tender is ready to be paint
  10. The final step was to insert auxiliary components on the structure as the pumps, the piping, and all the electronics that command all the operations. At first, you have to perforate the board on the top of the structure and fix a threaded rod on it. The rod extremity height corresponds at the top of the glass where the liquids are poured. An annular wooden board is fixed on this extremity, and 5 holes are perforated where are inserted each pipe coming from the pumps. The pipes come from a bottle, go through the pump and finally go out of the pump by a pipe that is inserted in the annular wooden board that I was speaking about previously.
  11. You can choose not to make the piping visible. Then you can put a hold cable duct to insert all the pipes. A part of the big base plate is dedicated to the fixation of the electronics on the back of the device.
  12. Finally, the bottle are inserted in the box and each pipe is inserted in each bottle.

Step 5: Connect the Raspberry Pi, the Arduino and the Frame Together :

As you can see, you have to plug in the three power supplies. The Arduino and the raspberry pi are connected thanks to the serial and then the Arduino is connected to the breadboard to command the activation of the different pumps thanks to the electrical relays.

The electrical relays are essential because the Arduino command in 5V and the pumps need to be powerred by 12V. So we need a command part and a power part.

Let’s see accurately the cabling of the breadboard :

The command part :

The + is connected to the 5volts of the Arduino and the - is connected to the ground of the Arduino.

The relays have 3 pins for command :

  • Vcc must be connected to the 5volts of the Arduino (terminal + of the breadboard)
  • Grd must be connected to the ground of the Arduino (terminal – of the breadboard)
  • In must be connected to the pin of the Arduino corresponding of the right pump

The power part :

The + and – terminals must be connected to the power supply. That allows to power the 5 pumps with the single power supply.