vending machines

Vending Machines


Im Just getting started but it looks good sofar.

https://github.com/netpipe/coin_acceptor – old code should update it soon

https://github.com/netpipe/OSMMAC

https://www.thingiverse.com/thing:3050863

 

dc step up transformer works well for converting 5v to 12v for the coin acceptor

  • Its nice to convert these things to 5v power with a wallwart so they are CSA approved and non fire hazard. I used underground networking cable (cat45E) which can supply 3 paired 2 amp lines,only needed one though.
  • the motors spin easily on 5v and have enough oomph to not get stuck.
  • be sure to have a vending licence unless your selling non food items and on your own property / lawn or shop otherwise you will need a direct seller licence to cover any liability’s.
  • old vending machines without coin mechs or outdated ones can go for under 300 dollars, its nice to have the option to put electronic parts inside or jewlery / makeup i’ve even seen them selling steaks in them. also if you get one with a working coin mech they can be resold for part of the cost of buying the vending machine after replacing the insides.

 

 

ment to run on arduino due. , the nano 328 ran out of space or something. i’ve seen a more reliable version where they solder to the led’s on the coin acceptor instead of relying on code which can double the pulses or misfire without the ir sensor.

 

#include <Adafruit_SSD1306-swire.h>
#include <Adafruit_GFX.h>
// OLED display TWI address
#define OLED_ADDR 0x3C
Adafruit_SSD1306 display(-1);

#if (SSD1306_LCDHEIGHT != 64)
#error(“Height incorrect, please fix Adafruit_SSD1306.h!”);
#endif

#include “SWire.h”
#include “I2CKeyPad-swire.h”

const uint8_t KEYPAD_ADDRESS = 0x38; //38

I2CKeyPad keyPad(KEYPAD_ADDRESS);

uint32_t start, stop;
uint32_t lastKeyPressed = 0;

char keys[] = “123A456B789C*0#DNF”; // N = Nokey, F = Fail

//#define IRSENSOR //TCRT5000 IR SENSOR module from ebay hotglued to bottom of unit on left side and connected to D0

//20 , 40,70 ms with 100 ms between
//#define SLOW 70
//#define MEDIUM 40
#define FAST 20

const int IRPIN = 3;
const int COINPIN = 8;

#ifdef MEDIUM
const int threshold1 = 350; // higher value for larger sample window
const int sampleWindow = 40; // Sample window width in mS (50 mS = 20Hz)
#endif

#ifdef FAST
const int threshold1 = 100; // higher value for larger sample window
const int sampleWindow = 15; // Sample window width in mS (50 mS = 20Hz)
#endif

int oldpulses=0;
int counter=0;
int sample;
int samplebuffer = 0;
int count=0; //idle loop counter
float money = 0.0;
int pulses = 0;
uint32_t timeLastPulse = 0;
//string pulsestring;
uint32_t startMillis;
uint32_t elapsedmilis=0;
uint32_t halfmilis=0;
uint32_t timeFromLastPulse;
int bpulse=0;
int oldcounter=0;

 

void setup()
{

Serial.begin(9600);
// Serial.println(__FILE__);
pinMode(COINPIN,INPUT_PULLUP);

display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR,1,A4,A5);
display.clearDisplay();
display.display();

// display a line of text
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(27,30);
display.print(“Hello, world!”);

// update display with all of the above graphics
display.display();

 

// delay(1500);
// SWire.begin(A4,A5);
// SWire.setClock(400000);
if (keyPad.begin(A4,A5) == false)
{
Serial.println(“\nERROR: cannot communicate to keypad.\nPlease reboot.\n”);
// while(1);
}

}

void Keypad(){
if (startMillis – lastKeyPressed >= 100)
{
lastKeyPressed = startMillis;

start = micros();
uint8_t idx = keyPad.getKey();
stop = micros();

Serial.print(millis());
Serial.print(“\t”);
Serial.print(idx);
Serial.print(“\t”);
Serial.print(keys[idx]);
Serial.print(“\t”);
Serial.println(stop – start);
}
}

void LCDupdate(){
delay(400);
display.clearDisplay();
// display a line of text
display.setTextSize(5);
display.setTextColor(WHITE);
display.setCursor(27,30);
// String test2 = String(count) ;
display.print( String(startMillis) );

// update display with all of the above graphics
display.display();
}

void loop()
{
startMillis= millis(); // Start of sample window
//halfmilis=startMillis/2-40;

while (elapsedmilis < sampleWindow)
{

// #ifdef IRSENSOR
// if (bpulse < 3 && digitalRead(IRPIN) < 1 ){
// bpulse++;
// // delay(5);
// }
// #endif

if (digitalRead(COINPIN) < 1)
{
// Serial.println(samplebuffer);
samplebuffer++;
}

elapsedmilis = millis() – startMillis;
}

//check thresholds
if (samplebuffer >= threshold1)
{
Serial.println(samplebuffer);
pulses++;
// pulsestring+=1;
timeLastPulse = millis();
count=0;
delay (100);
}

samplebuffer = 0;
elapsedmilis=0;
count++;

// #ifdef IRSENSOR
// if (bpulse >= 3){
// // Serial.println(“IRPULSE2”);
// Serial.println(counter);
// counter++;
// bpulse=0;
// count=0;
// delay(16);
// }
// #endif

timeFromLastPulse = millis() – timeLastPulse;

if (pulses > 0 && timeFromLastPulse > 150) //set higher to be more accurate or if you are getting single and double pulse
{
switch(pulses){
// single and double pulse available aswell but sometimes are triggered accidently when putting coins in fast
// might be ok to use with larger 100ms sample window now.
case 3: {
Serial.println(“Received quarter (3 pulses)”);
Serial.println(counter);
money += .25;
break;
}
case 6: {
Serial.println(“Received 50 cents (6 pulses)”);
Serial.println(counter);
money += .50;
break;
}
case 9: {
Serial.println(“Received 75 cents (9 pulses)”);
Serial.println(counter);
money += .75;
break;
}
case 4: { //10 pulses
Serial.println(“Received looney (4 pulses)”);
Serial.println(counter);
money += 1.0;
break;
}
case 8: {
Serial.println(“Received toonie (8 pulses)”);
Serial.println(counter);
money += 2.0;
break;
}
case 7: {
Serial.println(“Received 1.25 (7 pulses)”);
money += 1.25;
break;
}
case 10: {
Serial.println(“Received 1.50 (10 pulses)”);
money += 1.50;
break;
}
case 11: {
Serial.println(“Received 2.25 (11 pulses)”);
money += 2.25;
break;
}
case 12: {
Serial.println(“doozy”);
Serial.println(counter);
if (counter < 4){
Serial.println(“Received 3.00 (12 pulses)”);
money += 3.00;
}
if (counter == 4){
Serial.println(“Received 3 quarters (12 pulses)”);
money += 1.00;
}
break;
}
case 15: { // on nano i could only compile this many in
Serial.println(“Received 5quarters (16 pulses)”);
money += 1.25;
break;
}
case 16: {
Serial.println(“Received 2tooney (16 pulses)”);
Serial.println(counter);
money += 4.0;
break;
}
case 20: {
Serial.println(“Received 2tooney (20 pulses)”);
money += 3.0;
break;
}
case 24: {
Serial.println(“Received 3tooney (24 pulses)”);
money += 6.0;
break;
}
default : {
Serial.print(“Unknown coin: “);
Serial.print(pulses);
Serial.println(” pulses”);
break;
}
} //end switch

counter=0;
pulses = 0;
timeFromLastPulse=0;
timeLastPulse=0;
oldpulses=0;
bpulse=0;
oldcounter=0;
count=0;
}else{
if (count > 50) {
// Serial.println(“r”);
oldcounter=0;
counter=0;
bpulse=0;
if (count > 600) {
Serial.println(“money”);
Serial.println(money);
// LCDupdate();
// Keypad();
count=0;
}
delay(4);
}
count++;
} //idle detector

LCDupdate();
Keypad();
}

// — END OF FILE —

 

savemco motor turners, put the old grounds into power then  ground all the motors and use the irf540n pin to trigger the motor on and off.

 

 

 

 

saega vending machine motors only need a jumper pin from the motor to the D side, leave power constant to the O side in marker there