Coin Acceptor Fault

Hey All,

I am currently working on a project involving a coin acceptor. I have a code that waits until there are 4 pulses send to the Arduino before it will activate two motors.

This is all working fine, but I am trying to combat a mysterious problem I have with the coin acceptor. Every now and then when I go to insert a coin it will register that a coin has been inserted when all I have done is touched the front panel or inserted the coin a tiny way into the slot.

I think I am experiencing the same issue as this: http://www.instructables.com/id/The-Soda-Locker-Vending-Machine/step6/Money-Cheat/

I have tried to use parts of his code to combat the problem but all I can seem to do is stop my code from counting the pulses and do all sorts of funky stuff.

I have also tried using my basic code and earthing the coin acceptor’s metal part to the -v on the power supply.

Here is my basic code without the changes:

#include <AFMotor.h>
#include <LiquidCrystal_I2C.h> 
#include <Wire.h> 

AF_DCMotor motor(1); // create motor #2, 64KHz pwm
AF_DCMotor motor2(2); // create motor #2, 64KHz pwm
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address (addr, en, rw, rs, d4, d5, d6, d7, backlight, polarity)

// Constants
const int coinpin = 2;
const int ledpin = 3;
const int targetcents = 4;

// Variables
volatile int cents = 0.00;

int credits = 0;
int coins = 0;

// Setup
void setup() {

  
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(coinpin), coinInterrupt, RISING);
  pinMode(ledpin, OUTPUT);
  motor.setSpeed(200);     // set the speed to 200/255
  motor2.setSpeed(200);     // set the speed to 200/255
  lcd.begin(20,4);   // Initialize the lcd for 20 chars 4 lines, turn on backlight
  //lcd.noBacklight(); // Turns backlight off
lcd.clear();
  // NOTE: Cursor Position: (CHAR, LINE) starts at 0  
  lcd.setCursor(3,0);
  lcd.print("Hey");
  lcd.setCursor(3,1);
  lcd.print("Official Show");
  lcd.setCursor(5,2);
  lcd.print("Programme");
  lcd.setCursor(6,3);
  lcd.print("");

}

// Main loop
void loop() {
  
  // If we've hit our target amount of coins, increment our credits and reset the cents counter
  if (cents >= targetcents) { 
    credits = credits + 1;
    cents = cents - targetcents;
    
  }

  // If we haven't reached our target, keep waiting...
  else {
   lcd.clear();
  lcd.setCursor(3,0);
  lcd.print("Hey");
  lcd.setCursor(3,1);
  lcd.print("Official Show");
  lcd.setCursor(5,2);
  lcd.print("Programme");
  lcd.setCursor(6,3);
  lcd.print(cents);

  delay(1000);
  }

  // Debugging zone
  Serial.print(cents);
  Serial.print(" Money toward current programme and ");
  Serial.print(credits);
  Serial.println(" programme(s) earned so far.");
  Serial.print(coins);
  Serial.println(" programme(s) earned so far.");
  delay(1000);
   // Turn off LED
  digitalWrite(ledpin, LOW);


  // Now, write your own cool code here that triggers an event when the player has credits!
  if (credits > 0) {
    lcd.clear();
    //lcd.setCursor(2,0);
   // lcd.print("");
    lcd.setCursor(5,1);
    lcd.print("Processing");
    lcd.setCursor(4,2);
    lcd.print("Please Wait");
    lcd.setCursor(5,3);
    lcd.print("..........");
    
     digitalWrite(ledpin, HIGH);
     delay(1000);
     digitalWrite(ledpin, LOW);
     delay(1000);
     digitalWrite(ledpin, HIGH);
     delay(1000);
     digitalWrite(ledpin, LOW);
     // Turn Motors In hopper One
     motor.run(FORWARD);      // turn it on going forward
     motor2.run(FORWARD);      // turn it on going forward

     //Delay
     delay(1000);
      //asm volatile ("  jmp 0");
    return;
    // Spin up a motor?
    // Start a game?
    // It's up to you!
    
  }

}

// Interrupt
void coinInterrupt(){
  
  // Each time a pulse is sent from the coin acceptor, interrupt main loop to add 1 cent and flip on the LED
  cents = cents + 1;
  coins = coins + 1;
  digitalWrite(ledpin, HIGH);
  
 }

If anyone could assist me it would be much appreciated as I am now pulling my hair out as to what I can do to stop this error.

volatile int cents = 0.00;

You don't seem to grasp the concept of int.

  cents = cents + 1;
  coins = coins + 1;

Why do you need to count coins and cents exactly the same way?

Why is coins not volatile?

I think you need to provide a link to the coin acceptor you are using, and I think you need to contact the manufacturer to get their recommendations on how to avoid the problems.

Hey PaulS,

That was just some testing I was doing but does not have anything to do with the acceptor's functionality.

The coin acceptor i am using is:
http://www.ebay.co.uk/itm/192122841916?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

The coin acceptor i am using is:

Do you really think ebay made that?

Hi
It is possible that your are experiencing a problem caused by static. Make sure the chassis it is grounding.

tauro0221:
Hi
It is possible that your are experiencing a problem caused by static. Make sure the chassis it is grounding.

The problem is EDDCATON is carrying the static charge to the coin acceptor. When the device and all are ground and the holder of the coin is charged, guess what happens when the coin or flesh of the operator touches the metal. The ground suddenly goes very high voltage/current for a very short time and this is = to a pulse on the active circuits.

He needs to separately ground the acceptor metal surface directly the ground point, not through the electronics of the mechanism.

Paul

What is connected to "coinPin" is the pin "floating" when not activated?

Hello all,

Thanks for the helpful comments.

The front panel of the coin slot is plastic... I have grounded the metal parts i can see to the -V of the 12v PSU I am using.

CoinPin is the output from the coin acceptor.

I did think that static might be the case, as there is a link that talks about the same issue:

They seem to combat the static by measuring the pulses and only accepting pulses within a certain tolerance of time. But i cannot seem to get that code to work with mine.

eddcaton:
Hello all,

Thanks for the helpful comments.

The front panel of the coin slot is plastic... I have grounded the metal parts i can see to the -V of the 12v PSU I am using.

CoinPin is the output from the coin acceptor.

I did think that static might be the case, as there is a link that talks about the same issue:
http://www.instructables.com/id/The-Soda-Locker-Vending-Machine/step6/Money-Cheat/

They seem to combat the static by measuring the pulses and only accepting pulses within a certain tolerance of time. But i cannot seem to get that code to work with mine.

Your plastic is an insulator, therefore it can be charged electrostatically. An old fix for plastic cased panel meters when the plastic was charged and capture the needle was to mix a bit of dishwashing detergent and water and lightly coat the meter plastic with the mixture. When dry, a film was left that was slightly conductive and that would bleed off any static charge.

Worth a test with your static problem Be sure to get a bit of the solution onto a grounded metal part.

Let me know if this works.

Paul

Hi,
You can try the anti-static spray. It may works.

Hi,

I have tried the Anti-Static spray which works intermittently, but I am looking for a more permanent fix. Is there a way to do this on the timing of the pulses?

Hi,
Some suggestion.
1- Mount the micro in aluminum plate and ground it or mount it a metal case. This will shield it from the plastic.
2- Try to paint the back of the panel with metallic galvanize paint and ground it.
3- Use ESD protection in the inputs. They will discharge any electrostatic voltage in the input.
4- Use shielding input wires or try to twist the one in uses now.
5. Last try relocating the micro from the front panel.

Just few suggestion.