Project tutorial
Coin Op Personal Vending Machine

Coin Op Personal Vending Machine © GPL3+

A step by step guide to building a fully functioning, personal vending machine that will amaze everyone who sees it.

  • 2,243 views
  • 7 comments
  • 20 respects

Components and supplies

FriendlyARM 1/4 Plywood
Cut Plywood to the dimensions specified in the diagram
×4
3/4" plywood blocking
Cut plywood into strips 3/4" wide and as long as the piece it connects to, see diagram
×1
LAFVIN 5 Sets 28BYJ-48 ULN2003 5V Stepper Motor + ULN2003 Driver Board for Arduino
These motors will will be able to push any treat you put in the machine
×1
Pc Accessories - Connectors Pro IDC 1.27mm Pitch Rainbow Color Flat Ribbon Cable for 2.54mm Connectors (50P-10FT)
Needed to make the machine clean and professional
×1
Glarks 635Pcs Dupont Connector Housing Male/Female Pin Connector 40 Pin
Needed to make the machine clean and professional
×1
Gamelec-Illuminated-Replacement-Microswitch
Gotta have buttons
×1
12002 04
Breadboard (generic)
Solder boards work well also
×1
30 Pcs Double Sided PCB Board Prototype Kit
Only one or two needed but are a perfect size for future projects
×1
Ardgen mega
Arduino Mega 2560 & Genuino Mega 2560
The controller used was the Mega 2560
×1
Tolako 5v Relay Module for Arduino ARM
Needed to keep the motors from being over heated
×1
HiLetgo 2pcs 1602 Serial LCD Module Display
Without this you will not know what button was pushed
×1
LED Light Strips
Optional
×2
50 ft. 8-Gauge Solid SD Bare Copper Grounding Wire
This is what you will use to make the coils
×1
Flat metal shelf divider
×1

Necessary tools and machines

Table or power saw
Unless you have somewhere to get the wood cut
09507 01
Soldering iron (generic)
Hy gluegun
Hot glue gun (generic)
Don't forget the glue sticks also

Apps and online services

About this project

THE PERSONAL VENDING MACHINE

This project is a step by step build of a personal vending machine. The vending machine can be filled with your favorite snacks or could be brought to the office so you can share some treats with your team. Take a look and let me know your thoughts.

UPDATED CONTENT- Please check the bottom of this text (LED STRIP SECTION) to see the update. Code and circuit diagram was also added to the details so you can set it up also.
Completed Project

Building the Machine :

I will refer to the diagrams of the machine throughout this text so please refer to the diagrams for clarification/understanding.

The dimensions of the machine are 21"W x 18"D x 24 1/4"H (Box Dimensions)

2 panels 18"D x 23 3/4"H (Sides)

2 panels 21"W x 18"D (Top & Bottom)

2 panels 21"W x 24 1/4"H (Front & Back)

Divider wall is 18"D x 23 3/4"H

Internal Shelf is 13"W x 12"D (times 2, upper and lower shelf)

Shelves are 8” apart 13” wide 12” deep

Each blue block on the panels diagram is a ¾”W x ¾”H mounting point as deep as the panel

Assemble the box as shown in the diagram and here using the 3/4" blocking at each of the junction points. Take note that the sidewalls sit on top of the bottom plate and under the top plate. The perimeter walls should measure 21"W by 24 1/4"H.

The Divider wall needs to be setup before installing. Measure down from the top 16 1/4" and attach blocking there for bottom shelf. Measure down 8 1/4" from the top and attach blocking for top shelf. Complete these steps on the left wall (looking from the front of the machine) so you can attached the blocking for the top and bottom shelves.

**** Note the bottom shelf needs to be installed first otherwise securing to the blocking will be very difficult.

Once blocking is installed for the shelves use the 13" x 12" panels and install one on each set of blocking. This will automatically setup the divider wall in its proper place. Then secure blocking at the top and bottom of the right side of the divider wall. Then secure it to the top and bottom panel This will completely sure up your structure.

Install the back panel and get ready for the motor installs. Make sure you have the coil wheels printed so you can measure them and setup your drill holes. Measure the wheels and add 1/4" to the height so it it will leave room for the coil to spin. You may want to adjust this as needed depending on your material. Measure over 6 1/2" on the shelf to mark its middle. Measure over 3 1/4" to find the center of each shelf section. Use the height measurement you recorded moments ago to find the drill points. Drill a hole that will allow you to connect the wheel to the motor without the wheel shaft rubbing on the board. Finish mounting the motors and screwing in the fasteners.

Setting up the motor relay:

