Coin Acceptor or Coin Sensor Tutorial with Arduino
7491
0Kamu harus login untuk menyukai postingan ini
In this tutorial we will use the cheap Chinese Coin Acceptor GD-100F.
The wiring diagram is like this :
This Coin Acceptor works by compare the coin that already inserted in this sensor (blue color at sensor) with the coin that inserted at the front hole. If the coin is the same, the coin will accepted, but if coin is different, the coin will be rejected.
We will make a sketch that will print Coin Detected when a match coin is inserted.
const int coin = 2; boolean insert = false; volatile int pulse = 0; void setup() { // put your setup code here, to run once: Serial.begin(9600); attachInterrupt(digitalPinToInterrupt(2), coinInterrupt, RISING); delay(1000); } void loop() { // put your main code here, to run repeatedly: if (insert) { insert = false; Serial.println("coin detected!"); delay(1000); } } //interrupt void coinInterrupt() { pulse++ ; insert = true; }
And then we want to make a program that will add balance by 1000 every a match coin is inserted.
const int coin = 2; boolean insert = false; volatile int pulse = 0; unsigned long balance; void setup() { // put your setup code here, to run once: Serial.begin(9600); attachInterrupt(digitalPinToInterrupt(2), coinInterrupt, RISING); delay(1000); } void loop() { // put your main code here, to run repeatedly: if (insert) { insert = false; //Serial.println("coin detected!"); balance+=1000; Serial.println("Balance : "+(String)balance); delay(1000); } } //interrupt void coinInterrupt() { pulse++ ; insert = true; }
And here’s the complete tutorial on video.
arduino
coin acceptor
money
sensor
tutorial