Counting square wave pulses

Hi I am making a electronic water meter but I am not sure where to start on the code.

I use a hall-effect sensor that changes state as the impeller of my meter turns. What I need to do is count every time the square wave changes but I am not sure how to do it.

I enjoy the hardware part but the coding is very new to me

you could connect it to pin 2 or 3 i think it is so that you can have an interrupt service routine to increment some counter for you.

setup some global variable for your counter, then in your setup, attach an interrupt to the pin and set it to 'change' or whatever suits your application exactly.
http://arduino.cc/en/Reference/AttachInterrupt

then, for the function, just write a void function in your code that just does "counter++".

then, you should always have an up to date count :slight_smile:

thanks I tried it and it works like a charm :slight_smile: