pluse counter

Then have a look at this:-
http://www.arduino.cc/en/Reference/AttachInterrupt