Connect the pins as follows. Use chip L293D (notch to the left) (In circuit diagram) so you can control the relay. This will allow you to connect the motors to power.

(Starting Left to Right)

Pin 1 connect to pin socket 10 on controller (In circuit diagram)

Pin2 connect to pin socket 9 on the controller (In circuit diagram)

Pin 3 connect to positive side of relay (with the 3 pins facing you, pin on left) (In circuit diagram)

Pin 4 connect to 12V ground on breadboard (In circuit diagram)

Pin 5 Not used (In circuit diagram)

Pin 6 connect to Ground side on relay (with the 3 pins facing you, pin on right) (In circuit diagram)

Pin 7 connect to pin socket 8 on controller (In circuit diagram)

Pin 8 connect to +12V on breadboard (In circuit diagram)

Connect middle pin on relay to +12V on breadboard (In circuit diagram)

Connect back right pin on relay (with the 3 pins facing you, pin in back on right) to the positive lead going to the motor drivers (In circuit diagram)

Screen & button installation: Screen - Pick a spot on the right side of the machine (looking at the machine from the front) and mark out the hole that needs to be made for the display portion of the screen (2.53937" x 0.5708661) Button - Pick a spot on the right side of the machine (looking at the machine from the front) and mark out the holes that need to be made for the 4 buttons. The holes needs to be 1.10236" if using the exact same button in the parts list. I like to use a drill bit smaller then needed and sand paper to bring it out to the needed size.

Keep in mind that you need to make sure that you have all of the connections in the exact same spots as in the diagram above. The LEDs shown in the diagram are the LEDs built into the push buttons. The diagrams show them separate but that is only for display and to make it easier to read the schematic.

Connect each motor to the driver provided with them. Then connect each driver to the controller using these steps:

Motor Setup:

Power should be connected to the 12V side of the breadboard. This power comes from the ATX power supply we will prep at the end. Then connect the 4 "in" pins on the driver to the controller. These pins are as follows

********* DO NOT CONNECT TO THE FIRST 2 PINS IN THIS BLOCK THEY ARE 5V PINS - NOT USED IN THIS PROJECT *********

Motor 1: Blue Pins 22, 24, 26, 28 (In circuit diagram)

Motor 2: Yellow Pins 23, 25, 27, 29 (In circuit diagram)

Motor 3: Green Pins 30, 32, 34, 36 (In circuit diagram)

Motor 4: Red Pins 31, 33, 35, 37 (In circuit diagram)

Button Connections:

Connect one side of Push Button 1 to power 5v, the other side to a grounded 220 resistor along with Analog Pin A0 (In circuit diagram)

Connect one side of Push Button 2 to power 5v, the other side to a grounded 220 resistor along with Analog Pin A1 (In circuit diagram)

Connect one side of Push Button 3 to power 5v, the other side to a grounded 220 resistor along with Analog Pin A2 (In circuit diagram)

Connect one side of Push Button 4 to power 5v, the other side to a grounded 220 resistor along with Analog Pin A3 (In circuit diagram)

LCD SCREEN:

Connect the screen to the 5v side of the breadboard for power and ground

Pins are as follows:

Pin 1: Connect to Ground(In circuit diagram)

Pin 2:Connect to 5v power (In circuit diagram)

Pin 3:Connect to adjustable potentiometer (Pictured below) Bottom left pin to ground, bottom right to power, and top pin to pin 3 on LCD (In circuit diagram, This is how you set the contrast on the LCD so text is crisp and clean)

Pin 4: First signal pin to controller pin socket 2 (In circuit diagram)

Pin 5: Connect to ground (In circuit diagram)

Pin 6: Second signal pin to controller pin socket 3 (In circuit diagram)

Pin 7: NOT USED

Pin 8: NOT USED

Pin 9: NOT USED

Pin 10: NOT USED

Pin 11: Third signal pin to controller pin socket 4 (In circuit diagram)

Pin 12: Fourth signal pin to controller pin socket 5 (In circuit diagram)

Pin 13: Fifth signal pin to controller pin socket 6 (In circuit diagram)

Pin 14: Sixth signal pin to controller pin socket 7 (In circuit diagram)

Pin 15: Connect to 5v power (In circuit diagram)

Pin 16: Connect to Ground (In circuit diagram)

ATX POWER SUPPLY:

Only cut the wires needed to power the device. The other wires are safer in the plastic connector and will allow you to use it for other projects if needed.

ATX Pins:

Cut and strip (Ground) black wire pin 3 and the (Signal) green wire pin 16. Attach these wires to a switch so you can turn on and off the machine (In circuit diagram)

Cut and strip (Ground) black wire pin 7 and (+12V) yellow wire pin 10. Attach these wires to the 12v side of the breadboard designated in yellow and black connections. (In circuit diagram)

Cut and strip (Ground) black wire pin 24 and (+12V) yellow wire pin 11. Attach these wires to a compatible connector to power the Arduino board (In circuit diagram)

Cut and strip (Ground) black wire pin 19 and (+5V) red wire pin 21. Attach these wires to the 5V side of the breadboard (In circuit diagram)

Shelf Dividers and Coils:

Here is how to setup your shelves and extruders.

Shelves - At the middle point 6 1/2" from the left side wall (looking at the machine from the front) or divider wall there should be a mark from the steps above. Use the flat metal and bend it into the top of a triangle. Looks just like this "^" This will serve as your middle divider. Center the triangle over the middle mark on the shelf. Repeat for the second shelf. Use hot glue to fasten in place. I put slides on the sides also but they are optional.

Coils - To create the coils first find a 1 1/2" tube. A pipe, caulk tube, spray paint can, or similar object will do. One trick is to take a rubber band and wrap it from top to bottom around the length of the tube. Trace the straight line down each side of the band on both sides of the tube. Once you have parallel lines down both sides use a tape measure to mark the next spots. Pick one side and measure in 1" and mark it, then measure 2" from there mark it and keep making 2" spaces all of the way down the tube. Now, on the other side of the tube mark only 2" intervals. Start making the coil on the 1" side of the tube and continue making your coil so it touches each mark on the both side of the tube. This will give you a 2" gap between the rungs. Should be large enough for most items. If you plan to use it for candy bard shorten the coil to 1" just reduce the formula above by half.

Connecting the coils to the 3D printed wheels. Keep in mind that there are some manufactured wheels that will work. Take a look on Amazon.

On the 1" side of the coil collapse this coil so it make a circle. Then shorten the diameter to slightly smaller then the wheel. Once the coil is ready fit it around the edge of the wheel. This should cause the coil to compress around the edge of the wheel and keep it from slipping. Once you are happy with the fit take a small dab of hot glue and put it on the wheel at the end of the coil to hold it in place.

LED Strip Lights:

Connect Positive lead to +12V pin on the 12V side of bread board. Connect the ground lead to the ground pin on the 12V side of the bread board (Not in diagram)

PLEASE ASK ALL OF THE QUESTIONS YOU HAVE SO I MAY ASSIST WITH UPDATE TO MAKE THIS THE EASIEST PROJECT EVER.

Code

Vending Machine - WITHOUT CHANGING LED LIGHTSArduino
Everything you need to complete and understand the project
// Display
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

//Stepper Library
#include <Stepper.h> //including stepper motor library

//Relay Setup
#define ENABLE 10
#define DIRA 8
#define DIRB 9

//Define "i"
int i;

//defining pins section
//Stepper Connect 1
int stepIN1Pin = 22;
int stepIN2Pin = 24;
int stepIN3Pin = 26;
int stepIN4Pin = 28;

//Stepper Connect 2
int stepIN1Pin1 = 23; 
int stepIN2Pin1 = 25;
int stepIN3Pin1 = 27;
int stepIN4Pin1 = 29;

//Stepper Connect 3
int stepIN1Pin2 = 30;
int stepIN2Pin2 = 32;
int stepIN3Pin2 = 34;
int stepIN4Pin2 = 36;

//Stepper Connect 4
int stepIN1Pin3 = 31;
int stepIN2Pin3 = 33;
int stepIN3Pin3 = 35;
int stepIN4Pin3 = 37;

//define steps
int stepsPerRevolution = 2048; // amount of steps per revolution

//define buttons pin ports
const int button1Pin = A0;  // Push Button 1 Analog Pin A0
const int button2Pin = A1;  // Push Button 2 Analog Pin A1
const int button3Pin = A2;  // Push Button 3 Analog Pin A2
const int button4Pin = A3;  // Push Button 4 Analog Pin A3

//define each stepper
// 1
Stepper myStepper0(stepsPerRevolution, stepIN1Pin, stepIN3Pin, stepIN2Pin, stepIN4Pin);
//2
Stepper myStepper1(stepsPerRevolution, stepIN1Pin1, stepIN3Pin1, stepIN2Pin1, stepIN4Pin1);
//3
Stepper myStepper2(stepsPerRevolution, stepIN1Pin2, stepIN3Pin2, stepIN2Pin2, stepIN4Pin2);
//4
Stepper myStepper3(stepsPerRevolution, stepIN1Pin3, stepIN3Pin3, stepIN2Pin3, stepIN4Pin3);

void setup() {
  // Assign Push Button Pin input:
  pinMode(button1Pin, INPUT);
  pinMode(button2Pin, INPUT);
  pinMode(button3Pin, INPUT);
  pinMode(button4Pin, INPUT);
  // Assign pin output
  pinMode(ENABLE, OUTPUT);
  pinMode(DIRA, OUTPUT);
  pinMode(DIRB,OUTPUT);

  // Assign Stepper Speed
  myStepper0.setSpeed(15);
  myStepper1.setSpeed(15);
  myStepper2.setSpeed(15);
  myStepper3.setSpeed(15);

  //Initialize LCD Display
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Select your item");
  lcd.setCursor(0, 1);
  lcd.print(" #1 #2 #3 #4");
}
void loop() {
  // read button assignment
  int button1State, button2State, button3State, button4State;
  button1State = digitalRead(button1Pin);
  button2State = digitalRead(button2Pin);
  button3State = digitalRead(button3Pin);
  button4State = digitalRead(button4Pin);
  digitalWrite(ENABLE, HIGH);// Set state
  for (i=0;i<5;i++);

  // define action when button 1 is pressed
  if (((button1State == LOW) && !(button2State == LOW)))// if we're pushing button 1 OR button 2
 {digitalWrite(DIRA,HIGH); //engage relay
   digitalWrite(DIRB,LOW);
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("Dispensing");
    lcd.setCursor(3, 1);
    lcd.print("Your Item");
    myStepper0.step(stepsPerRevolution); //run motor
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("Please take");
    lcd.setCursor(3, 1);
    lcd.print("Your Item");
    delay(2500);
    lcd.setCursor(0, 0);
    lcd.print("Button State 1");
    lcd.setCursor(2, 1);
    lcd.print("1 2 3 or 4");
    digitalWrite(DIRA,LOW); //disengage relay
   digitalWrite(DIRB,LOW);
  } 
  // define action when button 2 is pressed
  if (((button2State == LOW) && !(button1State == LOW)))  // if we're pushing button 1 OR button 2
  {digitalWrite(DIRA,HIGH); //engage relay
   digitalWrite(DIRB,LOW);
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("Dispensing");
    lcd.setCursor(3, 1);
    lcd.print("Your Item");
    myStepper1.step(stepsPerRevolution);//run motor
   lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("Please take");
    lcd.setCursor(3, 1);
    lcd.print("Your Item");
    delay(2500);
    lcd.setCursor(0, 0);
    lcd.print("Button State 2");
    lcd.setCursor(2, 1);
    lcd.print("1 2 3 or 4");
    digitalWrite(DIRA,LOW); //disengage relay
   digitalWrite(DIRB,LOW);
  }
  // define action when button 3 is pressed
  if (((button3State == LOW) && !(button4State == LOW)))  // if we're pushing button 1 OR button 2
  {digitalWrite(DIRA,HIGH); //engage relay
   digitalWrite(DIRB,LOW);
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("Dispensing");
    lcd.setCursor(3, 1);
    lcd.print("Your Item");
    myStepper2.step(stepsPerRevolution);//run motor
     lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("Please take");
    lcd.setCursor(3, 1);
    lcd.print("Your Item");
    delay(2500);
    lcd.setCursor(0, 0);
    lcd.print("Button State 3");
    lcd.setCursor(2, 1);
    lcd.print("1 2 3 or 4");
    digitalWrite(DIRA,LOW); //disengage relay
   digitalWrite(DIRB,LOW);
  }
  // define action when button 4 is pressed
  if (((button4State == LOW) && !(button3State == LOW)))  // if we're pushing button 1 OR button 2
  {digitalWrite(DIRA,HIGH); //engage relay
   digitalWrite(DIRB,LOW);
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("Dispensing");
    lcd.setCursor(3, 1);
    lcd.print("Your Item");
    myStepper3.step(-stepsPerRevolution);//run motor
   lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("Please take");
    lcd.setCursor(3, 1);
    lcd.print("Your Item");
    delay(2500);
    lcd.setCursor(0, 0);
    lcd.print("Button State 4");
    lcd.setCursor(2, 1);
    lcd.print("1 2 3 or 4");
    digitalWrite(DIRA,LOW); //disengage relay
   digitalWrite(DIRB,LOW);
  }
}
Vending Machine - WITH CHANGING LED LIGHTSC#
Take a look at the video!
// Display
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

//Stepper Library
#include <Stepper.h> //including stepper motor library

//Relay Setup
#define ENABLE 10
#define PinA 8
#define PinB 9
#define REDPIN 38
#define GREENPIN 39
#define BLUEPIN 40

//Define "i"
int i;

//Define "RGB"
int r, g, b;

//defining pins section
//Stepper Connect 1
int stepIN1Pin = 22;
int stepIN2Pin = 24;
int stepIN3Pin = 26;
int stepIN4Pin = 28;

//Stepper Connect 2
int stepIN1Pin1 = 23;
int stepIN2Pin1 = 25;
int stepIN3Pin1 = 27;
int stepIN4Pin1 = 29;

//Stepper Connect 3
int stepIN1Pin2 = 30;
int stepIN2Pin2 = 32;
int stepIN3Pin2 = 34;
int stepIN4Pin2 = 36;

//Stepper Connect 4
int stepIN1Pin3 = 31;
int stepIN2Pin3 = 33;
int stepIN3Pin3 = 35;
int stepIN4Pin3 = 37;

//define steps
int stepsPerRevolution = 2048; // amount of steps per revolution

//define buttons pin ports
const int button1Pin = A0;  // Push Button 1 Analog Pin A0
const int button2Pin = A1;  // Push Button 2 Analog Pin A1
const int button3Pin = A2;  // Push Button 3 Analog Pin A2
const int button4Pin = A3;  // Push Button 4 Analog Pin A3

//define each stepper
// 1
Stepper myStepper0(stepsPerRevolution, stepIN1Pin, stepIN3Pin, stepIN2Pin, stepIN4Pin);
//2
Stepper myStepper1(stepsPerRevolution, stepIN1Pin1, stepIN3Pin1, stepIN2Pin1, stepIN4Pin1);
//3
Stepper myStepper2(stepsPerRevolution, stepIN1Pin2, stepIN3Pin2, stepIN2Pin2, stepIN4Pin2);
//4
Stepper myStepper3(stepsPerRevolution, stepIN1Pin3, stepIN3Pin3, stepIN2Pin3, stepIN4Pin3);

void setup() {
  // Assign Push Button Pin input:
  pinMode(button1Pin, INPUT);
  pinMode(button2Pin, INPUT);
  pinMode(button3Pin, INPUT);
  pinMode(button4Pin, INPUT);

  // Assign pin output
  pinMode(ENABLE, OUTPUT);
  pinMode(PinA, OUTPUT);
  pinMode(PinB, OUTPUT);

  //LED Strips pin setup
  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);

  // Assign Stepper Speed
  myStepper0.setSpeed(15);
  myStepper1.setSpeed(15);
  myStepper2.setSpeed(15);
  myStepper3.setSpeed(15);

  //Initialize LCD Display
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Select your item");
  lcd.setCursor(0, 1);
  lcd.print(" #1 #2 #3 #4");
  analogWrite(REDPIN, 256);
  analogWrite(GREENPIN, 256);
  analogWrite(BLUEPIN, 256);
}
void loop() {
  // read button assignment
  int button1State, button2State, button3State, button4State;
  button1State = digitalRead(button1Pin);
  button2State = digitalRead(button2Pin);
  button3State = digitalRead(button3Pin);
  button4State = digitalRead(button4Pin);
  digitalWrite(ENABLE, HIGH);// Set state
  for (i = 0; i < 5; i++);

  // define action when button 1 is pressed
  if (((button1State == LOW) && !(button2State == LOW)))// if we're pushing button 1 OR button 2
  { digitalWrite(PinA, HIGH); //engage relay
    digitalWrite(PinB, LOW);
    analogWrite(REDPIN, 256);
    for (b = 256; b > 0; b--);
    analogWrite(BLUEPIN, b);
    for (g = 256; g > 0; g--);
    analogWrite(GREENPIN, g);
    for (g = 256; g > 0; g--);
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("Dispensing");
    lcd.setCursor(3, 1);
    lcd.print("Your Item");
    myStepper0.step(stepsPerRevolution); //run motor
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("Please take");
    lcd.setCursor(3, 1);
    lcd.print("Your Item");
    delay(2500);
    lcd.setCursor(0, 0);
    lcd.print("Button State 1");
    lcd.setCursor(2, 1);
    lcd.print("1 2 3 or 4");
    for (b = 0; b < 256; b++);
    analogWrite(BLUEPIN, b);
    for (g = 0; g < 256; g++);
    analogWrite(GREENPIN, g);
    digitalWrite(PinA, LOW); //disengage relay
    digitalWrite(PinB, LOW);
  }
  // define action when button 2 is pressed
  if (((button2State == LOW) && !(button1State == LOW)))  // if we're pushing button 1 OR button 2
  { digitalWrite(PinA, HIGH); //engage relay
    digitalWrite(PinB, LOW);
    analogWrite(GREENPIN, 256);
    for (b = 256; b > 0; b--);
    analogWrite(BLUEPIN, b);
    for (r = 256; r > 0; r--);
    analogWrite(REDPIN, r);
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("Dispensing");
    lcd.setCursor(3, 1);
    lcd.print("Your Item");
    myStepper1.step(stepsPerRevolution);//run motor
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("Please take");
    lcd.setCursor(3, 1);
    lcd.print("Your Item");
    delay(2500);
    lcd.setCursor(0, 0);
    lcd.print("Button State 2");
    lcd.setCursor(2, 1);
    lcd.print("1 2 3 or 4");
    digitalWrite(PinA, LOW); //disengage relay
    digitalWrite(PinB, LOW);
    for (b = 0; b < 256; b++);
    analogWrite(BLUEPIN, b);
    for (r = 0; r < 256; r++);
    analogWrite(REDPIN, r);
  }
  // define action when button 3 is pressed
  if (((button3State == LOW) && !(button4State == LOW)))  // if we're pushing button 1 OR button 2
  { digitalWrite(PinA, HIGH); //engage relay
    digitalWrite(PinB, LOW);
    analogWrite(BLUEPIN, 256);
    for (r = 256; r > 0; r--);
    analogWrite(REDPIN, r);
    for (g = 256; g > 0; g--);
    analogWrite(GREENPIN, g);
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("Dispensing");
    lcd.setCursor(3, 1);
    lcd.print("Your Item");
    myStepper2.step(stepsPerRevolution);//run motor
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("Please take");
    lcd.setCursor(3, 1);
    lcd.print("Your Item");
    delay(2500);
    lcd.setCursor(0, 0);
    lcd.print("Button State 3");
    lcd.setCursor(2, 1);
    lcd.print("1 2 3 or 4");
    digitalWrite(PinA, LOW); //disengage relay
    digitalWrite(PinB, LOW);
    for (g = 0; g < 256; g++);
    analogWrite(GREENPIN, g);
    for (r = 0; r < 256; r++);
    analogWrite(REDPIN, r);
  }
  // define action when button 4 is pressed
  if (((button4State == LOW) && !(button3State == LOW)))  // if we're pushing button 1 OR button 2
  { digitalWrite(PinA, HIGH); //engage relay
    digitalWrite(PinB, LOW);
    analogWrite(REDPIN, 256);
    analogWrite(GREENPIN, 256);
    for (b = 256; b > 0; b--);
    analogWrite(BLUEPIN, b);
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("Dispensing");
    lcd.setCursor(3, 1);
    lcd.print("Your Item");
    myStepper3.step(-stepsPerRevolution);//run motor
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("Please take");
    lcd.setCursor(3, 1);
    lcd.print("Your Item");
    delay(2500);
    lcd.setCursor(0, 0);
    lcd.print("Button State 4");
    lcd.setCursor(2, 1);
    lcd.print("1 2 3 or 4");
    digitalWrite(PinA, LOW); //disengage relay
    digitalWrite(PinB, LOW);
    for (b = 0; b < 256; b++);
    analogWrite(BLUEPIN, b);
  }
}
Coin Acceptor and complete copdeC#
Complete code
// Display
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

