Convert Your POP/Drink Machine to Use RFID With Arduino




This is my first instructable so any helpful comments are appreciated. I started this project about a year ago.

I started searching on how to use arduino to control a vending machine and I found one project that without it I wouldn't have gotten anywhere. My gratitude goes out to and the popcard project.

So I started with a mixture between his popcard version 1 and his popcard version 2. The pop machine I have is older then his, so I had to make some changes based on that.

So my version 1 was setup as every drink was the same price, I used one relay and then when someone swiped their card, the arduino would read the card send the data to my web server, the web server would respond back with if the card was active or unknown, the users name and the amount remaining on their card. I had an admin page that I could go and add money to their card. The best part is that everytime someone buys a drink, the drink machine would email them and tell them their current amount on their card. Worked extremely well, I only had issues with how long it took the arduino to contact the webserver.

So I told a couple friends and they wanted to do the same thing, except they don't have a web server they could connect to. So, this is why I decided to start from scratch and designed version 2 & 3.

I wanted a RFID reader/ controller that was all contained within the drink machine. A way to add and update cards without having to open the machine. I also wanted to be able to assign different prices for the different drinks in the machine.

Version 3 as shown below has the following features

1) Reads the RFID tag and uses it the same as the number on the tag
2) Pricing is loaded from the SD card
3) Every RFID Tag is stored as a separate file on the SD card containing the cardnumber, emailaddress,value
4) Current Time is read in from a NTP server
5) Email is sent out to the card holder with current amount available on their card at every purchase
6) Every Friday from 4:30 - 6 PM the machine automatically goes into Free Mode and using a rfid tag will get you a free drink
7) with a tag that has been set to Admin mode - Using the drink buttons:

option 1:add money to the last scanned RFID tags account in increments of .25 -.25,1.00,-1.00, 5.00 -5.00.
option 2: set the machine into free drink mode
option 3: turn off free drink mode
option 6: reset the arduino device

8) I have also added the code for a web server, so that you can log in to the arduino and update the cards. this portion hasn't been completed yet, but the starting blocks are also included.

Version 2 and 3 use the SD card to contain all the user information, and prices for the buttons. I created an admin RFID tag that when scanned can update the last read RFID tag by using the drink buttons on the machine. The difference is Version 3 uses the network card to read in the current time, and send out emails on every purchase.

This is version 3 that I will be explaining in this instructable.

Step 1: Items to Purchase

my Parts List:

I think everything I needed was just under $100, but I purchased it over several months as I was increasing the scope of the project.

1) New Arduino Mega2560 R3 ATMEGA16U2 Ethernet Shield W5100 Kit

2) 125K RFID rdm6300 ID RF UART

3)1602 16x2 LCD Character Display + IIC/I2C/TWI

4) 40PCS Female/Female & 40 PCS Male/Famale Dupont Wire

5) 8 Channel 5v Relay (you need 7 relay channels for a 6 button drink machine)

6) computer wire, and 120 volt wire. misc connectors.

7) 100x 125Khz RFID Proximity ID Card Token Tags Key

8) 110v to USB 1 amp power supply

9) a pc speaker

10) Electrical tape

11) Wire cutters

12 Soldering Iron

13) Resistors

I will have to take some pictures of the stuff I purchased.

Step 2: Wiring Everything Together.

The 8 channel relay board - Relay side
looking at the picture shown, there the red wires are about 6" long and have a red male flat connector on the end and they replace the connection that the button on the machine use to connect to.

starting from the bottom of the picture is relay 1 which connects to the ready to vend on the vending machine as shown in the picture with the three clear wires with the yellow connectors on the end. You will need to verify with your machine which are the proper connections.

For the drink buttons you will notice that I have a clear wire that jumbers from the middle of one relay to the middle of the next one and so forth. There is only one power line and which ever button is press is the one that uses the power to signal the drink machine a button is pressed.

The 8 channel relay board - arduino side

using 10 female to male wires

