comptek4
Published © GPL3+

Coin Op Personal Vending Machine

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

BeginnerFull instructions provided21,684
Coin Op Personal Vending Machine

Things used in this project

Hardware components

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
Breadboard (generic)
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
Arduino Mega 2560
Arduino 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

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

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

Story

Read more

Schematics

Wire Diagram

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

Code

Vending Machine - WITHOUT CHANGING LED LIGHTS

Arduino
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 LIGHTS

C#
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 copde

C#
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);
}

Credits

comptek4

comptek4

0 projects • 15 followers

Comments