//Stepper Library
#include <Stepper.h> //including stepper motor library

//Relay Setup
#define ENABLE 10
//#define PinA 8
//#define PinB 9

//Transitor pins for LEDs
#define REDPIN 38
#define GREENPIN 39
#define BLUEPIN 40

//Define "i"
//int i;

//Define "RGB"
int r, g, b;

// Constants
const int coinpin = 21;
const int ledpin = 13;
const int targetcents = 100;

// Variables
volatile int cents = 0;
int credits = 0;

//defining pins section
//Stepper Connect 1
int stepIN1Pin = 22;
int stepIN2Pin = 24;
int stepIN3Pin = 26;
int stepIN4Pin = 28;

//Stepper Connect 2
int stepIN1Pin1 = 23;
int stepIN2Pin1 = 25;
int stepIN3Pin1 = 27;
int stepIN4Pin1 = 29;

//Stepper Connect 3
int stepIN1Pin2 = 30;
int stepIN2Pin2 = 32;
int stepIN3Pin2 = 34;
int stepIN4Pin2 = 36;

//Stepper Connect 4
int stepIN1Pin3 = 31;
int stepIN2Pin3 = 33;
int stepIN3Pin3 = 35;
int stepIN4Pin3 = 37;

//define steps
int stepsPerRevolution = 2048; // amount of steps per revolution

