/* Program 6-3: Counting Pulses * External pulses from pin 13 are fed to pin 3 (interrupt 2) of Arduino * the ISR counts up pulses and displays them on the Serial Monitor */ volatile int count = LOW; void setup() { pinMode(13, OUTPUT); /* set pin 13 as output, for generating pulses */ pinMode(3, INPUT); //make pin3 interrupt as input, pin 13 pulses are fed to pin3 Serial.begin(9600); attachInterrupt(digitalPinToInterrupt(3), PulseCounterISR, RISING); } void loop() { digitalWrite(13,HIGH); /* turn on the LED */ delay(750); /* delay 750 ms */ digitalWrite(13,LOW); /* turn off the LED */ delay(750); /* delay 750 ms */ } //Interrupt Service Routine void PulseCounterISR() { count++; //count up pulses Serial.println(count); // Display pulse counts on Serial Monitor }