atticusyong37
Published © GPL3+

Making Arduino + Coin Sensor Project for Vending Machine

This project will demonstrate the effect of using e water vending machine, but instead of water it will light up an LED.

IntermediateFull instructions provided3,697
Making Arduino + Coin Sensor Project for Vending Machine

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Coin Acceptor
×1
Jumper wires (generic)
Jumper wires (generic)
×12
Tactile Switch, Top Actuated
Tactile Switch, Top Actuated
×1
Breadboard (generic)
Breadboard (generic)
×1
MW 122A Power Supply
×1
LED (generic)
LED (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×3

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Arduino USB Cable

Story

Read more

Schematics

Arduino Schematic Diagram

Code

Code for Project

Arduino
boolean buttonPressed = false;
int count = 0;
int totalCount = 0;
int cents = 0;

void setup() {
  Serial.begin(19200);
  attachInterrupt(digitalPinToInterrupt(2), buttonCB, FALLING);
  attachInterrupt(digitalPinToInterrupt(3), coinAcceptorCB, FALLING);
  pinMode(4, OUTPUT);
}


void buttonCB() {
  Serial.println("Button pressed");
  buttonPressed = true;
}

void coinAcceptorCB() {
  count = count + 1;
  cents = 10 * count;
  Serial.print("Count = ");
  Serial.println(count);
  Serial.print(cents);
  Serial.println(" cents received. ");

}

void loop() {
  if (buttonPressed) {
    if (5 <= totalCount && totalCount < 10) {
//      DISPENSE WATER
      digitalWrite(4, HIGH);
      delay(5000);
      digitalWrite(4, LOW);
      buttonPressed = false;  
//      SHOW RECEIPT
      Serial.print("Total count: ");
      Serial.println(totalCount);
      totalCount = 0;
    } else {
      Serial.println("Insufficient. Minimum is 50 Cents.");
      buttonPressed = false;
    }
  }

  delay(1000);
  totalCount = totalCount + count;
  count = 0;
}

Credits

atticusyong37

atticusyong37

1 project • 3 followers

Comments