Hey Guys really need your help on how to accurately read the pulse signal input from a Coin Slot to Arduino Uno
This is the code i used:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 6, 5, 4, 3);
volatile int coins = 0;
void setup()
{
lcd.begin(16, 2);
Serial.begin(9600);
attachInterrupt(0, coinInserted, CHANGE );
}
void coinInserted()
{
//delay(1000);
coins = coins + 1;
}
void loop()
{
lcd.setCursor(1,0);
lcd.print(coins);
}
the coin slot has been set for 3 outputs:
P1.00 coin- 1 pulse
P5.00 coin- 5 pulse
P10.00 coin- 10 pulse
I used a LCD to see if the "coins" value counts corresponding to the coin inserted. But when i started to test,
the LCD DISPLAYS A CONTINUES COUNT OF THE "coins" VALUE EVEN WHEN I HAVEN'T EVEN INSERTED A COIN IN THE COIN SLOT.
In the attachInterrupt command, i interchange the "CHANGE", "LOW", "RISING", and "FALLING" and here what happens:
Falling: with delay set to 5000 - 50000, even without a coin inserted it counts up but more slowly
Rising: the same as Falling
Change: the same as Falling and Rising
Low: with delay set to 5000 - 50000, after uploading the program code to arduino the LCD doesn't display anything. Without any delay and after uploading the program code the LCD displays a continues count up of the "coins" value insanely fast.
What i'm after:
If I inserted a coin, (1,5 or 10), the LCD should display from "0" to the corresponding count up of pulses being read by the arduino (0 to 1, 0 to 5, 0 to 10) and continues to count up depending on the coin being inserted.
REALLY NEED HELP ON FIXING THIS PROBLEM.