I am try to make Simple Pulse Counter using arduino uno board, so i find following link
where write
"Simple circuit that counts pulses, and reports it through the serial monitor.
This circuit counts pulses fed into pin 12. In this circuit, the pulses are generated by a push-button. The arduino checks the state of pin 12 every one millisecond. If pin 12 goes high, the arduino will count it as a pulse. The amount of pulses detected is displayed on the serial monitor. If pin 12 is held high, the arduino will count it as a single pulse."
And Following code use
/* Simple Pulse Counter
Counts digital pulses fed into pin 12. For reliability, the minimum pulse width is 1 millisecond.
If the signal is held high, the arduino will count it as one pulse.
*/
const int input = 12; // This is where the input is fed.
int pulse = 0; // Variable for saving pulses count.
int var = 0;
void setup(){
pinMode(input, INPUT);
Serial.begin(9600);
Serial.println(F("No pulses yet...")); // Message to send initially (no pulses detected yet).
}
void loop(){
if(digitalRead(input) > var)
{
var = 1;
pulse++;
Serial.print(pulse);
Serial.print(F(" pulse"));
// Put an "s" if the amount of pulses is greater than 1.
if(pulse > 1) {Serial.print(F("s"));}
Serial.println(F(" detected."));
}
if(digitalRead(input) == 0) {var = 0;}
delay(1); // Delay for stability.
}
But when i am upload sketch and click on serial monitor then i see automatic pulse counting start continue ( I am Not press switch ), its totally auto start pulse counting continue.
i can't understand where is the problem in code, please you find solution then tell me