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.
Components and supplies
Arduino Mega 2560 Rev3
Breadboard (generic)
Flat metal shelf divider
HiLetgo 2pcs 1602 Serial LCD Module Display
Pc Accessories - Connectors Pro IDC 1.27mm Pitch Rainbow Color Flat Ribbon Cable for 2.54mm Connectors (50P-10FT)
Glarks 635Pcs Dupont Connector Housing Male/Female Pin Connector 40 Pin
Tolako 5v Relay Module for Arduino ARM
LAFVIN 5 Sets 28BYJ-48 ULN2003 5V Stepper Motor + ULN2003 Driver Board for Arduino
1/4 Plywood
50 ft. 8-Gauge Solid SD Bare Copper Grounding Wire
LED Light Strips
30 Pcs Double Sided PCB Board Prototype Kit
3/4" plywood blocking
Gamelec-Illuminated-Replacement-Microswitch
Tools and machines
Hot glue gun (generic)
Soldering iron (generic)
Table or power saw
Apps and platforms
Arduino IDE
Project description
Code
Vending Machine - WITH CHANGING LED LIGHTS
csharp
Take a look at the video!
1// Display 2#include <LiquidCrystal.h> 3LiquidCrystal lcd(2, 3, 4, 5, 6, 7); 4 5//Stepper Library 6#include <Stepper.h> //including stepper motor library 7 8//Relay Setup 9#define ENABLE 10 10#define PinA 8 11#define PinB 9 12#define REDPIN 38 13#define GREENPIN 39 14#define BLUEPIN 40 15 16//Define "i" 17int i; 18 19//Define "RGB" 20int r, g, b; 21 22//defining pins section 23//Stepper Connect 1 24int stepIN1Pin = 22; 25int stepIN2Pin = 24; 26int stepIN3Pin = 26; 27int stepIN4Pin = 28; 28 29//Stepper Connect 2 30int stepIN1Pin1 = 23; 31int stepIN2Pin1 = 25; 32int stepIN3Pin1 = 27; 33int stepIN4Pin1 = 29; 34 35//Stepper Connect 3 36int stepIN1Pin2 = 30; 37int stepIN2Pin2 = 32; 38int stepIN3Pin2 = 34; 39int stepIN4Pin2 = 36; 40 41//Stepper Connect 4 42int stepIN1Pin3 = 31; 43int stepIN2Pin3 = 33; 44int stepIN3Pin3 = 35; 45int stepIN4Pin3 = 37; 46 47//define steps 48int stepsPerRevolution = 2048; // amount of steps per revolution 49 50//define buttons pin ports 51const int button1Pin = A0; // Push Button 1 Analog Pin A0 52const int button2Pin = A1; // Push Button 2 Analog Pin A1 53const int button3Pin = A2; // Push Button 3 Analog Pin A2 54const int button4Pin = A3; // Push Button 4 Analog Pin A3 55 56//define each stepper 57// 1 58Stepper myStepper0(stepsPerRevolution, stepIN1Pin, stepIN3Pin, stepIN2Pin, stepIN4Pin); 59//2 60Stepper myStepper1(stepsPerRevolution, stepIN1Pin1, stepIN3Pin1, stepIN2Pin1, stepIN4Pin1); 61//3 62Stepper myStepper2(stepsPerRevolution, stepIN1Pin2, stepIN3Pin2, stepIN2Pin2, stepIN4Pin2); 63//4 64Stepper myStepper3(stepsPerRevolution, stepIN1Pin3, stepIN3Pin3, stepIN2Pin3, stepIN4Pin3); 65 66void setup() { 67 // Assign Push Button Pin input: 68 pinMode(button1Pin, INPUT); 69 pinMode(button2Pin, INPUT); 70 pinMode(button3Pin, INPUT); 71 pinMode(button4Pin, INPUT); 72 73 // Assign pin output 74 pinMode(ENABLE, OUTPUT); 75 pinMode(PinA, OUTPUT); 76 pinMode(PinB, OUTPUT); 77 78 //LED Strips pin setup 79 pinMode(REDPIN, OUTPUT); 80 pinMode(GREENPIN, OUTPUT); 81 pinMode(BLUEPIN, OUTPUT); 82 83 // Assign Stepper Speed 84 myStepper0.setSpeed(15); 85 myStepper1.setSpeed(15); 86 myStepper2.setSpeed(15); 87 myStepper3.setSpeed(15); 88 89 //Initialize LCD Display 90 lcd.begin(16, 2); 91 lcd.clear(); 92 lcd.setCursor(0, 0); 93 lcd.print("Select your item"); 94 lcd.setCursor(0, 1); 95 lcd.print(" #1 #2 #3 #4"); 96 analogWrite(REDPIN, 256); 97 analogWrite(GREENPIN, 256); 98 analogWrite(BLUEPIN, 256); 99} 100void loop() { 101 // read button assignment 102 int button1State, button2State, button3State, button4State; 103 button1State = digitalRead(button1Pin); 104 button2State = digitalRead(button2Pin); 105 button3State = digitalRead(button3Pin); 106 button4State = digitalRead(button4Pin); 107 digitalWrite(ENABLE, HIGH);// Set state 108 for (i = 0; i < 5; i++); 109 110 // define action when button 1 is pressed 111 if (((button1State == LOW) && !(button2State == LOW)))// if we're pushing button 1 OR button 2 112 { digitalWrite(PinA, HIGH); //engage relay 113 digitalWrite(PinB, LOW); 114 analogWrite(REDPIN, 256); 115 for (b = 256; b > 0; b--); 116 analogWrite(BLUEPIN, b); 117 for (g = 256; g > 0; g--); 118 analogWrite(GREENPIN, g); 119 for (g = 256; g > 0; g--); 120 lcd.clear(); 121 lcd.setCursor(2, 0); 122 lcd.print("Dispensing"); 123 lcd.setCursor(3, 1); 124 lcd.print("Your Item"); 125 myStepper0.step(stepsPerRevolution); //run motor 126 lcd.clear(); 127 lcd.setCursor(2, 0); 128 lcd.print("Please take"); 129 lcd.setCursor(3, 1); 130 lcd.print("Your Item"); 131 delay(2500); 132 lcd.setCursor(0, 0); 133 lcd.print("Button State 1"); 134 lcd.setCursor(2, 1); 135 lcd.print("1 2 3 or 4"); 136 for (b = 0; b < 256; b++); 137 analogWrite(BLUEPIN, b); 138 for (g = 0; g < 256; g++); 139 analogWrite(GREENPIN, g); 140 digitalWrite(PinA, LOW); //disengage relay 141 digitalWrite(PinB, LOW); 142 } 143 // define action when button 2 is pressed 144 if (((button2State == LOW) && !(button1State == LOW))) // if we're pushing button 1 OR button 2 145 { digitalWrite(PinA, HIGH); //engage relay 146 digitalWrite(PinB, LOW); 147 analogWrite(GREENPIN, 256); 148 for (b = 256; b > 0; b--); 149 analogWrite(BLUEPIN, b); 150 for (r = 256; r > 0; r--); 151 analogWrite(REDPIN, r); 152 lcd.clear(); 153 lcd.setCursor(2, 0); 154 lcd.print("Dispensing"); 155 lcd.setCursor(3, 1); 156 lcd.print("Your Item"); 157 myStepper1.step(stepsPerRevolution);//run motor 158 lcd.clear(); 159 lcd.setCursor(2, 0); 160 lcd.print("Please take"); 161 lcd.setCursor(3, 1); 162 lcd.print("Your Item"); 163 delay(2500); 164 lcd.setCursor(0, 0); 165 lcd.print("Button State 2"); 166 lcd.setCursor(2, 1); 167 lcd.print("1 2 3 or 4"); 168 digitalWrite(PinA, LOW); //disengage relay 169 digitalWrite(PinB, LOW); 170 for (b = 0; b < 256; b++); 171 analogWrite(BLUEPIN, b); 172 for (r = 0; r < 256; r++); 173 analogWrite(REDPIN, r); 174 } 175 // define action when button 3 is pressed 176 if (((button3State == LOW) && !(button4State == LOW))) // if we're pushing button 1 OR button 2 177 { digitalWrite(PinA, HIGH); //engage relay 178 digitalWrite(PinB, LOW); 179 analogWrite(BLUEPIN, 256); 180 for (r = 256; r > 0; r--); 181 analogWrite(REDPIN, r); 182 for (g = 256; g > 0; g--); 183 analogWrite(GREENPIN, g); 184 lcd.clear(); 185 lcd.setCursor(2, 0); 186 lcd.print("Dispensing"); 187 lcd.setCursor(3, 1); 188 lcd.print("Your Item"); 189 myStepper2.step(stepsPerRevolution);//run motor 190 lcd.clear(); 191 lcd.setCursor(2, 0); 192 lcd.print("Please take"); 193 lcd.setCursor(3, 1); 194 lcd.print("Your Item"); 195 delay(2500); 196 lcd.setCursor(0, 0); 197 lcd.print("Button State 3"); 198 lcd.setCursor(2, 1); 199 lcd.print("1 2 3 or 4"); 200 digitalWrite(PinA, LOW); //disengage relay 201 digitalWrite(PinB, LOW); 202 for (g = 0; g < 256; g++); 203 analogWrite(GREENPIN, g); 204 for (r = 0; r < 256; r++); 205 analogWrite(REDPIN, r); 206 } 207 // define action when button 4 is pressed 208 if (((button4State == LOW) && !(button3State == LOW))) // if we're pushing button 1 OR button 2 209 { digitalWrite(PinA, HIGH); //engage relay 210 digitalWrite(PinB, LOW); 211 analogWrite(REDPIN, 256); 212 analogWrite(GREENPIN, 256); 213 for (b = 256; b > 0; b--); 214 analogWrite(BLUEPIN, b); 215 lcd.clear(); 216 lcd.setCursor(2, 0); 217 lcd.print("Dispensing"); 218 lcd.setCursor(3, 1); 219 lcd.print("Your Item"); 220 myStepper3.step(-stepsPerRevolution);//run motor 221 lcd.clear(); 222 lcd.setCursor(2, 0); 223 lcd.print("Please take"); 224 lcd.setCursor(3, 1); 225 lcd.print("Your Item"); 226 delay(2500); 227 lcd.setCursor(0, 0); 228 lcd.print("Button State 4"); 229 lcd.setCursor(2, 1); 230 lcd.print("1 2 3 or 4"); 231 digitalWrite(PinA, LOW); //disengage relay 232 digitalWrite(PinB, LOW); 233 for (b = 0; b < 256; b++); 234 analogWrite(BLUEPIN, b); 235 } 236}
Vending Machine - WITHOUT CHANGING LED LIGHTS
arduino
Everything you need to complete and understand the project
1// Display 2#include <LiquidCrystal.h> 3LiquidCrystal lcd(2, 3, 4, 5, 6, 7); 4 5//Stepper Library 6#include <Stepper.h> //including stepper motor library 7 8//Relay Setup 9#define ENABLE 10 10#define DIRA 8 11#define DIRB 9 12 13//Define "i" 14int i; 15 16//defining pins section 17//Stepper Connect 1 18int stepIN1Pin = 22; 19int stepIN2Pin = 24; 20int stepIN3Pin = 26; 21int stepIN4Pin = 28; 22 23//Stepper Connect 2 24int stepIN1Pin1 = 23; 25int stepIN2Pin1 = 25; 26int stepIN3Pin1 = 27; 27int stepIN4Pin1 = 29; 28 29//Stepper Connect 3 30int stepIN1Pin2 = 30; 31int stepIN2Pin2 = 32; 32int stepIN3Pin2 = 34; 33int stepIN4Pin2 = 36; 34 35//Stepper Connect 4 36int stepIN1Pin3 = 31; 37int stepIN2Pin3 = 33; 38int stepIN3Pin3 = 35; 39int stepIN4Pin3 = 37; 40 41//define steps 42int stepsPerRevolution = 2048; // amount of steps per revolution 43 44//define buttons pin ports 45const int button1Pin = A0; // Push Button 1 Analog Pin A0 46const int button2Pin = A1; // Push Button 2 Analog Pin A1 47const int button3Pin = A2; // Push Button 3 Analog Pin A2 48const int button4Pin = A3; // Push Button 4 Analog Pin A3 49 50//define each stepper 51// 1 52Stepper myStepper0(stepsPerRevolution, stepIN1Pin, stepIN3Pin, stepIN2Pin, stepIN4Pin); 53//2 54Stepper myStepper1(stepsPerRevolution, stepIN1Pin1, stepIN3Pin1, stepIN2Pin1, stepIN4Pin1); 55//3 56Stepper myStepper2(stepsPerRevolution, stepIN1Pin2, stepIN3Pin2, stepIN2Pin2, stepIN4Pin2); 57//4 58Stepper myStepper3(stepsPerRevolution, stepIN1Pin3, stepIN3Pin3, stepIN2Pin3, stepIN4Pin3); 59 60void setup() { 61 // Assign Push Button Pin input: 62 pinMode(button1Pin, INPUT); 63 pinMode(button2Pin, INPUT); 64 pinMode(button3Pin, INPUT); 65 pinMode(button4Pin, INPUT); 66 // Assign pin output 67 pinMode(ENABLE, OUTPUT); 68 pinMode(DIRA, OUTPUT); 69 pinMode(DIRB,OUTPUT); 70 71 // Assign Stepper Speed 72 myStepper0.setSpeed(15); 73 myStepper1.setSpeed(15); 74 myStepper2.setSpeed(15); 75 myStepper3.setSpeed(15); 76 77 //Initialize LCD Display 78 lcd.begin(16, 2); 79 lcd.clear(); 80 lcd.setCursor(0, 0); 81 lcd.print("Select your item"); 82 lcd.setCursor(0, 1); 83 lcd.print(" #1 #2 #3 #4"); 84} 85void loop() { 86 // read button assignment 87 int button1State, button2State, button3State, button4State; 88 button1State = digitalRead(button1Pin); 89 button2State = digitalRead(button2Pin); 90 button3State = digitalRead(button3Pin); 91 button4State = digitalRead(button4Pin); 92 digitalWrite(ENABLE, HIGH);// Set state 93 for (i=0;i<5;i++); 94 95 // define action when button 1 is pressed 96 if (((button1State == LOW) && !(button2State == LOW)))// if we're pushing button 1 OR button 2 97 {digitalWrite(DIRA,HIGH); //engage relay 98 digitalWrite(DIRB,LOW); 99 lcd.clear(); 100 lcd.setCursor(2, 0); 101 lcd.print("Dispensing"); 102 lcd.setCursor(3, 1); 103 lcd.print("Your Item"); 104 myStepper0.step(stepsPerRevolution); //run motor 105 lcd.clear(); 106 lcd.setCursor(2, 0); 107 lcd.print("Please take"); 108 lcd.setCursor(3, 1); 109 lcd.print("Your Item"); 110 delay(2500); 111 lcd.setCursor(0, 0); 112 lcd.print("Button State 1"); 113 lcd.setCursor(2, 1); 114 lcd.print("1 2 3 or 4"); 115 digitalWrite(DIRA,LOW); //disengage relay 116 digitalWrite(DIRB,LOW); 117 } 118 // define action when button 2 is pressed 119 if (((button2State == LOW) && !(button1State == LOW))) // if we're pushing button 1 OR button 2 120 {digitalWrite(DIRA,HIGH); //engage relay 121 digitalWrite(DIRB,LOW); 122 lcd.clear(); 123 lcd.setCursor(2, 0); 124 lcd.print("Dispensing"); 125 lcd.setCursor(3, 1); 126 lcd.print("Your Item"); 127 myStepper1.step(stepsPerRevolution);//run motor 128 lcd.clear(); 129 lcd.setCursor(2, 0); 130 lcd.print("Please take"); 131 lcd.setCursor(3, 1); 132 lcd.print("Your Item"); 133 delay(2500); 134 lcd.setCursor(0, 0); 135 lcd.print("Button State 2"); 136 lcd.setCursor(2, 1); 137 lcd.print("1 2 3 or 4"); 138 digitalWrite(DIRA,LOW); //disengage relay 139 digitalWrite(DIRB,LOW); 140 } 141 // define action when button 3 is pressed 142 if (((button3State == LOW) && !(button4State == LOW))) // if we're pushing button 1 OR button 2 143 {digitalWrite(DIRA,HIGH); //engage relay 144 digitalWrite(DIRB,LOW); 145 lcd.clear(); 146 lcd.setCursor(2, 0); 147 lcd.print("Dispensing"); 148 lcd.setCursor(3, 1); 149 lcd.print("Your Item"); 150 myStepper2.step(stepsPerRevolution);//run motor 151 lcd.clear(); 152 lcd.setCursor(2, 0); 153 lcd.print("Please take"); 154 lcd.setCursor(3, 1); 155 lcd.print("Your Item"); 156 delay(2500); 157 lcd.setCursor(0, 0); 158 lcd.print("Button State 3"); 159 lcd.setCursor(2, 1); 160 lcd.print("1 2 3 or 4"); 161 digitalWrite(DIRA,LOW); //disengage relay 162 digitalWrite(DIRB,LOW); 163 } 164 // define action when button 4 is pressed 165 if (((button4State == LOW) && !(button3State == LOW))) // if we're pushing button 1 OR button 2 166 {digitalWrite(DIRA,HIGH); //engage relay 167 digitalWrite(DIRB,LOW); 168 lcd.clear(); 169 lcd.setCursor(2, 0); 170 lcd.print("Dispensing"); 171 lcd.setCursor(3, 1); 172 lcd.print("Your Item"); 173 myStepper3.step(-stepsPerRevolution);//run motor 174 lcd.clear(); 175 lcd.setCursor(2, 0); 176 lcd.print("Please take"); 177 lcd.setCursor(3, 1); 178 lcd.print("Your Item"); 179 delay(2500); 180 lcd.setCursor(0, 0); 181 lcd.print("Button State 4"); 182 lcd.setCursor(2, 1); 183 lcd.print("1 2 3 or 4"); 184 digitalWrite(DIRA,LOW); //disengage relay 185 digitalWrite(DIRB,LOW); 186 } 187} 188
Coin Acceptor and complete copde
csharp
Complete code
1// Display 2#include <LiquidCrystal.h> 3LiquidCrystal lcd(2, 3, 4, 5, 6, 7); 4 5//Stepper Library 6#include <Stepper.h> //including stepper motor library 7 8//Relay Setup 9#define ENABLE 10 10//#define PinA 8 11//#define PinB 9 12 13//Transitor pins for LEDs 14#define REDPIN 38 15#define GREENPIN 39 16#define BLUEPIN 40 17 18//Define "i" 19//int i; 20 21//Define "RGB" 22int r, g, b; 23 24// Constants 25const int coinpin = 21; 26const int ledpin = 13; 27const int targetcents = 100; 28 29// Variables 30volatile int cents = 0; 31int credits = 0; 32 33//defining pins section 34//Stepper Connect 1 35int stepIN1Pin = 22; 36int stepIN2Pin = 24; 37int stepIN3Pin = 26; 38int stepIN4Pin = 28; 39 40//Stepper Connect 2 41int stepIN1Pin1 = 23; 42int stepIN2Pin1 = 25; 43int stepIN3Pin1 = 27; 44int stepIN4Pin1 = 29; 45 46//Stepper Connect 3 47int stepIN1Pin2 = 30; 48int stepIN2Pin2 = 32; 49int stepIN3Pin2 = 34; 50int stepIN4Pin2 = 36; 51 52//Stepper Connect 4 53int stepIN1Pin3 = 31; 54int stepIN2Pin3 = 33; 55int stepIN3Pin3 = 35; 56int stepIN4Pin3 = 37; 57 58//define steps 59int stepsPerRevolution = 2048; // amount of steps per revolution 60 61//define buttons pin ports 62const int button1Pin = A0; // Push Button 1 Analog Pin A0 63const int button2Pin = A1; // Push Button 2 Analog Pin A1 64const int button3Pin = A2; // Push Button 3 Analog Pin A2 65const int button4Pin = A3; // Push Button 4 Analog Pin A3 66 67//define each stepper 68// 1 69Stepper myStepper0(stepsPerRevolution, stepIN1Pin, stepIN3Pin, stepIN2Pin, stepIN4Pin); 70//2 71Stepper myStepper1(stepsPerRevolution, stepIN1Pin1, stepIN3Pin1, stepIN2Pin1, stepIN4Pin1); 72//3 73Stepper myStepper2(stepsPerRevolution, stepIN1Pin2, stepIN3Pin2, stepIN2Pin2, stepIN4Pin2); 74//4 75Stepper myStepper3(stepsPerRevolution, stepIN1Pin3, stepIN3Pin3, stepIN2Pin3, stepIN4Pin3); 76 77 78// Setup 79void setup() { 80 81 // Assign interupt to Pin and condition 82 attachInterrupt(digitalPinToInterrupt(coinpin), coinInterrupt, RISING); 83 // Assign Push Button Pin input: 84 pinMode(button1Pin, INPUT); 85 pinMode(button2Pin, INPUT); 86 pinMode(button3Pin, INPUT); 87 pinMode(button4Pin, INPUT); 88 89 // Assign relay pin output 90 pinMode(ENABLE, OUTPUT); 91// pinMode(PinA, OUTPUT); 92// pinMode(PinB, OUTPUT); 93 94 //LED Strips pin setup 95 pinMode(REDPIN, OUTPUT); 96 pinMode(GREENPIN, OUTPUT); 97 pinMode(BLUEPIN, OUTPUT); 98 99 // Assign Stepper Speed 100 myStepper0.setSpeed(15); 101 myStepper1.setSpeed(15); 102 myStepper2.setSpeed(15); 103 myStepper3.setSpeed(15); 104 105 //Initialize LCD Display 106 lcd.begin(16, 2); 107 lcd.clear(); 108 lcd.setCursor(0, 0); 109 lcd.print("Select your item"); 110 lcd.setCursor(0, 1); 111 lcd.print(" #1 #2 #3 #4"); 112 analogWrite(REDPIN, 256); 113 analogWrite(GREENPIN, 256); 114 analogWrite(BLUEPIN, 256); 115} 116 117// Main loop 118void loop() { 119 120 // If we've hit our target amount of coins, increment our credits and reset the cents counter 121 if (cents >= targetcents) { 122 credits = credits + 1; 123 cents = cents - targetcents; 124 } 125 126 // If we haven't reached our target, keep waiting... 127 else { 128 } 129 130 // Debugging zone 131 lcd.begin(16, 2); 132 lcd.clear(); 133 lcd.setCursor(0, 0); 134 lcd.print(cents); 135 lcd.setCursor(3, 0); 136 lcd.print("Coin Count"); 137 lcd.setCursor(0, 1); 138 lcd.print(credits); 139 lcd.setCursor(3, 1); 140 lcd.print("credit earned"); 141 delay(1000); 142 143 // Now, write your own code here that triggers an event when the player has credits! 144 if (credits > 0) { 145 // read button assignment 146 int button1State, button2State, button3State, button4State; 147 button1State = digitalRead(button1Pin); 148 button2State = digitalRead(button2Pin); 149 button3State = digitalRead(button3Pin); 150 button4State = digitalRead(button4Pin); 151 // digitalWrite(ENABLE, HIGH);// Set state 152 // for (i = 0; i < 5; i++); 153 154 // define action when button 1 is pressed 155 if (((button1State == LOW) && !(button2State == LOW)))// if we're pushing button 1 OR button 2 156 { digitalWrite(ENABLE, HIGH); //engage relay 157// digitalWrite(PinB, LOW); 158 analogWrite(REDPIN, 256); 159 for (b = 256; b > 0; b--); 160 analogWrite(BLUEPIN, b); 161 for (g = 256; g > 0; g--); 162 163 analogWrite(GREENPIN, g); 164 for (g = 256; g > 0; g--); 165 lcd.clear(); 166 lcd.setCursor(2, 0); 167 lcd.print("Dispensing"); 168 lcd.setCursor(3, 1); 169 lcd.print("Your Item"); 170 myStepper0.step(stepsPerRevolution); //run motor 171 lcd.clear(); 172 lcd.setCursor(2, 0); 173 lcd.print("Please take"); 174 lcd.setCursor(3, 1); 175 lcd.print("Your Item"); 176 delay(2500); 177 for (b = 0; b < 256; b++); 178 analogWrite(BLUEPIN, b); 179 for (g = 0; g < 256; g++); 180 analogWrite(GREENPIN, g); 181 digitalWrite(ENABLE, LOW); //disengage relay 182// digitalWrite(PinB, LOW); 183 credits = credits - 1; 184 cents = cents - cents; 185 } 186 // define action when button 2 is pressed 187 if (((button2State == LOW) && !(button1State == LOW))) // if we're pushing button 1 OR button 2 188 { digitalWrite(ENABLE, HIGH); //engage relay 189// digitalWrite(PinB, LOW); 190 analogWrite(GREENPIN, 256); 191 for (b = 256; b > 0; b--); 192 analogWrite(BLUEPIN, b); 193 for (r = 256; r > 0; r--); 194 analogWrite(REDPIN, r); 195 lcd.clear(); 196 lcd.setCursor(2, 0); 197 lcd.print("Dispensing"); 198 lcd.setCursor(3, 1); 199 lcd.print("Your Item"); 200 myStepper1.step(stepsPerRevolution);//run motor 201 lcd.clear(); 202 lcd.setCursor(2, 0); 203 lcd.print("Please take"); 204 lcd.setCursor(3, 1); 205 lcd.print("Your Item"); 206 delay(2500); 207 digitalWrite(ENABLE, LOW); //disengage relay 208// digitalWrite(PinB, LOW); 209 for (b = 0; b < 256; b++); 210 analogWrite(BLUEPIN, b); 211 for (r = 0; r < 256; r++); 212 analogWrite(REDPIN, r); 213 credits = credits - 1; 214 cents = cents - cents; 215 } 216 // define action when button 3 is pressed 217 if (((button3State == LOW) && !(button4State == LOW))) // if we're pushing button 1 OR button 2 218 { digitalWrite(ENABLE, HIGH); //engage relay 219// digitalWrite(PinB, LOW); 220 analogWrite(BLUEPIN, 256); 221 for (r = 256; r > 0; r--); 222 analogWrite(REDPIN, r); 223 for (g = 256; g > 0; g--); 224 analogWrite(GREENPIN, g); 225 lcd.clear(); 226 lcd.setCursor(2, 0); 227 lcd.print("Dispensing"); 228 lcd.setCursor(3, 1); 229 lcd.print("Your Item"); 230 myStepper2.step(stepsPerRevolution);//run motor 231 lcd.clear(); 232 lcd.setCursor(2, 0); 233 lcd.print("Please take"); 234 lcd.setCursor(3, 1); 235 lcd.print("Your Item"); 236 delay(2500); 237 digitalWrite(ENABLE, LOW); //disengage relay 238// digitalWrite(PinB, LOW); 239 for (g = 0; g < 256; g++); 240 analogWrite(GREENPIN, g); 241 for (r = 0; r < 256; r++); 242 analogWrite(REDPIN, r); 243 credits = credits - 1; 244 cents = cents - cents; 245 } 246 // define action when button 4 is pressed 247 if (((button4State == LOW) && !(button3State == LOW))) // if we're pushing button 1 OR button 2 248 { digitalWrite(ENABLE, HIGH); //! engage relay 249// digitalWrite(PinB, LOW); 250 analogWrite(REDPIN, 256); 251 analogWrite(GREENPIN, 256); 252 for (b = 256; b > 0; b--); 253 analogWrite(BLUEPIN, b); 254 lcd.clear(); 255 lcd.setCursor(2, 0); 256 lcd.print("Dispensing"); 257 lcd.setCursor(3, 1); 258 lcd.print("Your Item"); 259 myStepper3.step(-stepsPerRevolution);//run motor 260 lcd.clear(); 261 lcd.setCursor(2, 0); 262 lcd.print("Please take"); 263 lcd.setCursor(3, 1); 264 lcd.print("Your Item"); 265 delay(2500); 266 digitalWrite(ENABLE, LOW); //disengage relay 267// digitalWrite(PinB, LOW); 268 for (b = 0; b < 256; b++); 269 analogWrite(BLUEPIN, b); 270 credits = credits - 1; 271 cents = cents - cents; 272 } 273 } 274} 275 276// Coin Increase loop 277void coinInterrupt() { 278 279 // Each time a pulse is sent from the coin acceptor, interrupt main loop to add 5 cent and flip on the LED 280 cents = cents + 5; 281 digitalWrite(ledpin, HIGH); 282}
Vending Machine - WITHOUT CHANGING LED LIGHTS
arduino
Everything you need to complete and understand the project
1// Display 2#include <LiquidCrystal.h> 3LiquidCrystal lcd(2, 3, 4, 4 5, 6, 7); 5 6//Stepper Library 7#include <Stepper.h> //including stepper motor 8 library 9 10//Relay Setup 11#define ENABLE 10 12#define DIRA 8 13#define DIRB 14 9 15 16//Define "i" 17int i; 18 19//defining pins section 20//Stepper Connect 21 1 22int stepIN1Pin = 22; 23int stepIN2Pin = 24; 24int stepIN3Pin = 26; 25int 26 stepIN4Pin = 28; 27 28//Stepper Connect 2 29int stepIN1Pin1 = 23; 30int stepIN2Pin1 31 = 25; 32int stepIN3Pin1 = 27; 33int stepIN4Pin1 = 29; 34 35//Stepper Connect 36 3 37int stepIN1Pin2 = 30; 38int stepIN2Pin2 = 32; 39int stepIN3Pin2 = 34; 40int 41 stepIN4Pin2 = 36; 42 43//Stepper Connect 4 44int stepIN1Pin3 = 31; 45int stepIN2Pin3 46 = 33; 47int stepIN3Pin3 = 35; 48int stepIN4Pin3 = 37; 49 50//define steps 51int 52 stepsPerRevolution = 2048; // amount of steps per revolution 53 54//define buttons 55 pin ports 56const int button1Pin = A0; // Push Button 1 Analog Pin A0 57const 58 int button2Pin = A1; // Push Button 2 Analog Pin A1 59const int button3Pin = A2; 60 // Push Button 3 Analog Pin A2 61const int button4Pin = A3; // Push Button 4 62 Analog Pin A3 63 64//define each stepper 65// 1 66Stepper myStepper0(stepsPerRevolution, 67 stepIN1Pin, stepIN3Pin, stepIN2Pin, stepIN4Pin); 68//2 69Stepper myStepper1(stepsPerRevolution, 70 stepIN1Pin1, stepIN3Pin1, stepIN2Pin1, stepIN4Pin1); 71//3 72Stepper myStepper2(stepsPerRevolution, 73 stepIN1Pin2, stepIN3Pin2, stepIN2Pin2, stepIN4Pin2); 74//4 75Stepper myStepper3(stepsPerRevolution, 76 stepIN1Pin3, stepIN3Pin3, stepIN2Pin3, stepIN4Pin3); 77 78void setup() { 79 // 80 Assign Push Button Pin input: 81 pinMode(button1Pin, INPUT); 82 pinMode(button2Pin, 83 INPUT); 84 pinMode(button3Pin, INPUT); 85 pinMode(button4Pin, INPUT); 86 // 87 Assign pin output 88 pinMode(ENABLE, OUTPUT); 89 pinMode(DIRA, OUTPUT); 90 91 pinMode(DIRB,OUTPUT); 92 93 // Assign Stepper Speed 94 myStepper0.setSpeed(15); 95 96 myStepper1.setSpeed(15); 97 myStepper2.setSpeed(15); 98 myStepper3.setSpeed(15); 99 100 101 //Initialize LCD Display 102 lcd.begin(16, 2); 103 lcd.clear(); 104 lcd.setCursor(0, 105 0); 106 lcd.print("Select your item"); 107 lcd.setCursor(0, 1); 108 lcd.print(" 109 #1 #2 #3 #4"); 110} 111void loop() { 112 // read button assignment 113 int button1State, 114 button2State, button3State, button4State; 115 button1State = digitalRead(button1Pin); 116 117 button2State = digitalRead(button2Pin); 118 button3State = digitalRead(button3Pin); 119 120 button4State = digitalRead(button4Pin); 121 digitalWrite(ENABLE, HIGH);// Set 122 state 123 for (i=0;i<5;i++); 124 125 // define action when button 1 is pressed 126 127 if (((button1State == LOW) && !(button2State == LOW)))// if we're pushing button 128 1 OR button 2 129 {digitalWrite(DIRA,HIGH); //engage relay 130 digitalWrite(DIRB,LOW); 131 132 lcd.clear(); 133 lcd.setCursor(2, 0); 134 lcd.print("Dispensing"); 135 136 lcd.setCursor(3, 1); 137 lcd.print("Your Item"); 138 myStepper0.step(stepsPerRevolution); 139 //run motor 140 lcd.clear(); 141 lcd.setCursor(2, 0); 142 lcd.print("Please 143 take"); 144 lcd.setCursor(3, 1); 145 lcd.print("Your Item"); 146 delay(2500); 147 148 lcd.setCursor(0, 0); 149 lcd.print("Button State 1"); 150 lcd.setCursor(2, 151 1); 152 lcd.print("1 2 3 or 4"); 153 digitalWrite(DIRA,LOW); //disengage 154 relay 155 digitalWrite(DIRB,LOW); 156 } 157 // define action when button 2 158 is pressed 159 if (((button2State == LOW) && !(button1State == LOW))) // if we're 160 pushing button 1 OR button 2 161 {digitalWrite(DIRA,HIGH); //engage relay 162 digitalWrite(DIRB,LOW); 163 164 lcd.clear(); 165 lcd.setCursor(2, 0); 166 lcd.print("Dispensing"); 167 168 lcd.setCursor(3, 1); 169 lcd.print("Your Item"); 170 myStepper1.step(stepsPerRevolution);//run 171 motor 172 lcd.clear(); 173 lcd.setCursor(2, 0); 174 lcd.print("Please take"); 175 176 lcd.setCursor(3, 1); 177 lcd.print("Your Item"); 178 delay(2500); 179 180 lcd.setCursor(0, 0); 181 lcd.print("Button State 2"); 182 lcd.setCursor(2, 183 1); 184 lcd.print("1 2 3 or 4"); 185 digitalWrite(DIRA,LOW); //disengage 186 relay 187 digitalWrite(DIRB,LOW); 188 } 189 // define action when button 3 is 190 pressed 191 if (((button3State == LOW) && !(button4State == LOW))) // if we're 192 pushing button 1 OR button 2 193 {digitalWrite(DIRA,HIGH); //engage relay 194 digitalWrite(DIRB,LOW); 195 196 lcd.clear(); 197 lcd.setCursor(2, 0); 198 lcd.print("Dispensing"); 199 200 lcd.setCursor(3, 1); 201 lcd.print("Your Item"); 202 myStepper2.step(stepsPerRevolution);//run 203 motor 204 lcd.clear(); 205 lcd.setCursor(2, 0); 206 lcd.print("Please 207 take"); 208 lcd.setCursor(3, 1); 209 lcd.print("Your Item"); 210 delay(2500); 211 212 lcd.setCursor(0, 0); 213 lcd.print("Button State 3"); 214 lcd.setCursor(2, 215 1); 216 lcd.print("1 2 3 or 4"); 217 digitalWrite(DIRA,LOW); //disengage 218 relay 219 digitalWrite(DIRB,LOW); 220 } 221 // define action when button 4 is 222 pressed 223 if (((button4State == LOW) && !(button3State == LOW))) // if we're 224 pushing button 1 OR button 2 225 {digitalWrite(DIRA,HIGH); //engage relay 226 digitalWrite(DIRB,LOW); 227 228 lcd.clear(); 229 lcd.setCursor(2, 0); 230 lcd.print("Dispensing"); 231 232 lcd.setCursor(3, 1); 233 lcd.print("Your Item"); 234 myStepper3.step(-stepsPerRevolution);//run 235 motor 236 lcd.clear(); 237 lcd.setCursor(2, 0); 238 lcd.print("Please take"); 239 240 lcd.setCursor(3, 1); 241 lcd.print("Your Item"); 242 delay(2500); 243 244 lcd.setCursor(0, 0); 245 lcd.print("Button State 4"); 246 lcd.setCursor(2, 247 1); 248 lcd.print("1 2 3 or 4"); 249 digitalWrite(DIRA,LOW); //disengage 250 relay 251 digitalWrite(DIRB,LOW); 252 } 253} 254
Vending Machine - WITH CHANGING LED LIGHTS
csharp
Take a look at the video!
1// Display 2#include <LiquidCrystal.h> 3LiquidCrystal lcd(2, 3, 4, 4 5, 6, 7); 5 6//Stepper Library 7#include <Stepper.h> //including stepper motor 8 library 9 10//Relay Setup 11#define ENABLE 10 12#define PinA 8 13#define PinB 14 9 15#define REDPIN 38 16#define GREENPIN 39 17#define BLUEPIN 40 18 19//Define 20 "i" 21int i; 22 23//Define "RGB" 24int r, g, b; 25 26//defining pins section 27//Stepper 28 Connect 1 29int stepIN1Pin = 22; 30int stepIN2Pin = 24; 31int stepIN3Pin = 26; 32int 33 stepIN4Pin = 28; 34 35//Stepper Connect 2 36int stepIN1Pin1 = 23; 37int stepIN2Pin1 38 = 25; 39int stepIN3Pin1 = 27; 40int stepIN4Pin1 = 29; 41 42//Stepper Connect 43 3 44int stepIN1Pin2 = 30; 45int stepIN2Pin2 = 32; 46int stepIN3Pin2 = 34; 47int 48 stepIN4Pin2 = 36; 49 50//Stepper Connect 4 51int stepIN1Pin3 = 31; 52int stepIN2Pin3 53 = 33; 54int stepIN3Pin3 = 35; 55int stepIN4Pin3 = 37; 56 57//define steps 58int 59 stepsPerRevolution = 2048; // amount of steps per revolution 60 61//define buttons 62 pin ports 63const int button1Pin = A0; // Push Button 1 Analog Pin A0 64const 65 int button2Pin = A1; // Push Button 2 Analog Pin A1 66const int button3Pin = A2; 67 // Push Button 3 Analog Pin A2 68const int button4Pin = A3; // Push Button 4 69 Analog Pin A3 70 71//define each stepper 72// 1 73Stepper myStepper0(stepsPerRevolution, 74 stepIN1Pin, stepIN3Pin, stepIN2Pin, stepIN4Pin); 75//2 76Stepper myStepper1(stepsPerRevolution, 77 stepIN1Pin1, stepIN3Pin1, stepIN2Pin1, stepIN4Pin1); 78//3 79Stepper myStepper2(stepsPerRevolution, 80 stepIN1Pin2, stepIN3Pin2, stepIN2Pin2, stepIN4Pin2); 81//4 82Stepper myStepper3(stepsPerRevolution, 83 stepIN1Pin3, stepIN3Pin3, stepIN2Pin3, stepIN4Pin3); 84 85void setup() { 86 // 87 Assign Push Button Pin input: 88 pinMode(button1Pin, INPUT); 89 pinMode(button2Pin, 90 INPUT); 91 pinMode(button3Pin, INPUT); 92 pinMode(button4Pin, INPUT); 93 94 95 // Assign pin output 96 pinMode(ENABLE, OUTPUT); 97 pinMode(PinA, OUTPUT); 98 99 pinMode(PinB, OUTPUT); 100 101 //LED Strips pin setup 102 pinMode(REDPIN, OUTPUT); 103 104 pinMode(GREENPIN, OUTPUT); 105 pinMode(BLUEPIN, OUTPUT); 106 107 // Assign Stepper 108 Speed 109 myStepper0.setSpeed(15); 110 myStepper1.setSpeed(15); 111 myStepper2.setSpeed(15); 112 113 myStepper3.setSpeed(15); 114 115 //Initialize LCD Display 116 lcd.begin(16, 117 2); 118 lcd.clear(); 119 lcd.setCursor(0, 0); 120 lcd.print("Select your item"); 121 122 lcd.setCursor(0, 1); 123 lcd.print(" #1 #2 #3 #4"); 124 analogWrite(REDPIN, 125 256); 126 analogWrite(GREENPIN, 256); 127 analogWrite(BLUEPIN, 256); 128} 129void 130 loop() { 131 // read button assignment 132 int button1State, button2State, button3State, 133 button4State; 134 button1State = digitalRead(button1Pin); 135 button2State = digitalRead(button2Pin); 136 137 button3State = digitalRead(button3Pin); 138 button4State = digitalRead(button4Pin); 139 140 digitalWrite(ENABLE, HIGH);// Set state 141 for (i = 0; i < 5; i++); 142 143 144 // define action when button 1 is pressed 145 if (((button1State == LOW) && !(button2State 146 == LOW)))// if we're pushing button 1 OR button 2 147 { digitalWrite(PinA, HIGH); 148 //engage relay 149 digitalWrite(PinB, LOW); 150 analogWrite(REDPIN, 256); 151 152 for (b = 256; b > 0; b--); 153 analogWrite(BLUEPIN, b); 154 for (g = 256; 155 g > 0; g--); 156 analogWrite(GREENPIN, g); 157 for (g = 256; g > 0; g--); 158 159 lcd.clear(); 160 lcd.setCursor(2, 0); 161 lcd.print("Dispensing"); 162 163 lcd.setCursor(3, 1); 164 lcd.print("Your Item"); 165 myStepper0.step(stepsPerRevolution); 166 //run motor 167 lcd.clear(); 168 lcd.setCursor(2, 0); 169 lcd.print("Please 170 take"); 171 lcd.setCursor(3, 1); 172 lcd.print("Your Item"); 173 delay(2500); 174 175 lcd.setCursor(0, 0); 176 lcd.print("Button State 1"); 177 lcd.setCursor(2, 178 1); 179 lcd.print("1 2 3 or 4"); 180 for (b = 0; b < 256; b++); 181 analogWrite(BLUEPIN, 182 b); 183 for (g = 0; g < 256; g++); 184 analogWrite(GREENPIN, g); 185 digitalWrite(PinA, 186 LOW); //disengage relay 187 digitalWrite(PinB, LOW); 188 } 189 // define action 190 when button 2 is pressed 191 if (((button2State == LOW) && !(button1State == LOW))) 192 // if we're pushing button 1 OR button 2 193 { digitalWrite(PinA, HIGH); //engage 194 relay 195 digitalWrite(PinB, LOW); 196 analogWrite(GREENPIN, 256); 197 for 198 (b = 256; b > 0; b--); 199 analogWrite(BLUEPIN, b); 200 for (r = 256; r > 201 0; r--); 202 analogWrite(REDPIN, r); 203 lcd.clear(); 204 lcd.setCursor(2, 205 0); 206 lcd.print("Dispensing"); 207 lcd.setCursor(3, 1); 208 lcd.print("Your 209 Item"); 210 myStepper1.step(stepsPerRevolution);//run motor 211 lcd.clear(); 212 213 lcd.setCursor(2, 0); 214 lcd.print("Please take"); 215 lcd.setCursor(3, 216 1); 217 lcd.print("Your Item"); 218 delay(2500); 219 lcd.setCursor(0, 220 0); 221 lcd.print("Button State 2"); 222 lcd.setCursor(2, 1); 223 lcd.print("1 224 2 3 or 4"); 225 digitalWrite(PinA, LOW); //disengage relay 226 digitalWrite(PinB, 227 LOW); 228 for (b = 0; b < 256; b++); 229 analogWrite(BLUEPIN, b); 230 for 231 (r = 0; r < 256; r++); 232 analogWrite(REDPIN, r); 233 } 234 // define action 235 when button 3 is pressed 236 if (((button3State == LOW) && !(button4State == LOW))) 237 // if we're pushing button 1 OR button 2 238 { digitalWrite(PinA, HIGH); //engage 239 relay 240 digitalWrite(PinB, LOW); 241 analogWrite(BLUEPIN, 256); 242 for 243 (r = 256; r > 0; r--); 244 analogWrite(REDPIN, r); 245 for (g = 256; g > 0; 246 g--); 247 analogWrite(GREENPIN, g); 248 lcd.clear(); 249 lcd.setCursor(2, 250 0); 251 lcd.print("Dispensing"); 252 lcd.setCursor(3, 1); 253 lcd.print("Your 254 Item"); 255 myStepper2.step(stepsPerRevolution);//run motor 256 lcd.clear(); 257 258 lcd.setCursor(2, 0); 259 lcd.print("Please take"); 260 lcd.setCursor(3, 261 1); 262 lcd.print("Your Item"); 263 delay(2500); 264 lcd.setCursor(0, 265 0); 266 lcd.print("Button State 3"); 267 lcd.setCursor(2, 1); 268 lcd.print("1 269 2 3 or 4"); 270 digitalWrite(PinA, LOW); //disengage relay 271 digitalWrite(PinB, 272 LOW); 273 for (g = 0; g < 256; g++); 274 analogWrite(GREENPIN, g); 275 for 276 (r = 0; r < 256; r++); 277 analogWrite(REDPIN, r); 278 } 279 // define action 280 when button 4 is pressed 281 if (((button4State == LOW) && !(button3State == LOW))) 282 // if we're pushing button 1 OR button 2 283 { digitalWrite(PinA, HIGH); //engage 284 relay 285 digitalWrite(PinB, LOW); 286 analogWrite(REDPIN, 256); 287 analogWrite(GREENPIN, 288 256); 289 for (b = 256; b > 0; b--); 290 analogWrite(BLUEPIN, b); 291 lcd.clear(); 292 293 lcd.setCursor(2, 0); 294 lcd.print("Dispensing"); 295 lcd.setCursor(3, 296 1); 297 lcd.print("Your Item"); 298 myStepper3.step(-stepsPerRevolution);//run 299 motor 300 lcd.clear(); 301 lcd.setCursor(2, 0); 302 lcd.print("Please 303 take"); 304 lcd.setCursor(3, 1); 305 lcd.print("Your Item"); 306 delay(2500); 307 308 lcd.setCursor(0, 0); 309 lcd.print("Button State 4"); 310 lcd.setCursor(2, 311 1); 312 lcd.print("1 2 3 or 4"); 313 digitalWrite(PinA, LOW); //disengage 314 relay 315 digitalWrite(PinB, LOW); 316 for (b = 0; b < 256; b++); 317 analogWrite(BLUEPIN, 318 b); 319 } 320}
Downloadable files
Wire Diagram
This is a complete Diagram of the system. It includes, ATX power supply, motors,LCD,LEDs, lights and controller
Wire Diagram
Wire Diagram
This is a complete Diagram of the system. It includes, ATX power supply, motors,LCD,LEDs, lights and controller
Wire Diagram
Comments
Only logged in users can leave comments