//define buttons pin ports
const int button1Pin = A0;  // Push Button 1 Analog Pin A0
const int button2Pin = A1;  // Push Button 2 Analog Pin A1
const int button3Pin = A2;  // Push Button 3 Analog Pin A2
const int button4Pin = A3;  // Push Button 4 Analog Pin A3

//define each stepper
// 1
Stepper myStepper0(stepsPerRevolution, stepIN1Pin, stepIN3Pin, stepIN2Pin, stepIN4Pin);
//2
Stepper myStepper1(stepsPerRevolution, stepIN1Pin1, stepIN3Pin1, stepIN2Pin1, stepIN4Pin1);
//3
Stepper myStepper2(stepsPerRevolution, stepIN1Pin2, stepIN3Pin2, stepIN2Pin2, stepIN4Pin2);
//4
Stepper myStepper3(stepsPerRevolution, stepIN1Pin3, stepIN3Pin3, stepIN2Pin3, stepIN4Pin3);


// Setup
void setup() {

  // Assign interupt to Pin and condition
  attachInterrupt(digitalPinToInterrupt(coinpin), coinInterrupt, RISING);
  // Assign Push Button Pin input:
  pinMode(button1Pin, INPUT);
  pinMode(button2Pin, INPUT);
  pinMode(button3Pin, INPUT);
  pinMode(button4Pin, INPUT);

  // Assign relay pin output
  pinMode(ENABLE, OUTPUT);
//  pinMode(PinA, OUTPUT);
//  pinMode(PinB, OUTPUT);

  //LED Strips pin setup
  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);

  // Assign Stepper Speed
  myStepper0.setSpeed(15);
  myStepper1.setSpeed(15);
  myStepper2.setSpeed(15);
  myStepper3.setSpeed(15);

  //Initialize LCD Display
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Select your item");
  lcd.setCursor(0, 1);
  lcd.print(" #1 #2 #3 #4");
  analogWrite(REDPIN, 256);
  analogWrite(GREENPIN, 256);
  analogWrite(BLUEPIN, 256);
}

