├── README.md ├── LICENSE └── coin-acceptor.ino /README.md: -------------------------------------------------------------------------------- 1 | # arduino-coin-acceptor 2 | 3 | Source code for adding a programmable coin acceptor to an Arduino project. Originally created for "Adding a Coin Acceptor to Your Arduino Project" on the Maker Show. Watch the video tutorial [here](https://channel9.msdn.com/Shows/themakershow/10/). 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Rachel Simone Weil 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /coin-acceptor.ino: -------------------------------------------------------------------------------- 1 | // Arduino coin acceptor code by hxlnt 2 | // Originally created for "Adding a Coin Acceptor to Your Arduino Project" on the Maker Show 3 | // See the entire video tutorial at https://channel9.msdn.com/Shows/themakershow/10 4 | // 5 | // Read your coin acceptor's specs and instructions first for hookup specifics 6 | // Modifications to this code may be needed 7 | // Coin acceptor model used in this example is JY-923 8 | // 9 | // xoxox 10 | 11 | 12 | 13 | // Constants 14 | const int coinpin = 2; 15 | const int ledpin = 3; 16 | const int targetcents = 100; 17 | 18 | // Variables 19 | volatile int cents = 0; 20 | int credits = 0; 21 | 22 | // Setup 23 | void setup() { 24 | 25 | Serial.begin(9600); 26 | attachInterrupt(digitalPinToInterrupt(coinpin), coinInterrupt, RISING); 27 | pinMode(ledpin, OUTPUT); 28 | 29 | } 30 | 31 | // Main loop 32 | void loop() { 33 | 34 | // If we've hit our target amount of coins, increment our credits and reset the cents counter 35 | if (cents >= targetcents) { 36 | credits = credits + 1; 37 | cents = cents - targetcents; 38 | } 39 | 40 | // If we haven't reached our target, keep waiting... 41 | else { 42 | } 43 | 44 | // Debugging zone 45 | Serial.print(cents); 46 | Serial.print(" cents toward current credit and "); 47 | Serial.print(credits); 48 | Serial.println(" credit(s) earned so far."); 49 | delay(1000); 50 | 51 | // Turn off LED 52 | digitalWrite(ledpin, LOW); 53 | 54 | // Now, write your own cool code here that triggers an event when the player has credits! 55 | if (credits > 0) { 56 | // Play music? 57 | // Spin up a motor? 58 | // Start a game? 59 | // It's up to you! 60 | } 61 | 62 | } 63 | 64 | // Interrupt 65 | void coinInterrupt(){ 66 | 67 | // Each time a pulse is sent from the coin acceptor, interrupt main loop to add 1 cent and flip on the LED 68 | cents = cents + 1; 69 | digitalWrite(ledpin, HIGH); 70 | 71 | } 72 | 73 | --------------------------------------------------------------------------------