SBHX Vending Machine

SBHX Vending Machine

The Hackerspace recently acquired a coin acceptor from Sparkfun. We brainstormed a bit and decided that a vending machine was the best use of such technology and work began. The coin acceptor is programmable and can be trained to accept up to three coins, and upon accepting a coin outputs a configurable pulse train. There is some sample code available but we had issues making it reliable and modifying it to work like a regular vending machine, so we cooked up our own available below. TheOtherMike came up with a neat little trick of using the serial port to count coin pulses much more reliably. Though we did find that building up a static charge and half inserting a coin would cause it to increment without actually inserting a coin, this was solved with a decoupling cap on the coin acceptor power rails. Once we got the basic code working we added an HD44780 type LCD to display prices and how much had been deposited.

We plan on adding a handful of new features such a numeric keypad to punch an item number, and debug commands to see how much is in the acceptor and to display inventory. In keeping with the Hackerspace tradition of making something slightly less useful we are also going to add an option to pay less but in return the machine does something annoying. Ideas so far have been attaching a siren, attaching a large off balance motor to shake the machine, and using a camera flash circuit to shock people in return for the discount. Updates will be posted as they develop.

Current Code:


//developed by TheOtherMike and Swiss
 //Licensed under the beerware license
 #define COIN1 2 //type of coin that generates 2 pulses
 #define COIN2 3 //type of coin that generates 3 pulses
 #define COIN3 1 //type of coin that generates 1 pulses
 #include
 #include

LiquidCrystal lcd(8, 9, 10, 11, 12, 13); //HD44780 type display assumed
 SoftwareSerial mySerial (15, 16); //software serial ports, connect COIn or COUNT wire from coin acceptor to RX

int total = 0; //variable for total value of coins
 int total1 = 0; //how many dollars should be in the acceptor
 int dispense1 = 100; //variable for an item worth $1, total must equal this for it to dispense
 int nickel = 5; //set coin names and value here
 int dime = 10; //set coin names and value here
 int quarter = 25; //set coin names and value here

void setup() {
 Serial.begin (9600); //for serial debugging
 mySerial.begin(9600); //software serial to count pulses from coin acceptor
 lcd.begin(16, 2); //this location will vary by lcd size
 lcd.print("Everything $1.00"); //welcome message
 }

void loop() {
 while(mySerial.available()){
 delay(350);
 char count = mySerial.available();
 while(mySerial.available()) mySerial.read();
 mySerial.flush();
 switch(count){
 case COIN1:
 Serial.println("Dime Inserted");
 total += dime;
 break;
 case COIN2:
 Serial.println("Nickel Inserted");
 total += nickel;
 break;
 case COIN3:
 Serial.println("Quarter Inserted");
 total += quarter;
 break;
 default:
 Serial.println("Error!");
 break;
 }
 if(total >= 100) {
 lcd.setCursor(0, 1);
 lcd.print(" ");
 lcd.setCursor(0,1);
 lcd.print("Enjoy!");
 digitalWrite(13, HIGH);
 delay(1000);
 digitalWrite(13, LOW);
 total = 0;
 total1++;
 }
 else{
 lcd.setCursor(0, 1);
 Serial.print((100 - total), DEC);
 Serial.println(" needed");
 lcd.print((100 - total), DEC);
 lcd.print(" needed");
 }
 }
 }

Santa Barbara Hackerspace
About The Author

There are no comments yet, but you can be the first



Comments are closed.

What is the Hackerspace?

We are a group of makers and developers in the Santa Barbara community who love building things. The Hackerspace has a Makerbot printer, piles of Arduinos, and much, much more. Learn More →
Become a Member

Membership Levels
Location

5782 Thornwood Dr
Goleta CA 93117

Contact Us

Current Status

Current status of the Hackerspace: "awesome".
Twitter Feed

Find out what's happening, right now, with the people and organizations you care about.


Bad Authentication data.
Copyright 2012 Builder - Company. Design by OrangeIdea