Female side goes to the relay board (wrap some black tape around the connectors to hold them together in one straight line.

1 -GND (recommend black wire)
2 - Relay1
3 - Relay2
4 - Relay3
5 - Relay4
6 - Relay5
7 - Relay6
8 - Relay7
9 - Relay8 (not used)
10 - 5volt (recommend red wire)

Male side plugs into the arduino board

1 - Pin 50
2 - Pin 40
3 - Pin 41
4 - Pin 42
5 - Pin 43
6 - Pin 44
7 - Pin 45
8 - Pin 46
9 - Pin 47 (not used)
10 - joined to the 5 volt power

as shown in the code pin 40 is relay 1 used for the vend ready on the drink machine, and 41-46 is drink buttons 1 - 6

(This is the arduino code)
#define PIN_VEND_RELAY 40
int drinkPins[] = {41,42,43,44,45,46};

The Relay to replace the drink buttons

The drink buttons need a resistor added between them and ground (as shown in the picture above), to make things simple I created a ground wire soldered 6 resistors to it and then connected one side to the pins shown below and then the other side to the centre pin on the push buttons on the machine.

Drink button 1 - Pin 31
Drink button 2 - Pin 32
Drink button 3 - Pin 33
Drink button 4 - Pin 34
Drink button 5 - Pin 35
Drink button 6 - Pin 36

(This is the arduino code)
int buttonPins[] ={31,32,33,34,35,36};

The RFID connector

Female to Male
Pin 5 - Pin 2
Pin 4 - GND
Pin 1 - Pin 19

(This is the arduino code)

#define PIN_RFID_RX 19

#define PIN_RFID_RESET 2

The speaker
gnd and A4

(This is the arduino code)
#define PIN_BUZZER A2 // the piezo buzzer

The LCD screen

This code is based on the LCD screen I2C backboard that I purchased, it might have to be changed to match the one you purchase
5v to pin 3,
GND to pin GND
SDA to pin 20
SCL to pin 21

(This is the arduino code)
#define LCD_5volt 3
#define BACKLIGHT_PIN 13
LiquidCrystal_I2C lcd(0x20, 4, 5, 6, 0, 1, 2, 3, 7, NEGATIVE);

Step 3: The Code

The actual code will be available to download later but here are some important parts of the code

The pins are shown below. I used arrays to manage the drink buttons, this way if you have a drink machine that has more buttons, it is simple to increase the button array. I hope that in the next version, I will have a setup file to read all of these setttings in from the SD card so that the code doesn't have to be recompiled differently for each machine.

#define BACKLIGHT_PIN 13
LiquidCrystal_I2C lcd(0x20, 4, 5, 6, 0, 1, 2, 3, 7, NEGATIVE);

#define PIN_BUZZER A2 // the piezo buzzer
#define PIN_SDCARD 4 //do not use, sdcard uses it.
// LCD Screen
#define LCD_5volt 3
#define PIN_RFID_RX 19
#define PIN_RFID_RESET 2
#define PIN_VEND_RELAY 40

int drinkPins[] = {41,42,43,44,45,46};
int buttonPins[] ={31,32,33,34,35,36};
int buttonState[] ={0,0,0,0,0,0};
String drinkName[] = {"empty","empty","empty","empty","empty","empty"};
float drinkCost[] = {0,0,0,0,0,0}; float updateCard[] = {.25,-.25,1,-1,5,-5};
int drinkPinCount = 6;
int admintimeout = 0;

#define PIN_RESET_NET A3 // network module reset

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 2);//the IP address for the shield:
IPAddress gateway( 192, 168, 0, 1 );
IPAddress subnet( 255, 255, 255, 0 );
IPAddress timeServer(132, 163, 4, 102); //
char emailserver[] = ""; // smtp mail server (
char emaildomain[] ="";
const int timeZone = -6; // Central Time

Step 4: Files on the Sd Card

Price file

create a file in notepad

save it as prices (the name and price will be displayed when the button is pressed on the drink machine)

4,Diet Coke,1.00
6,Ginger Ale,1.00

User rfid tag

I am using our company email server so I dropped the If you are not using the email server then the files can automatically be added by scanning them on the machine and using the admin rfid tag to add money to it.

create a file in notepad using the 7 digits from the rfid tag and replace the 6260593.


using the 7 digits (ignore the zeros) save the file name.

Admin rfid tag.

create a file in notepad using the 7 digits from the rfid tag replace 6254429


using the 7 digits (ignore the zeros) save the file name.

Step 5: Vending a Drink

The code shown below is how a drink is actually dispersed. Once the RFID tag is read and the SD card brings back the amount remaining on the RFID tag, the machine goes into the SelectDrink sub routine. The person has 5500 milliseconds to decide/ press a drink button before the machine goes back to Ready to Scan. Once their drink is selected it then presses the opens the relay to for the readytovend and then opens the corresponding drink relay as if they pressed the button.

void SelectDrink()

long mil = millis();
long timer = 0;
lcd.print("Card Amt $");
lcd.print("Select a Drink");
Serial.print("Card Value $");
Serial.println("Select a drink");
int buttonpressed = 0;
while(buttonpressed < 1)
timer = millis();
for (int thisPin = 0; thisPin < drinkPinCount; thisPin++)
buttonState[thisPin] = digitalRead(buttonPins[thisPin]);
buttonpressed += buttonState[thisPin];
if(timer - mil > 5500) {buttonpressed = 1;}
if(timer - mil < 5500)
for (int thisPin = 0; thisPin < drinkPinCount; thisPin++)
if (buttonState[thisPin] == HIGH)
buzz(NOTE_C4, 8); // Startup sound
if(myNewCredit >=drinkCost[thisPin])
Serial.print(" New Credit $");
Serial.println(myNewCredit - drinkCost[thisPin]);
myNewCredit = myNewCredit - drinkCost[thisPin];
lcd.print("Card at $");
lcd.print(" ");
lcd.print(" Vending Drink! ");
pinMode(drinkPins[thisPin], OUTPUT);
digitalWrite(drinkPins[thisPin], LOW);
digitalWrite(drinkPins[thisPin], HIGH);


Step 6: Simple Warnings to Remember

Please remember to unplug the drink machine before you decide to open it up.

