Pages: [1]   Go Down
Author Topic: CoinSlot to Arduino... Need Help  (Read 526 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Coin Slot to Arduino... Need Help. What to do?
Hey guys, been doing one of the project in instructables w/c is this
http://www.instructables.com/id/Make-Money-with-Arduino/

Interfacing a Coin Slot to a Arduino. Read and done the instructions provided in the project. But there seems to be a problem bec. i can't seem to get the desired output.

I have a Coin Slot w/c was already set to 3 different types of coins (P1, P5.00, P10.00)(Philippine Coins)
Set it up according to the instructions of the project, "COIN" white wire connected to pin2 (interrupt pin 0) of the arduino, common ground connection of the arduino and the coin slot (12V), and for an easy way to see the output i put up 3 LEDs on pin8, pin9, and pin10.

This is the code i used, (modified)(original comments still there)
--
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;
int OneLed = 8;
int FiveLed = 9;
int TenLed = 10;
//A Coin has been inserted flag

void setup()
{
  pinMode(OneLed, OUTPUT);
  pinMode(FiveLed, OUTPUT);
  pinMode(TenLed, OUTPUT);
  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
}

void coinInserted()   
//The function that is called every time it recieves a pulse
{
  coinsValue = coinsValue + 1;
//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
  {
   if (coinsValue == 1)
    {
       digitalWrite(OneLed, HIGH);
       delay(1000);
       digitalWrite(OneLed, LOW);
    }
    else if (coinsValue == 5)
    {
       digitalWrite(FiveLed, HIGH);
       delay(1000);
       digitalWrite(FiveLed, LOW);
    }
    else if (coinsValue == 10)
    {
       digitalWrite(TenLed, HIGH);
       delay(1000);
       digitalWrite(TenLed, LOW);
    }
//Print the Value of coins inserted
  coinsChange = 0;
  }
}
--
Rather than using microsoft express, i wanted to use simple LEDs on pin8, pin9, and pin10 to indicate if the program read the input correctly.
after doing the wiring, and coding in the arduino, i tested to see if it would work.
NONE of the LEDs light up after inserting coins on the coinslot.
Need Help :X
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Coin Slot to Arduino... Need Help. What to do?
Hey guys, been doing one of the project in instructables w/c is this
http://www.instructables.com/id/Make-Money-with-Arduino/

Interfacing a Coin Slot to a Arduino. Read and done the instructions provided in the project. But there seems to be a problem bec. i can't seem to get the desired output.

I have a Coin Slot w/c was already set to 3 different types of coins (P1, P5.00, P10.00)(Philippine Coins)
Set it up according to the instructions of the project, "COIN" white wire connected to pin2 (interrupt pin 0) of the arduino, common ground connection of the arduino and the coin slot (12V), and for an easy way to see the output i put up 3 LEDs on pin8, pin9, and pin10.

This is the code i used, (modified)(original comments still there)
--
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;
int OneLed = 8;
int FiveLed = 9;
int TenLed = 10;
//A Coin has been inserted flag

void setup()
{
  pinMode(OneLed, OUTPUT);
  pinMode(FiveLed, OUTPUT);
  pinMode(TenLed, OUTPUT);
  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
}

void coinInserted()   
//The function that is called every time it recieves a pulse
{
  coinsValue = coinsValue + 1;
//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
  {
   if (coinsValue == 1)
    {
       digitalWrite(OneLed, HIGH);
       delay(1000);
       digitalWrite(OneLed, LOW);
    }
    else if (coinsValue == 5)
    {
       digitalWrite(FiveLed, HIGH);
       delay(1000);
       digitalWrite(FiveLed, LOW);
    }
    else if (coinsValue == 10)
    {
       digitalWrite(TenLed, HIGH);
       delay(1000);
       digitalWrite(TenLed, LOW);
    }
//Print the Value of coins inserted
  coinsChange = 0;
  }
}
--
Rather than using microsoft express, i wanted to use simple LEDs on pin8, pin9, and pin10 to indicate if the program read the input correctly.
after doing the wiring, and coding in the arduino, i tested to see if it would work.
NONE of the LEDs light up after inserting coins on the coinslot.
Need Help :X
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Read this before posting a programming question


Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.gammon.com.au/interrupts

Variables used in the ISR need to be volatile.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Coin Slot to Arduino... Need Help. What to do?

This is the code i used, (modified)(original comments still there)
This code doesn't seem to do what i want as an output.

Code:
[/b]
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;
int OneLed = 8;
int FiveLed = 9;
int TenLed = 10;
//A Coin has been inserted flag

void setup()
{
  pinMode(OneLed, OUTPUT);
  pinMode(FiveLed, OUTPUT);
  pinMode(TenLed, OUTPUT);
  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
}

void coinInserted()   
//The function that is called every time it recieves a pulse
{
  coinsValue = coinsValue + 1;
//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
  {
   if (coinsValue == 1)
    {
       digitalWrite(OneLed, HIGH);
       delay(1000);
       digitalWrite(OneLed, LOW);
    }
    else if (coinsValue == 5)
    {
       digitalWrite(FiveLed, HIGH);
       delay(1000);
       digitalWrite(FiveLed, LOW);
    }
    else if (coinsValue == 10)
    {
       digitalWrite(TenLed, HIGH);
       delay(1000);
       digitalWrite(TenLed, LOW);
    }
//Print the Value of coins inserted
  coinsChange = 0;
  }
}

What i want to do is, after receiving pulses from the COIN SLOT the arduino will count the number of pulses (1,5, or 10 pulses) then lights up LED corresponding to the number of pulses (if there is 1 pulse, LED1 will be HIGH; if there are 5 pulses, LED2 will be HIGH; if there are 10 pulses, LED3 will be HIGH)



any comments/suggestions?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46090
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
any comments/suggestions?
Sure. Hook up another LED with resistor to another pin. In the ISR, turn the LED pin on.

At least you'll know whether the interrupt was triggered.
Logged

USA
Offline Offline
God Member
*****
Karma: 14
Posts: 644
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For debugging purposes, I would have some message to the Arduino IDE's serial monitor that displays when the void coinInserted() is called.  Just placing one right at the end would give an indication if your ISR is even being called.
Logged

nr Bundaberg, Australia
Online Online
Tesla Member
***
Karma: 121
Posts: 8448
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It seems to me that you need to wait for X amount of time with no pulses before you can use the count. As it is your using coinsValue straight away on the first pulse when there may be more pulses on the way, then you delay(1000) which presumably misses all subsequent pulses.

Also you never reset coinsValue so it's value will continue to rise well past 10.

As it stands I would expect the LEDs to light on the 1st, 5th and 10th coins then never again.

coinsChange should be volatile.

There's no reason to have coinsValue as a float, that's silly. Use an int.


______
Rob

« Last Edit: October 24, 2012, 11:28:40 am by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

any comments/suggestions?

Yes. Pay attention to when I said to make ISR variables volatile. Don't just ignore it.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int coinsChange = 0;
...
void coinInserted()   
{
  coinsValue = coinsValue + 1;
  coinsChange = 1;                         
}

...
void loop()
{
  if(coinsChange == 1)     
...

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46090
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Don't just ignore it.
To be fair, OP didn't. He/she just didn't make all ISR and loop() accessed variables volatile.
Logged

nr Bundaberg, Australia
Online Online
Tesla Member
***
Karma: 121
Posts: 8448
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well the OP is ignoring other people, this has been cross posted, myself and Far-seeker responded to the exact same post yesterday

http://arduino.cc/forum/index.php/topic,128790.msg969482.html#msg969482

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Topics merged.
Logged

Pages: [1]   Go Up
Jump to: