Devices & Components
Arduino Uno Rev3
Tactile Switch, Top Actuated
MW 122A Power Supply
Breadboard (generic)
Jumper wires (generic)
Resistor 10k ohm
Coin Acceptor
LED (generic)
Hardware & Tools
Arduino USB Cable
Software & Tools
Arduino IDE
Project description
Code
Code for Project
arduino
1boolean buttonPressed = false; 2int count = 0; 3int totalCount = 0; 4int cents = 0; 5 6void setup() { 7 Serial.begin(19200); 8 attachInterrupt(digitalPinToInterrupt(2), buttonCB, FALLING); 9 attachInterrupt(digitalPinToInterrupt(3), coinAcceptorCB, FALLING); 10 pinMode(4, OUTPUT); 11} 12 13 14void buttonCB() { 15 Serial.println("Button pressed"); 16 buttonPressed = true; 17} 18 19void coinAcceptorCB() { 20 count = count + 1; 21 cents = 10 * count; 22 Serial.print("Count = "); 23 Serial.println(count); 24 Serial.print(cents); 25 Serial.println(" cents received. "); 26 27} 28 29void loop() { 30 if (buttonPressed) { 31 if (5 <= totalCount && totalCount < 10) { 32// DISPENSE WATER 33 digitalWrite(4, HIGH); 34 delay(5000); 35 digitalWrite(4, LOW); 36 buttonPressed = false; 37// SHOW RECEIPT 38 Serial.print("Total count: "); 39 Serial.println(totalCount); 40 totalCount = 0; 41 } else { 42 Serial.println("Insufficient. Minimum is 50 Cents."); 43 buttonPressed = false; 44 } 45 } 46 47 delay(1000); 48 totalCount = totalCount + count; 49 count = 0; 50}
Downloadable files
Arduino Schematic Diagram
Arduino Schematic Diagram

Arduino Schematic Diagram
Arduino Schematic Diagram

Comments
Only logged in users can leave comments