Coin counter to Interrupt pin. help.

hello, i'm using crowduino nano 328 for my project.

here's my code

const int cmd = 5;         // pin command for printing
const int coin = 0;        // pin for coinsense
char cCount = 0;           // temporary coin value handler
boolean ind = false;       // coin indicator
boolean pulse = false;     // ongoing pulse indicator
boolean sndNow = false;    // high pulse sending indicator
unsigned long insertTimer; // temporary time handler for coin
unsigned long printTimer;  // temporary time handler for printing
unsigned long pulseTimer;  // temporary time handler for cmd pulse
char cArray[9];            // inline coin count for printing
int idx = 0;               // pointer for coin array
int idxS = 0;              // command pointer


void setup(){              //This is where setup should be done.
  pinMode(cmd,OUTPUT);     // assigning pin as output
  digitalWrite(cmd,LOW);   // pull down command first
  attachInterrupt(coin, detectCoin, RISING); // Start coin Interrupt  
}

void loop(){             
  getCoinCount();
  sendCommand();
}


void getCoinCount(){
  if(ind && (millis()-insertTimer >= 3000)){  //3 sec period of consecutive input coins.
    insertTimer = 0;                          //reset timer for onother inputs.
    cArray[idx] = cCount;                     //save count to array.
    if(idx==8){idx=0;}else{idx++;}            //check if pointer,increment if less than the size of array otherwise reset.
    cCount = 0;                               //reset coin counter
    ind = false;                              //reset coin indicator
  }
}

void detectCoin(){                            //this is the ISR(Interrupt Sub Routine
    cCount++;                                 //increment counter for every pulse
    ind = true;                               //enable indicator
    insertTimer = millis();                   //get time stamp
}

void sendCommand(){                                            //This is where Command is send to host(Thread style execution)
  if(cArray[idxS]>0 && printTimer==0){printTimer = millis();}  //is specific array has a value to send? then set printerTimer.
  else if(cArray[idxS]>0 && printTimer>0){                     //is timer set and array at location idxS has value?
       if(!sndNow){                                            //should i send high pulse?
          pulseTimer = millis();                               //get time stamp for pulse timing                
          digitalWrite(cmd,HIGH);                              //send high pulse
          sndNow = true;                                       //indicate that i already sent high pulse
        }else{
          if(millis()-pulseTimer==500){                        //ofcourse high pulse is sent and were now checking the time for a period of 0.5sec 
            digitalWrite(cmd,LOW);                             //0.5 sec is reached, then pull down the sending line
          }else if(millis()-pulseTimer>=1000){                 //wait for 0.5sec again after pulling down the line 
           sndNow = false;                                     //0.5sec pulldown is reached,we now reset indicators and timers for the next pulse if any.
           pulseTimer = 0;
           cArray[idxS]--;                                     //ofcourse decrement the value after sending every pulse.
          }
        }
  }else if(printTimer>0){                                     //all pulse is sent and were now waiting for printer to finish his job.
        if(millis()-printTimer>=8000){                        //printer is done, we can now proceed to next index of array.
          printTimer = 0;
        }
  }else if(cArray[idxS]==0){                                  //array has no data to send?
        if(idxS==8){idxS=0;}                                  //well check its index if less than the size of the array.
        else {idxS++;}                                        //increment if less otherwise reset to zero.
  }
}

it was okay on my 1st upload but now it keeps on firing pulses without any input. i tried changing power source from usb or directed vin input but no luck.

This code seems to work fine but when I hold the input pin"wire" the pulses go crazy.

int cmd = 8;
int coin = 2;

void setup() {

pinMode(coin, INPUT);
pinMode(cmd, OUTPUT);
digitalWrite(cmd, LOW);

}

void loop() {
  if(digitalRead(coin)==HIGH)
  {digitalWrite(cmd, HIGH);
  }
  else{
    digitalWrite(cmd, LOW);
  }

}

anyone help XD

for the interrupt pin, have you set it to expect a signal (i.e. INPUT)?

Are you using an internal pull-up resistor or an external?

pinMode(myPin, INPUT_PULLUP);

When using INPUT_PULLUP, the coin read needs to look for a LOW.
Depending on how far along your wiring is, you can leave the code alone and just add a 10K resistor from pin 2 (coin) to Gnd so the pin is not "floating" and picking up random HIGH levels.

attachInterrupt(coin, detectCoin, RISING);

detetCoin serves as my ISR.

  pinMode(cmd,OUTPUT);     // assigning pin as output
  digitalWrite(cmd,LOW);   // pull down command first

That comment is nonsense. The Arduino does not have pull down resistors.

sorry that was intented to set the pin on low first.

Are you sure that the coin mech signal is normally LOW and pulses HIGH?

With serial and most others the OFF state is HIGH. That keeps the wire from building up a charge from outside influences and making false signals. The signal only goes LOW for short periods, the OFF state is HIGH. The rising edge would be at the end of the ON pulse.