Relay wont turn off when Coin hopper starts spinning

Hi newbie here seeking for help.

Im working on a automated coin changer, and Im having problem with the relay.

Im using this relay https://arduino-info.wikispaces.com/RelayIsolation

and this coing hopper: http://www.alibaba.com/product-detail/game-accesary-blue-coin-Hopper_487639208.html

my RELAY SET UP:
Relay is powered by external breadboard 5v powersupply (JD-VCC and GND)

IN1 is connected to Arduino on PIN13
VCC is connected to Arduino on 5V
no Ground is connected from relay to arduino.

Coin Acceptor is Connected to interrupt 0 (Pin2)

IN1 relay is connected to PIN13
when a coin is inserted it goes to LOW state which energized the relay for 5 sec. then it turns off the relay.

the CODE WORKS FINE if the COIN HOPPER is DISCONNECTED.

Once you connect the Coin hopper to the relay,
You insert a coin, pin13 goes LOW (energize the relay)
Coin Hopper goes ON!
after 5 sec, it doesnt turn off.
it just sits there and turn on all the time.

i noticed that the arduino is trying to shut it off, the pin 13's LED is trying to turn on every 5 sec but it seems like it cant stop the relay anymore.
Please help.

const int coinInt = 0; 
//Attach coinInt to Interrupt Pin 0 (Digital Pin 2). Pin 3 = Interrpt Pin 1.

volatile float coinsValue = 0.00;
//Set the coinsValue to a Volatile float
//Volatile as this variable changes any time the Interrupt is triggered
int coinsChange = 0;                  
//A Coin has been inserted flag
const int pinRelay = 13;

void setup()
{
  Serial.begin(9600);                 
//Start Serial Communication
  attachInterrupt(coinInt, coinInserted, RISING);   
//If coinInt goes HIGH (a Pulse), call the coinInserted function
//An attachInterrupt will always trigger, even if your using delays
  pinMode(pinRelay, OUTPUT);
}

void coinInserted()    
//The function that is called every time it recieves a pulse
{
  coinsValue = coinsValue + 5;  
//As we set the Pulse to represent 5p or 5c we add this to the coinsValue
  coinsChange = 1;

//Flag that there has been a coin inserted
}




void loop()
{
  if(coinsChange == 1)          
//Check if a coin has been Inserted
  {
    coinsChange = 0;
    
//unflag that a coin has been inserted
  
    Serial.print("Credit: P");
    Serial.println(coinsValue);
    digitalWrite(pinRelay, LOW);
    delay(5000);
    digitalWrite(pinRelay, HIGH);
    
//Print the Value of coins inserted
  }
  else
  {
    digitalWrite(pinRelay, HIGH);
  }
  
}

Always connect the grounds

Riva:
Always connect the grounds

Hi Riva i tried,
still the same.

what i did so far..

Disconnect everything (its the arduino alone right now)
Plug the arduino to the computer (for POWER).
Pin13 is HIGH (as it should)

then i tried to plug in the coinhopper directly to the wall (connection to relay or arduino)
just the wall and the coin hopper.

to my surprise pin13 goes LOW. ( there is nothing pluged in to the arduino)
i turn on my serial monitor and the code is running.

i tried a different device i unpluged my Computer monitor
and pin13 goes LOW! goes high again after 5 sec.
check serial monitor, code is running.

u unplug my avr,
and pin13 goes LOW! goes high again after 5 sec.
check serial monitor, code is running.

everything i unplug is making the code run!
T_T
i dont know what to do now.
is it because of the interrupt pin?

Do you have a link to the manual for the hopper as I cannot seem to find anything online.

If plugging/unplugging anything causes interrupt to trigger then your getting electrical noise in the system.

How is the hopper powered? You say you plugged it directly into the wall but is this a DC power adapter or does the hopper take AC mains?

Maybe using a pulldown resistor on the interrupt pin will reduce noise effects and some sort of debounce (software/hardware)

Hi Riva no manual for this chinese coin hopper.
It plugs directly to a AC wall jack.

Riva:
If plugging/unplugging anything causes interrupt to trigger then your getting electrical noise in the system.

Maybe using a pulldown resistor on the interrupt pin will reduce noise effects and some sort of debounce (software/hardware)

Please see my debounce Resistor Capacitor I attached the pictures.

maybe your right im getting electrical noise.
But i already have a RC debounce set up for the interrrupt pin. what else can i do? thanks for your answers! i appreciate it!

Attaching Pictures.

That RC isn't doing anything, its just a resistor and capacitor in series adding a small
load to your signal line. Do you intend an RC low-pass filter?

Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

It is hard to tell from your picture what is hooked to where, such as the relay, power supplies press button.

Thanks Tom… :slight_smile:
PS Do you have a DMM to measure circuit values?

Your initial connection description is good - this uses the full opto-isolation feature of your relay board. No ground wire from the Arduino to the relay module is needed as this would defeat the purpose of opto-isolation.

Use another pin other than pin 13 as it is being used for the on board LED. For example, try pin 12. You will still have LED status indication on the relay board.

Interrupts are very, very sensitive and fast. Are you sure an interrupt is required for this application? If required, then how you've interfaced your coin acceptor signal is important. For example, this technical document shows how the signal is created and gives the specifications. Can you provide link to the datasheet? I'm guessing that the output is open-collector type. In this case, a pullup resistor, series resistor and "FALLING" interrupt might be required.

As MarkT has pointed out, your RC filter is doing nothing. Were you trying to connect it like this?

dlloyd:
Your initial connection description is good - this uses the full opto-isolation feature of your relay board. No ground wire from the Arduino to the relay module is needed as this would defeat the purpose of opto-isolation.

I did not realize the interrupt pin from the hopper was also isolated.

Hi All,

Thanks for your kind replies.

dlloyd:
As MarkT has pointed out, your RC filter is doing nothing. Were you trying to connect it like this?

Hi dlloyd,

yes that was my connection. it stops the pin 2 from continous sending as you said interrupt are so sensitive it stops the interrupt pin from getting so sensitive.

by the way guys, i already disconnect the RELAY, COIN Hopper, coin Acceptor. the only thing that is connected is this .

I noticed the problem, when i Unplug and plug something on my wall outlet, pin13 goes low and the code gets executed. I think the interrrupt is getting triggered whenever i Plug something on the wall..

Riva:
If plugging/unplugging anything causes interrupt to trigger then your getting electrical noise in the system.

How can i deal with electrical noise?
its so great even if i plug my coin hopper 2 meters away from the arduino, the code still gets triggered.
even if the arduino is isolated (no connections to anything execpt this

Hi,
The output from the coin acceptor, is it a voltage or is it just a switch that .
If you just put a DMM and measure volts at the output of the acceptor and its gnd, do you see a voltage when you get it to operate?
If so, does the coin changer have a power transformer in it.

What I'm worried about is that the acceptor circuit is not fully isolated from the main power input, I can't see in the picture on the sale site if it has a relay output or even an opto.

Tom..... :slight_smile:

Try as I might I cannot find a manual for this hopper on how it needs connecting. Do you have any form of manual for it that you can photograph the connection pages for us?
I assume (maybe foolishly) that hoppers will use standard connections to allow interchanging of parts and this manual does show a 4 pin Molex similar to the one shown in the link you supplied.
If it is the same and works on the same principle then you may have damaged the arduino interrupt pin with over volts.