// Main loop
void loop() {

  // If we've hit our target amount of coins, increment our credits and reset the cents counter
  if (cents >= targetcents) {
    credits = credits + 1;
    cents = cents - targetcents;
  }

  // If we haven't reached our target, keep waiting...
  else {
  }

  // Debugging zone
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(cents);
  lcd.setCursor(3, 0);
  lcd.print("Coin Count");
  lcd.setCursor(0, 1);
  lcd.print(credits);
  lcd.setCursor(3, 1);
  lcd.print("credit earned");
  delay(1000);

  // Now, write your own code here that triggers an event when the player has credits!
  if (credits > 0) {
    // read button assignment
    int button1State, button2State, button3State, button4State;
    button1State = digitalRead(button1Pin);
    button2State = digitalRead(button2Pin);
    button3State = digitalRead(button3Pin);
    button4State = digitalRead(button4Pin);
 //   digitalWrite(ENABLE, HIGH);// Set state
 //   for (i = 0; i < 5; i++);

    // define action when button 1 is pressed
    if (((button1State == LOW) && !(button2State == LOW)))// if we're pushing button 1 OR button 2
    { digitalWrite(ENABLE, HIGH); //engage relay
//      digitalWrite(PinB, LOW);
      analogWrite(REDPIN, 256);
      for (b = 256; b > 0; b--);
      analogWrite(BLUEPIN, b);
      for (g = 256; g > 0; g--);
  
      analogWrite(GREENPIN, g);
      for (g = 256; g > 0; g--);
      lcd.clear();
      lcd.setCursor(2, 0);
      lcd.print("Dispensing");
      lcd.setCursor(3, 1);
      lcd.print("Your Item");
      myStepper0.step(stepsPerRevolution); //run motor
      lcd.clear();
      lcd.setCursor(2, 0);
      lcd.print("Please take");
      lcd.setCursor(3, 1);
      lcd.print("Your Item");
      delay(2500);
      for (b = 0; b < 256; b++);
      analogWrite(BLUEPIN, b);
      for (g = 0; g < 256; g++);
      analogWrite(GREENPIN, g);
      digitalWrite(ENABLE, LOW); //disengage relay
//      digitalWrite(PinB, LOW);
      credits = credits - 1;
      cents = cents - cents;
    }
    // define action when button 2 is pressed
    if (((button2State == LOW) && !(button1State == LOW)))  // if we're pushing button 1 OR button 2
    { digitalWrite(ENABLE, HIGH); //engage relay
//      digitalWrite(PinB, LOW);
      analogWrite(GREENPIN, 256);
      for (b = 256; b > 0; b--);
      analogWrite(BLUEPIN, b);
      for (r = 256; r > 0; r--);
      analogWrite(REDPIN, r);
      lcd.clear();
      lcd.setCursor(2, 0);
      lcd.print("Dispensing");
      lcd.setCursor(3, 1);
      lcd.print("Your Item");
      myStepper1.step(stepsPerRevolution);//run motor
      lcd.clear();
      lcd.setCursor(2, 0);
      lcd.print("Please take");
      lcd.setCursor(3, 1);
      lcd.print("Your Item");
      delay(2500);
      digitalWrite(ENABLE, LOW); //disengage relay
//      digitalWrite(PinB, LOW);
      for (b = 0; b < 256; b++);
      analogWrite(BLUEPIN, b);
      for (r = 0; r < 256; r++);
      analogWrite(REDPIN, r);
      credits = credits - 1;
      cents = cents - cents;
    }
    // define action when button 3 is pressed
    if (((button3State == LOW) && !(button4State == LOW)))  // if we're pushing button 1 OR button 2
    { digitalWrite(ENABLE, HIGH); //engage relay
//      digitalWrite(PinB, LOW);
      analogWrite(BLUEPIN, 256);
      for (r = 256; r > 0; r--);
      analogWrite(REDPIN, r);
      for (g = 256; g > 0; g--);
      analogWrite(GREENPIN, g);
      lcd.clear();
      lcd.setCursor(2, 0);
      lcd.print("Dispensing");
      lcd.setCursor(3, 1);
      lcd.print("Your Item");
      myStepper2.step(stepsPerRevolution);//run motor
      lcd.clear();
      lcd.setCursor(2, 0);
      lcd.print("Please take");
      lcd.setCursor(3, 1);
      lcd.print("Your Item");
      delay(2500);
      digitalWrite(ENABLE, LOW); //disengage relay
//      digitalWrite(PinB, LOW);
      for (g = 0; g < 256; g++);
      analogWrite(GREENPIN, g);
      for (r = 0; r < 256; r++);
      analogWrite(REDPIN, r);
      credits = credits - 1;
      cents = cents - cents;
    }
    // define action when button 4 is pressed
    if (((button4State == LOW) && !(button3State == LOW)))  // if we're pushing button 1 OR button 2
    { digitalWrite(ENABLE, HIGH); //! engage relay
//      digitalWrite(PinB, LOW);
      analogWrite(REDPIN, 256);
      analogWrite(GREENPIN, 256);
      for (b = 256; b > 0; b--);
      analogWrite(BLUEPIN, b);
      lcd.clear();
      lcd.setCursor(2, 0);
      lcd.print("Dispensing");
      lcd.setCursor(3, 1);
      lcd.print("Your Item");
      myStepper3.step(-stepsPerRevolution);//run motor
      lcd.clear();
      lcd.setCursor(2, 0);
      lcd.print("Please take");
      lcd.setCursor(3, 1);
      lcd.print("Your Item");
      delay(2500);
      digitalWrite(ENABLE, LOW); //disengage relay
//      digitalWrite(PinB, LOW);
      for (b = 0; b < 256; b++);
      analogWrite(BLUEPIN, b);
      credits = credits - 1;
      cents = cents - cents;
    }
  }
}

