Trouble with Coin Acceptor/120V triggering pulse

Hi everyone.
I'm posting this plea for help after a few weeks of researching and trying to figure out the best solution.
I'm creating an interactive boardwalk game, and I'm having trouble with false interrupt pulses being detected from the coin acceptor, but mainly only when the 120V circuit is connected.
I have 16 one-channel relays daisy chained in a circle, an Adafruit coin acceptor, and a lighted button.
Here are some examples of the false interrupts I have been experiencing:

  • When a coin is touched to the metal plate of the coin acceptor, but not inserted. (I as sume this is a grounding issue?"
  • When the bell rings, powered by 5V 1amp, not shown in the diagram.
  • When I move the machine while it is on.

I tried doing a pullup resistor with the coin acceptor which didn't work, but a pulldown resister seems to work okay.

I've perused the internet and this forum for possible solutions and the following solutions are:

  • Ceramic capacitors across the signal wire
  • Wire shields
  • Ferrite
  • Twisted wires

Code:

#include <Arduino.h>
#include <elapsedMillis.h>

// Module connection pins (Digital Pins)
#define CLK 3
#define DIO 4

volatile int impulsCount = 0;
// Led initialization
volatile int Leds = 16;
volatile int led[] = { 4, 5, 6, 7, 8, 9, 10, 11, 12, 26, 14, 15, 16, 17, 22, 23 };

const int Button_Pin = 25;
const int Led_Pin = 47;
const int Bell_Pin = 50;
volatile int i = 0;

// For Timer
elapsedMillis timeElapsed;

//*************************** Void Setup *******************************************//
void setup() {
  Serial.begin(9600);

  pinMode(2, INPUT);
  pinMode(Bell_Pin, OUTPUT);

  attachInterrupt(0, incomingImpuls, FALLING);
  Serial.println("................Setup Started");

  pinMode(LED_BUILTIN, OUTPUT);  // For Test purpose onboard Led is being used as button Led
  pinMode(Button_Pin, INPUT);
  pinMode(Led_Pin, OUTPUT);

  digitalWrite(LED_BUILTIN, HIGH);
  digitalWrite(Led_Pin, HIGH);
  Serial.println("[Button LED ON]");
  digitalWrite(33, LOW);

  for (i = 0; i <= Leds; i++) {
    pinMode(led[i], OUTPUT);
  }

  Serial.println(".................Setup Completed");
  Serial.println(impulsCount);
}
//********************************** Start ********************************//
void Start_Pattern() {
  Serial.println("Startup: All 16 Leds will light Up for 5 seconds");
  impulsCount = 0;

  for (i = 0; i <= Leds; i++) {
    digitalWrite(led[i], HIGH);
  }
  delay(0);
  for (i = 0; i <= Leds; i++) {
    digitalWrite(led[i], LOW);
  }
  Serial.println("Startup Completed");

  impulsCount = 0;
}

//*************************** 1 Minute and 80 ms Pattern *****************//
void Pattern1() {
  impulsCount = 0;
  Serial.println("Pattern 1: All Leds will blink in circle for 1 minute");
  Serial.println(impulsCount);
  timeElapsed = 0;
  unsigned int interval = 3000;
  while (timeElapsed < interval) {
    for (i = 0; i <= Leds; i++) {
      digitalWrite(led[i], HIGH);
      delay(180);
      digitalWrite(led[i], LOW);
    }
  }
  Serial.println(impulsCount);
  Serial.println("Pattern 1 Completed");
}

//******************** 30 seconds Random Blink Pattern *****************//
void Pattern2() {
  Serial.println("Pattern 2: Random Leds will blink for 30 seconds");
  timeElapsed = 0;
  unsigned int interval = 3000;
  while (timeElapsed < interval) {
    int temp = random(16);
    digitalWrite(led[temp], HIGH);
    delay(180);
    digitalWrite(led[temp], LOW);
  }
  Serial.println("Pattern 2 Completed");
  Serial.println("Pattern 1 & 2 will be repeated ");
}

//***************************** Interrupt Code  **************************//
void incomingImpuls() {
  impulsCount = 1;

  Serial.println("coin");

  for (i = 0; i <= Leds; i++) {
    digitalWrite(led[i], LOW);
  }

  while (digitalRead(Button_Pin) == LOW) {
    digitalWrite(LED_BUILTIN, LOW);
    digitalWrite(Led_Pin, LOW);
    delay(100000);
    digitalWrite(LED_BUILTIN, HIGH);
    digitalWrite(Led_Pin, HIGH);
    delay(100000);
  }

  Button_Pattern();
}
//*************************** After Button Pressed pattern *****************//
void Button_Pattern() {
  int timer = 500;
  int temp = 500;
  for (int k = 0; k < 4; k++) {
    for (i = 0; i <= Leds; i++) {
      digitalWrite(led[i], HIGH);
      delay(timer);
      timer = timer + temp;
      Serial.println(timer);
      digitalWrite(led[i], LOW);
      if (timer == 1900 && i == 11) {
        digitalWrite(led[11], HIGH);
        i = 20;
      }
    }
    temp = temp + 100;
  }
  for (i = 0; i <= Leds; i++) {
    digitalWrite(led[i], LOW);
    digitalWrite(Bell_Pin, HIGH);
  }
  for (i = 0; i < 10; i++) {
    digitalWrite(led[0], HIGH);

    Serial.println("11 BLINK ON");
    delay(80000);
    digitalWrite(led[0], LOW);

    Serial.println("11 BLINK OFF");
    delay(80000);
  }
  digitalWrite(Bell_Pin, LOW);
  impulsCount = 0;
}

void loop() {
  Serial.println(".....................................Loop Started");
  Start_Pattern();
  Pattern1();
  Pattern2();
}

Thank you for your help in advance. I'd really like to solve this issue. :slight_smile:

Does this ...Love Tester... have a bump sensor?

Do these frayed wires touch?

I know it's a dicey set up but no, they don't touch. It doesn't have a bump sensor, the signal wire from the coin acceptor sends 30ms pulses, so the interrupt is triggered by a pulse.

Hi,
The pin that senses the coin operation, does it switch to gnd when it operates to signal a coin?
If so and it is a NO of a relay, when the relay is OPEN, that input is floating, you need to add a 10K from the input pin to 5V to pull the pin HIGH when coin unit is open.
OR
pinMode the input pin as INPUT_PULLUP rather than INPUT.

I hope that helps.

A proper schematic would also help.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

To add code please click this link;

Tom.. :smiley: :+1: :coffee: :australia:

Not a good idea to use pin 0 for anything other than serial input. Do you have a pullup resistor on the white wire to 5V?

I'm not using Pin 0, on the MEGA 2, 3, 21, 20, 19, and 18, which correspond with 0, 1, 2, 3, 4, 5 in the attachInterrupt function

I don't have a pullup resister on 5v, I explained in my initial post that adding a pullup resister to 5V gave me an automatic trigger, but a pulldown on GND seems to work.

Hi, It doesn't switch to ground, the interrupt is triggered by a pulse.
Can you explain what you mean when you say the input is floating? I'm sorry I'm lacking of the correct terms of things.
I can work on making a hand-drawn circuit.
Thank you!

Is this a measurable pulse? Could the "pulse" be triggered by an input elsewhere (the reaction of a reaction...). Echoing @cedarlakeinstruments - your code shows your ISR is attached to pin 0.:

  attachInterrupt(0, incomingImpuls, FALLING);

Arduino recommends for the Mega:

2, 3, 18, 19, 20, 21 (pins 20 & 21 are not available to use for interrupts while they are used for I2C communication)

** bare wires that might touch something if jostled.

May I propose a counting method (for my ocd). Can't find wire on Pin23 for `leds[9]'? (small white text overlay on image)

Seems like this is your coin selector (instruction sheet).

If so, a pullup resistor isn't allowed, but I would suggest trying the slow 100ms option and setting the switch to N.O. mode, then try RISING interrupt mode. If that fails, try FALLING interrupt mode. If that fails, try getting a plot of what the signal looks like when connected to an analog input.

Are you aware that any significant noise riding on the signal on the pin you are watching will cause an interrupt, even before the actual pulse has completed?

I was half asleep when I read it, but I'm pretty sure the instructions on the Adafruit site (not that instruction sheet) said that the pulse output to arduino was on the white wire and needed a pullup to 5V.

Your right, the Adafruit site does say to use a pullup, but then Adafruit links to the manufacturer's instruction sheet that shows this:

image

Hmm ... I'm inclined to side with the manufacturer unless they've already confirmed otherwise.

Not familiar with this product ... perhaps the white Coin acceptor wire is separate from the NO NC switch.

Maybe disconnect one wire at a time from the coin acceptor until the "pulse" stops causing the problem?

It looks like the device has a built-in counter display. Could be what it's referring to. Either way, external pulldowns are rare enough that I find it hard to believe that's the solution.

Yes, I agree. Just browsing some images of coin selector circuits, 10K pullup on the coin signal seems to be most common.

Possible, but without seeing the signal, I would guess this isn't in a reliable state. Your circuit is quite "busy" with lots of relays, perhaps not configured for opto-isolation mode.

I would try a much simpler circuit just to make sure the coin selector works properly and reliably.
This seems like a good tutorial that could do this.

The coinacceptor datasheet says the pulse is configurable from 20ms to 60ms. Maybe config to max pulse width?