Coin Acceptor 10 drops is to 1 output pulse - NEED HELP

Hi Everyone, i was wondering if anyone can help me, or give me an idea on how to do a sketch, or give me a sample sketch,,, that lets 10 tokens/coins drops from the coin acceptor before it outputs 1 pulse... or an led blinks or lits right after you have dropped 10 coins, i tried googling but dont seen to find any answers on this, im still a starter in arduino, so any help will be very much appreciated...tnx in advance

Can you post a link to the data sheet for the coin acceptor?

im still a starter in arduino, so any help will be very much appreciated.

OK you count the number of pulses from your coin box. To do this you monitor the input pin connected to your coin box to count the number of times that signal goes high ( or low if you coin box provides an inverted signal ). You do this with code you will find in the examples section of the IDE under Basic 2 -> State change detector.

When your count is greater than or equal to 10, use an if statement, output your pulse, digitalWrite HIGH, delay, digitalWrite LOW. And reset your count back to zero.

Good luck.

@groundFungus and Grumpy_Mike,,, it's just a straight forward standard coin mech that only accepts 1 type of coin (in my case i use a TOKEN), and just 1 pulse per coin coin drop,,, what i want to do is to drop 10 coins ,,,and wait if the coins are complete 10, only then will the LED will lit, to trigger something...

We got that from the original post. Grumpy_Mike told you what to do. In the IDE go to File, Examples, Digital. Open the state change detection example. Read it carefully and you will see how it counts pulses. Then look at the if reference to see how to compare the count to 10 and do something when 10 counts occur.

MackieZ: @groundFungus and Grumpy_Mike,,, it's just a straight forward standard coin mech that only accepts 1 type of coin (in my case i use a TOKEN), and just 1 pulse per coin coin drop,,, what i want to do is to drop 10 coins ,,,and wait if the coins are complete 10, only then will the LED will lit, to trigger something...

make a var that keep a tally/count of this 'pulse' (variable)... once this var reaches your threshold of '10'.. execute what you NORMALLY do when 1 pulse is detected.

(more or less what GM stated above.. give it a shot.. if its already working with the 1 pulse.. this should be a very quick/easy update to implement)

Tnx Grumpy_Mike, groundFungus & xl97 for the idea, on the example sketch at the IDE, ill test it later, maybe do some edits and ill post the results here weather its working or not, and hopefully ask for some ideas,,, but for now, ill just try the sample sketch first,,, again many tnx!!!

Hello guys, got it to work by using the State change detection Example, I just edit the 4 to 10,,, but i was wondering how to add another button that turns off the LED,,, after its has been triggered by 10 button pushes,, now i want to turn if off by using another button,, is that possible?

now i want to turn if off by using another button, is that possible?

Yes. Trivial, even.

Hello guys, got it to work by using the State change detection Example, I just edit the 4 to 10,,, but i was wondering how to add another button that turns off the LED,,, after its has been triggered by 10 button pushes,, now i want to turn it off by using another button,, is that possible?

Yes it is possible. You could have an if statement that executes only if the count is greater than or equal to 10 and (&&) the button is pushed.

Pseudocode:

boolean buttonState = digitalRead(buttonPin);
if(buttonPushCount >= 10 && buttonState == LOW)
{
   // turn off LED
 }

Switch wired like this:
digin.jpg

Hello groundFungus, tnx for the idea,,, i tried it, & changed it a little bit , but , i think there is a conflict between the two buttons,, or maybe i inserted your added code in wrong place,,,,, after 10 drops/pushes from button via pin2, it works fine the LED lits,,,, now the problem is when press the button via pin3,that is suppose to turn the LED off,,, it wont,,,the LED just winks or just dims a little bit and goes bright again as soon as lift my finger,,,i've also tried reversing the pullup resistor to pulldown but still thesame,,, can you pls examine my code?, & in were to make some changes,,, tnx in advance

this is my code, based on -- StateChangeDetection---------------------------

// this constant won't change: const int coinPin = 2; // button for coin in (need to drop/push 10 time b4 LED lits const int ledPin = 9; // the pin that the LED is attached to // to be connected to a RELAY const int off_buttonPin = 3; // this button is suppose to turn off the button, when it reached 10 drops

// Variables will change: int buttonPushCounter = 0; // counter for the number of button presses int buttonState = 0; // current state of the button int lastButtonState = 0; // previous state of the button int buttonState2 = 0; // for off_buttonPin

void setup() { // initialize the button pin as a input: pinMode(coinPin, INPUT); // initialize the LED as an output: pinMode(ledPin, OUTPUT); // initialize serial communication: pinMode(off_buttonPin, INPUT);

Serial.begin(9600); }

void loop() { // read the pushbutton input pin: buttonState = digitalRead(coinPin);

// compare the buttonState to its previous state if (buttonState != lastButtonState) { // if the state has changed, increment the counter if (buttonState == HIGH) { // if the current state is HIGH then the button // wend from off to on: buttonPushCounter++; Serial.println("on"); Serial.print("number of button pushes: "); Serial.println(buttonPushCounter); } else { // if the current state is LOW then the button // wend from on to off: Serial.println("off"); } // Delay a little bit to avoid bouncing delay(50); } // save the current state as the last state, //for next time through the loop lastButtonState = buttonState;

// turns on the LED every four button pushes by // checking the modulo of the button push counter. // the modulo function gives you the remainder of // the division of two numbers: if (buttonPushCounter % 10 == 0) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } boolean buttonState2 = digitalRead(off_buttonPin); if(buttonPushCounter >= 10 && buttonState2 == LOW) {digitalWrite(ledPin, LOW);} { // turn off LED }

}