// Coin Increase loop
void coinInterrupt() {

  // Each time a pulse is sent from the coin acceptor, interrupt main loop to add 5 cent and flip on the LED
  cents = cents + 5;
  digitalWrite(ledpin, HIGH);
}

Schematics

Wire Diagram
This is a complete Diagram of the system. It includes, ATX power supply, motors,LCD,LEDs, lights and controller
Capture ngolkimdeh

Comments

Similar projects you might like

Arduino-Based Bitcoin Candy Vending Machine

Project tutorial by Team Elkrem

  • 4,485 views
  • 18 comments
  • 43 respects

DIY Vending Machine using Arduino & 1Sheeld

Project tutorial by Mahmoud Ahmed

  • 7,487 views
  • 7 comments
  • 32 respects

Snacks Vending Machine Powered By Arduino

Project tutorial by Sevenmojoe

  • 18,732 views
  • 13 comments
  • 90 respects

Smart Personal Money Vault Monitoring System Based on IoT

Project tutorial by Salah Uddin

  • 1,020 views
  • 0 comments
  • 6 respects

Personal Weather Station (Arduino+ ESP8266 + Thingspeak)

Project tutorial by Jayraj Desai

  • 54,523 views
  • 34 comments
  • 114 respects

Personal Home Assistant

Project tutorial by 3 developers

  • 4,452 views
  • 0 comments
  • 29 respects
Add projectSign up / Login