Introduction: How to Control CH-926 Coin Acceptor With Arduino

In this instructable I am going to show you how to program the cheap CH-926 coin acceptor .

I will configure it to recognize 5different Euro coins and connect it to arduino.

Step 1: Coin Acceptor Built

Connection to power supply and microcontroller via 4 pins.

  • DC12 (you need dc12v to power the coina acceptor)
  • GND
  • COIN (through this pin impulses are sent to the microcontroller
  • COUNTER

Controlling the impuls length

  • 3 way switch

Three possible impulse lengths to select

  • fast(20ms)
  • medium(50ms)
  • slow(100ms)

Programming the acceptor

  • Setup button
  • Plus/Minus buttons
  • LED display
  • LED indicators

Front planel

  • Coin slot
  • Button for blocked coin removal
  • Return coin slot

Step 2: Programming the Acceptor

In this example we want to program 5 coin types:

  • 2 EUR coin1 impuls
  • 1 EUR coin 2 impulses
  • 50 cent coin 3 impulses
  • 20 cent coin 4 impulses
  • 10 cent coin 5 impulses

Here is the procedure how to program the acceptor to recognise a set of 5 different coins

  1. We start by pressing + and - buttons together until A is displayed
  2. After pressing Setup button E should be displayed
  3. With + - buttons we select number of types of coins. 5 in our case
  4. After pressing Setup again H1 is displayed. Here with + - we select number of sample coins we would use to program this first type of coin.
  5. After pressing Setup again P1 is displayed. Here we select number of impulses that would represent the first coin. In our case it will be 1 impuls for first coin 2 for second and so on
  6. After accepting it with setup button F1 is displayed. Here we set sensitivity (Recommanded value =6)
  7. After pressing setup button H2 is diplayed and we can repeat action for all other coin types
  8. When done LED display again shows A. After pressing Setup it changes to E. At this stage we can power off con acceptor
  9. When pressed again we get A1 and we are ready to sample first coin. Slot the coints one by one
  10. When done indicator LEDs blink and we A2 is displayed .
  11. Lets continue to sample all remaing coins types. With last coin type smapled zero is displayed again and coin acceptor is ready to be use

You can see the whole process int the YT video in intro section of this instructable

Step 3: Connecting Programmed Coin Acceptor to Arduino

We will connect following components

  • Arduino Nano
  • Coin acceptor
  • 7 segment four digit display

Here are the required connections:

  • Coin acceptor is connected to external 12v power supply
  • Arduino 5V is connected to Breadboard 5v Bus
  • Grounds of coin acceptor and arduino are connected
  • Coin pin of the acceptor is connected to D2 and via 10kresistor to 5v
  • 5v and GND pins of the 7 segment display are connected to 5v and GND of the arduino
  • CLK and DAT pis of the 7 segment display are connected to D3 and D4 pin of arduino

Step 4: Detecting Coins

Now few words about the method I used to detect coins

We will define an interrupt on D2 pin of the arduino. It worth to mention that we have to use 10k pullup resistor when connecting COIN pin to D2. I have tried to use arduino build in pullup resistor. It worked but the readings were not precise and sometimes coins were not properly recognised.

The function IncomingImpuls is linked to the interrupt and is executed each time the signals goes from High to Low on the interrupt pin D2

In the loop function we increase variable i by one each time the loop function is run.

Now imagine that we get two impulses which would indicated 1 EUR coin being inserted

In this case IncomingImpuls function would be executed twice Each time it is executed we increase ImpulseCount variable. After two executions this variable would equal to 2. We also reset i variable to zero so in the loop function the countdown starts anew.

Impulses belonging to a single coin are close apart. If i is valued at 30 we can assume that all incoming impulses were received and we have a proper number of impulses recorded in the ImpulseCount variable and we can determine which coin was inserted. We can also be certain that with i at 30 there has been not enough time for anybody to insert next coin. In this case we detected 2 impulses and when i reached value of 30 we add the recognised 1EUR to our total and reset ImpulseCount to zero awaiting next incoming impulses belonging to next inserted coin.

Step 5: Code

Here is the code of the solution in which we sum all inserted coins and display the balance on the 7 segment 4 digit display

At the start of the sketch we have library declarations.

<p><span>#include </span><span><</span><span>Arduino.h</span><span>></span></p><p><span>#include </span><span><</span><span>TM1637Display</span><span>.h></span></p><p><span>#include </span><span><</span><span>EEPROM</span><span>.h></span></p>

Then we specify which pins would be used to connect 4digit display

#define CLK 3

#define DIO 4

The display is declared using those pins

TM1637Displaydisplay(CLK,IO);

Then we introduce 3 variables

  • i used to measure interval inbetween impulses
  • impulsCount to count incoming imoulses
  • total_ amount to store the sum of all inserted coins

int i;
int impulsCount=0;
float total_amount=0;

IncomingImpuls function is the the one connected to interrupt on digital pin2

void incomingImpuls()
{
  impulsCount=impulsCount+1;
  i_count=i;
  i=0;
}

In setup function we declare the interrupt and clear the display.

void setup() {
 // Interrupt connected to PIN D2 executing IncomingImpuls function when signal goes from HIGH to LOW
 attachInterrupt(0,incomingImpuls, FALLING);
 EEPROM.get(0, total_amount);
 display.clear();
}

In loop function with each execution we increase i variable by one Then we check if Interrupt detected incoming impulses and if it did if i has reached a value of 30 whichwould idicate that we received all incoming impulses belonging to a single coin. In such case we add the value of recognised coin to total amount and reset impulsCount back to zero.

When only one impuls is detected it was a 2EUR coin

  • If it was two impulses it was 1 EUR coin
  • 3impulses mean 50 eurocent coin
  • 4 impulses mean 20 cent coin
  • 5 impulses mean 10 eurocents coin

if (i>=30 and impulsCount==1){
    total_amount=total_amount+2;
    impulsCount=0;
    //EEPROM.put(0, total_amount);
  }
   if (i>=30 and impulsCount==2){
    total_amount=total_amount+1;
    impulsCount=0;
   // EEPROM.put(0, total_amount);
  }
   if (i>=30 and impulsCount==3){
    total_amount=total_amount+0.5;
    impulsCount=0;
    //EEPROM.put(0, total_amount);
  }
   if (i>=30 and impulsCount==4){
    total_amount=total_amount+0.2;
    impulsCount=0;
   // EEPROM.put(0, total_amount);
  }
   if (i>=30 and impulsCount==5){
    total_amount=total_amount+0.1;
    impulsCount=0;
    //EEPROM.put(0, total_amount);
  }
Finally we output the current balance to the 7 segment display
 if(total_amount<10) display.showNumberDecEx(total_amount*10, 0b10000000, true, 2, 2); 
  else
  display.showNumberDecEx(total_amount*10, 0b00100000, false, 4, 0);
}
If the balance is below 10EUR we need to add leading 0.

The last problem with our project is that when we power down arduino we loose information about coins inserted.

When restart arduino display is reset back to 0.

This can be fixed by saving total_amount in Arduino build in EEPRom.

To do this simply uncomment EEPROM lines of code in the loop funstion show above.

EEPROM can be written to a particular address 100.000 before it starts messing up the values.

Step 6: Conclusion

Thank you for spending time reading thorough this Instructable. Please watch the video in the intro section of this tutorial.

Link to the code:
https://create.arduino.cc/projecthub/mdraber/control-coin-acceptor-with-arduino-335950?ref=user&ref_id=1474727&offset=4

If you like this content and you want to support me in creating similar videos go to my Patreon webpage

https://www.patreon.com/MariosIdeas Or Paypal