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);
}
}