I was consistently doing mods to my project and I accidentally touched 110 volt live wire to one of the 5 volt pins while I was settings up the drink buttons. if you zoom in you can see the burnt wire. That mistake cost me $50 in materials, I had to replace almost everything.

So remember to take your time and unplug the machine until you know all the wires are connected properly.



    • Faux-Real Contest

      Faux-Real Contest
    • Paper Contest

      Paper Contest
    • Build a Tool Contest

      Build a Tool Contest

    12 Discussions


    Question 2 months ago on Step 4

    I cannot open the Notepad of the RFID/Admin which I am interested in. Could you please help. Thank you!


    1 year ago

    Is is possible to use a keypad to make the selection instead of the machine button.

    4 replies

    Reply 1 year ago

    Yes, just replace the button press routine, should be really easy to do


    Reply 1 year ago

    Would you be able to help me with this project, I am on an internship and this project would help me land a job with the company. You can email me at Thanks in advance.


    Reply 1 year ago

    I have more than half of the components, I will have the rest by the end of the week.


    1 year ago

    Ca you send me the Notepad files for RFID/admin, they seem to be broken on the link.

    1 reply

    Reply 1 year ago

    i just updated them, try now, weird that they stopped working.


    2 years ago

    Hi, I have some of the same issues as vendin 10. I a have a client who wants to vend safety equipment. I would contract with you for your programing work. Please contact me at


    2 years ago

    hi, i'd like to do the same thing but in nescafe branded alegria 8-60 coffee machines.the machines board allows for each individual drink to be charged different prices from the software settings on its main board. If we can somehow supply a signal to the mdb/executive interface telling it that a coin has been deposited when the credit is deducted from the rfid card by the arduino device.

    We have many machines spread over many corporate clients.clients want their employees to use rfid cards to obtain drinks from the machine. this will ensure only staff get access to free drinks but the companies also want to limit usage to say 2 drinks a day.

    This will avoid abuse of the free drinks and also cards from a certain client cannot be used to obtain drinks from another clients machine.This would require some form of authentication from the reader to ensure that the card is valid for use.

    is there any way any of you can help?

    we can pay someone for their time to help us do this so please do not see it as a waste of time.

    please email if you can help


    3 years ago on Introduction

    Hello quit new to this, get follow errors:

    Arduino: 1.6.5 (Windows 8.1), Board: "Arduino/Genuino Uno"

    Using library SPI in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI

    Using library SD in folder: C:\Program Files (x86)\Arduino\libraries\SD

    Using library Wire in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire

    Using library Arduino-LiquidCrystal-I2C-library-master in folder: C:\Program Files (x86)\Arduino\libraries\libraries\Arduino-LiquidCrystal-I2C-library-master (legacy)

    Using library Time in folder: C:\Program Files (x86)\Arduino\libraries\libraries\Time (legacy)

    Using library Ethernet in folder: C:\Program Files (x86)\Arduino\libraries\Ethernet

    Using library pitches in folder: C:\Program Files (x86)\Arduino\libraries\libraries\pitches (legacy)

    C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI -IC:\Program Files (x86)\Arduino\libraries\SD\src -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire -IC:\Program Files (x86)\Arduino\libraries\libraries\Arduino-LiquidCrystal-I2C-library-master -IC:\Program Files (x86)\Arduino\libraries\libraries\Time -IC:\Program Files (x86)\Arduino\libraries\Ethernet\src -IC:\Program Files (x86)\Arduino\libraries\libraries\pitches C:\Users\Reinhard\AppData\Local\Temp\build1104042723699220277.tmp\NewVendingMachine3_8.cpp -o C:\Users\Reinhard\AppData\Local\Temp\build1104042723699220277.tmp\NewVendingMachine3_8.cpp.o

    NewVendingMachine3_8.ino:15:53: error: 'POSITIVE' was not declared in this scope

    NewVendingMachine3_8.ino: In function 'void setup()':

    NewVendingMachine3_8.ino:91:18: error: no matching function for call to 'LiquidCrystal_I2C::begin(int, int)'

    NewVendingMachine3_8.ino:91:18: note: candidate is:

    In file included from NewVendingMachine3_8.ino:4:0:

    C:\Program Files (x86)\Arduino\libraries\libraries\Arduino-LiquidCrystal-I2C-library-master/LiquidCrystal_I2C.h:76:7: note: void LiquidCrystal_I2C::begin()

    void begin();


    C:\Program Files (x86)\Arduino\libraries\libraries\Arduino-LiquidCrystal-I2C-library-master/LiquidCrystal_I2C.h:76:7: note: candidate expects 0 arguments, 2 provided

    NewVendingMachine3_8.ino:121:3: error: 'Serial1' was not declared in this scope

    NewVendingMachine3_8.ino: In function 'void ReadyforRFID()':

    NewVendingMachine3_8.ino:256:11: error: 'Serial1' was not declared in this scope

    NewVendingMachine3_8.ino: In function 'void checkRFID()':

    NewVendingMachine3_8.ino:268:7: error: 'Serial1' was not declared in this scope

    'POSITIVE' was not declared in this scope

    Any idea what to set those ?

    Thanks a lot


    1 reply