I got a cheap tipping bucket rain gauge off eBay. When the bucket tips, the two attached wires connects for around half a second. I'd like to count that event.
Browsing around got me interested in the interrupt function but I can't quite get it working. I recon my Uno uses pin2 for interrupt 0 and experimented with both 3.3v, 5v and GND for the other one - rising/falling.
Running it sometimes types me a zero. Other times it gives me for example 151, 300, 450 etc. What are we counting? Something 50 Hz for 3 seconds? Sounds like the grid AC in my house.
If I tip the bucket, sometimes the counting stops in the middle position, other times nothing happens.
How can I make one tip (perhaps 500ms connection) count as +1? I plan on actually making my rain guage count millimeters of water.
Well, you browsed to the wrong places. An interrupt is not a good way to handle such a slow event. But your problem is likely that your switch is not de-bounced. You will have to do that whether it is done with an interrupt or not.
The purpose of the resistor is to guarantee the state of the pi when the switch is open. An Arduino I/O pin that is not connected to anything can randomly assume HIGH or LOW values and change rapidly between them.
The Atmega MCU has internal resistors that can be selected with pinMode(pinNum, INPUT_PULLUP); That guarantees that the pin reads HIGH until the external switch connects it to GND and pulls it LOW.
Thank you for a long and informative answer. You make newbies feel welcome.
I take it you could not be bothered to try to googling "switch debouncing", or to take the suggestion to use a pullup resistor seriously.
When you do the google search, the very first hit that turns up (in my location at least) is remarkably informative, and titled "A guide to debouncing". http://www.eng.utah.edu/~cs5780/debouncing.pdf