Pages: [1]   Go Down
Author Topic: Coin Acceptor + Arduino UNO R3 - programing issue  (Read 837 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello ,

Im new to such thing as electronics , im a photo booth builder

i got the coin acceptor " CH-923 " and i programed it to identify and accept one type of coin " no cash value " and send 1 pulse ..

though i have a major problem with the programing ..

how can i program the arduino to a accept the pulse from the coin acceptor and turn it into a mouse click ? , Just like that !

i'll be grateful , thanks for your help .
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50881
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
how can i program the arduino to a accept the pulse from the coin acceptor
That depends on how you have connected the coin acceptor to the Arduino.

Quote
and turn it into a mouse click ? , Just like that !
You need the Arduino Mouse board (also known as a Leonardo or Micro).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hey , i ordered the Leonardo once you told me to , and it has just arrived ..

what is next ..
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50881
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
what is next ..
You write some code.

And, before you ask, you test the code. Then, you debug the code.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 82
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey did you manage to write some code? Got stuck with this too..
I never used interrupts before and don't have much time to finish this now.. Any example code?

Thanks!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hy,

try the next code
Code:


    /*
      This sketch assumes that coin 1, will return 1 pulse, coin 2 will return 2 pulses, and so on.
     
     Coin values:
     1 = 0.5
     2 = 1
     3 = 2
     4 = 10
     */
     
    const byte coinValues[4] = {
      5, 10,50, 100}; //Coin values goes into this array
    #define pulseTimeout 200        //How many milliseconds there are from the last impulse to the coin is determined (default 275)
    #define actionTimeout 60000     //How many milliseconds before stored credit is reset (default 60000)
     
     
    unsigned long lastAction = 0;   //When last action was made
    unsigned long lastPulse = 0;    //When last pulse was send
    int pulseCount = 0;             //How many pulses we got
    int currentCredit;              //The current credit
     
    void showCredit()
    {
      int credit = currentCredit/10;
      int left = currentCredit % (currentCredit/10);
     
      Serial.print("Current credit: ");
      Serial.print(credit, DEC);
      Serial.print(".");
      Serial.print(left, DEC);
      Serial.println("0");
    }
     
    void setup()
    {
      Serial.begin(115200);
     
      attachInterrupt(0, acceptorCount, RISING); //Digital interrupt pin 1
      attachInterrupt(1, acceptorPulse, RISING); //Digital interrupt pin 2
     
      Serial.println("Coin Acceptor ready");
      pulseCount = 0;
     
      pinMode(13, OUTPUT);
    }
     
    unsigned long tempAction;
    unsigned long tempPulse;
     
    void loop()
    {
      tempAction = lastAction;
      tempPulse = lastPulse;
     
      if (millis() - lastPulse >= pulseTimeout && pulseCount > 0 || pulseCount >= 4)
      {
        if (tempAction != lastAction || tempPulse != lastPulse) return; //Check if interrupt has fired since loop started, wait for next cycle if it has
       
        tone(12, 1800, 150);
        currentCredit += coinValues[pulseCount-1];
        showCredit();
        pulseCount = 0;
      }
     
     
      if ((millis() - lastAction >= actionTimeout) && (lastAction != 0) && (currentCredit > 0) && (pulseCount == 0))
      {
        if (tempAction != lastAction || tempPulse != lastPulse) return; //Check if interrupt has fired since loop started, wait for next cycle if it has
       
        currentCredit = 0;
        lastAction = 0;
        Serial.println("\n*** TIMEOUT! Credit reset. ***");
        showCredit();
      }
    }
     
    void acceptorPulse()
    {
      lastAction = millis();
      lastPulse = millis();
      pulseCount++;
    }
     
    void acceptorCount()
    {
      digitalWrite(13, digitalRead(13));
    }


all credit goes to https://www.youtube.com/watch?v=wLgWcS-utIM
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26627
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
Coin values:
     1 = 0.5
     2 = 1
     3 = 2
     4 = 10
     */
     
    const byte coinValues[4] = {  5, 10,50, 100};
Isn't there a mismatch between comment and code there?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: [1]   Go Up
Jump to: