As you can tell from my other pages, I participate in local amateur radio activities. This includes communications support during public events such as the March of Dimes or the Crop Walk. And the biggest event that our club organizes is the DeKalb Hamfest in May.
On those occasions it is useful to count things: walkers, so we can be sure nobody got left behind, tickets sold at the hamfest gate, etc. The easy solution would be to buy a few of the handheld counters that increment count on an odometer-like readout with each click of a button. But I don't like easy solutions, and I like to tinker with electronic gadgets. Hence this project.
I used the very simple, cheap ($1.25 or so) but powerful 12F629 flash microprocessor. One of its pins is an output that drives a small beeper salvaged from an old Sun keyboard. A series diode provides some protection from reverse voltage spikes. Another pin is an input, with a 10k pullup resistor to Vdd, connected to a switch that - when shorted - pulls this input down to ground. A 10uF capacitor in parallel with the switch gives some amount of hardware debouncing. One more pin (for convenience the one next to the Vss pin, as explained later) is also pulled up with a 10k resistor, so it's normally at Vdd. The whole thing is powered with a small 3V button cell.
Here is my first prototype. Ugly as sin, but sturdy and cheap. Of course there are many other possibilities. At first I wanted to mount this one inside a surplus computer mouse (I had to make some notches in the circuit board so it would fit, they are apparent on the close-up picture), but I found that the microswitch in that mouse was broken. Besides, I think that a pushbutton design such as a mouse would be too easy to trip accidentally. That's when I settled on the electrical box enclosure which easily houses all the components. By the way, I found that the beeper I had was really soft when driven with a square wave on 3V, but it grew much louder when its opening was covered with something - that's what the piece of Scotch tape is for.
When the switch is closed momentarily, the PIC increments the current count, stores it in the EEPROM so power can be removed without losing it, and emits a short confirmation beep. To keep things simple I just store 5 decimal digits as 5 separate values in the data memory. I could have used 3 digits (I doubt we will ever need to count over 999), or ten, but five sounded like a reasonable choice.
When the switch is left in the on position for about 3 seconds, the current value is read out. In my version, true to the spirit of amateur radio, this is done with Morse code. By the way, the timings and spacing I used are not quite normal and will make CW'ers cringe, but I thought that made it easier to copy even by those not too familiar with Morse. Of course one can easily change this, so digits are represented by some other code of choice.
Zeroing the counter is (intentionally) difficult - one has to take off the faceplate. Then just short the Vss pin and the pin next to it, mentioned above, with a pen, screwdriver, or whatever. Three short confirmation beeps are heard if all goes well.
The chip spends 99.9% of the time in sleep mode, drawing current in the nA range. The (6 years old) button cell I had lying around is showing no discernible voltage drop after two days of playing with the device, so I'm pretty sure a new one will last a long time. And one can use a higher capacity one, such as the 600 mAh Duracell DL2450 or similar.
As with most of my projects, the code is a bit of a mess - it was whipped up in an hour, then some 'unavoidable' bugs were fixed (e.g. I forgot that the analog comparator on pins 0 through 2 was by default enabled, or that I'd better clear the watchdog timer more often), and that was it. I'm even too lazy to suppress the leading zeroes during readout. It surely can be cleaned up and made much more elegant, but - as long as it works - I'm not likely to touch it again. I use lower case for most everything, so make sure to disable case sensitivity in your compiler. You are free to download it, redistribute it with the attribution preserved, use and modify it for non-commercial purposes. But if you make a bundle selling such gadgets, I'm asking for a modest cut! :-) 73