Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
ardutronic
Published © CC BY-NC-SA

DIY Vending Machine

A significant part of smokers buy cigarettes for pieces - this is how the idea of making a cigarette machine was born.

IntermediateFull instructions provided12 hours4,449
DIY Vending Machine

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Graphic OLED, 128 x 32
Graphic OLED, 128 x 32
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Hot Air Station, Industrial
Hot Air Station, Industrial

Story

Read more

Custom parts and enclosures

part1

part2

part3

Schematics

Schematic

Board

Code

Code

Arduino
#include <Servo.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);

Servo myservo;

int pos = 0;
int x;

void setup() {
  myservo.attach(11);
  myservo.write(0);
    if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }

  Wire.begin(8);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);
  display.clearDisplay();
}

void loop() {
  display.setTextSize(1); // Draw 2X-scale text
  display.setTextColor(SSD1306_WHITE);
  display.setRotation(1);
  // display.setCursor(30, 16); //HALF
    display.setTextSize(1);
    display.setCursor(5, 0);
    display.println(F("PUSH"));
    display.setCursor(13, 30);
    display.println(F("A"));
    display.setCursor(05, 60);
    display.println(F("COIN"));
    display.display();
    
  if(x == 100)
  {
    display.clearDisplay();
    display.display();
    display.setTextSize(2);
    display.setCursor(10, 10);
    display.println(F("1   P L N"));
    display.display();
    delay(3000);
  myservo.write(60);
  delay(300);
  myservo.write(0);
  delay(1000);
  x = 0;
   display.clearDisplay();
    display.display();
  }
}

void receiveEvent(int howMany) {
  while (1 < Wire.available()) { // loop through all but the last
    char c = Wire.read(); // receive byte as a character
    Serial.print(c);         // print the character
  }
  x = Wire.read();    // receive byte as an integer
  Serial.println(x);         // print the integer
}

Code 2

Arduino
for Coin Sorter
byte zeroOne;
byte zeroTwo;
byte zeroFive;
byte one;
byte two;
byte five;
byte myTime = 500;
#include <Wire.h>
int x = 100;

void setup() {
  pinMode(6, INPUT);
  pinMode(7, INPUT);
  pinMode(8, INPUT);
  pinMode(9, INPUT);
  pinMode(10, INPUT);
  pinMode(11, INPUT);
  Wire.begin();
  Serial.begin(9600);
}

void loop() {
  zeroOne = digitalRead(5);
  zeroTwo = digitalRead(6);
  zeroFive = digitalRead(7);
  one = digitalRead(9);
  two = digitalRead(8);
  five = digitalRead(10);
  showCoin();
  delay(5);
}

void showCoin()
{
  if (zeroOne == 0)
  {
    Serial.println("0.1");
    delay(myTime);
  }

  if (zeroTwo == 0)
  {
    Serial.println("0.2");
    delay(myTime);
  }

  if (zeroFive == 0)
  {
    Serial.println("0.5");
    delay(myTime);
  }

  if (one == 0)
  {
    Serial.println("1");
    delay(myTime);
    Wire.beginTransmission(8);
    Wire.write(x);             
    Wire.endTransmission();
  }

  if (two == 0)
  {
    Serial.println("2");
    delay(myTime);
  }

  if (five == 0)
  {
    Serial.println("5");
    delay(myTime);
  }
}

void reading()  {
  Serial.print("6: ");
  Serial.println(digitalRead(6));
  Serial.print("7: ");
  Serial.println(digitalRead(7));
  Serial.print("8: ");
  Serial.println(digitalRead(8));
  Serial.print("9: ");
  Serial.println(digitalRead(9));
  Serial.print("10: ");
  Serial.println(digitalRead(10));
  Serial.print("5: ");
  Serial.println(digitalRead(5));
  delay(1000);
}

Credits

ardutronic
39 projects • 41 followers
I'm 20 years old student of electronic technical college. I'm passionate about electronics as well as editing movies
Contact

Comments

Please log in or sign up to comment.