You may this called cheating, but i can achieve to turn off the LED, by using internal PULLUP & i transfered from pin2 to pin8 as coin in, this puts the LED to Off State upon power on,,, then only lits after 10 drops,,, now to turn it off, i just use Arduino's RESET button, this resets the whole unit and cycles again,,,crazy idea right?,,, but i achieved my goal and can apply this to my project,,, maybe i'll just use relays and transistors as my I/O to reverse things.... This is the least i can do for now... but any suggestions to fix or improve the code to make it work as it should is very much appreciated... :)

Does this so what you want? My changes in comments (// *******).

// this constant won't change:
const int  coinPin = 2;      // button for coin in (need to drop/push 10 time b4 LED lits
const int ledPin = 9;        // the pin that the LED is attached to // to be connected to a RELAY
const int off_buttonPin = 3; //  this button is suppose to turn off the button, when it reached 10 drops

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button
int buttonState2 = 0;   // for off_buttonPin

void setup()
{
  // initialize the button pin as a input:
  pinMode(coinPin, INPUT);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communication:
  pinMode(off_buttonPin, INPUT_PULLUP);  // ******* enable internal pullup
  Serial.begin(9600);
}

void loop()
{
  // read the pushbutton input pin:
  buttonState = digitalRead(coinPin);

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState)
  {
    // if the state has changed, increment the counter
    if (buttonState == HIGH)
    {
      // if the current state is HIGH then the button
      // wend from off to on:
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter);
    }
    else
    {
      // if the current state is LOW then the button
      // wend from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state,
  //for next time through the loop
  lastButtonState = buttonState;


  // turns on the LED every four button pushes by
  // checking the modulo of the button push counter.
  // the modulo function gives you the remainder of
  // the division of two numbers:
  if (buttonPushCounter >= 10) // ******* not using modulo
  { 
    digitalWrite(ledPin, HIGH);
  }
  else
  {
    digitalWrite(ledPin, LOW);
  }
  boolean buttonState2 = digitalRead(off_buttonPin);
  if (buttonPushCounter >= 10 && buttonState2 == LOW)
  {
    digitalWrite(ledPin, LOW);
    buttonPushCounter = 0;  // ******* reset the counter
  }
}

This is how my test circuit is wired.
COIN.jpg

Many Tnx @groundFungus,,, its working now, with the pin3,, led turns off & timer resets,,, exactly what i wanted,,, did a small tweek at the input though...

Here's my final Code:

one again many many tnx groundFungus!!

// this constant won't change: const int coinPin = 8; // button for coin in (need to drop/push 10 time b4 LED lits const int ledPin = 9; // the pin that the LED is attached to // to be connected to a RELAY const int off_buttonPin = 3; // this button is suppose to turn off the LED, when it reached 10 drops & reset timer

// Variables will change: int buttonPushCounter = 0; // counter for the number of button presses int buttonState = 0; // current state of the button int lastButtonState = 0; // previous state of the button int buttonState2 = 0; // for off_buttonPin

void setup() { // initialize the button pin as a input: pinMode(coinPin, INPUT_PULLUP); // initialize the LED as an output: pinMode(ledPin, OUTPUT); // initialize serial communication: pinMode(off_buttonPin, INPUT_PULLUP); // ******* enable internal pullup Serial.begin(9600); }

void loop() { // read the pushbutton input pin: buttonState = digitalRead(coinPin);

// compare the buttonState to its previous state if (buttonState != lastButtonState) { // if the state has changed, increment the counter if (buttonState == HIGH) { // if the current state is HIGH then the button // wend from off to on: buttonPushCounter++; Serial.println("on"); Serial.print("number of button pushes: "); Serial.println(buttonPushCounter); } else { // if the current state is LOW then the button // wend from on to off: Serial.println("off"); } // Delay a little bit to avoid bouncing delay(50); } // save the current state as the last state, //for next time through the loop lastButtonState = buttonState;

// turns on the LED every four button pushes by // checking the modulo of the button push counter. // the modulo function gives you the remainder of // the division of two numbers: if (buttonPushCounter >= 10) // ******* not using modulo { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } boolean buttonState2 = digitalRead(off_buttonPin); if (buttonPushCounter >= 10 && buttonState2 == LOW) { digitalWrite(ledPin, LOW); buttonPushCounter = 0; // ******* reset the counter } }

i meant

const int off_buttonPin = 3; // this button is suppose to turn off the LED, when it reached 10 drops & reset the COUNTER (not timer)... tnx again!!!

hello groundFungus:,

is it possible for this project to integrated with a LCD? like a 16X2?

hello groundFungus,

is it possible for this project to be integrated with a LCD?, like a 16x2?

Sure it is. Once you have an LCD library installed and can write to the LCD, it is almost as easy as using Serial.print.

I like the LCD displays with the I2C backpack (only the 2 I2C pins used vs 6 0r 7). Here is a tutorial in their use.

thanks groundFungus, for the link and the idea,, i got it to work...