Using a pushbutton as a clock

Hi, I was wondering if it is possible to easily use a push-button to act as a TTL-compatible clock for an IC.

For example, I would like to use a counter that will go up by one each time I press a pushbutton. The problem I encountered when I tried to wire the push-button to the clock input of the counter directly is that due to the high rippling and 'roughness' of the push-button's contact, every time I pressed once, the counter would go up several bits.

Is there a relatively easy way (perhaps using a capacitor plus something else) to use a pushbutton or mechanical switch as a clock?

I want to do this because I don't want to use the cpu of the arduino to constantly monitor the switch and then send the signal to the counter.

Is the button plugged into the Digital or the Analog In Pin?

Try adding some form of signal smoothing

Here's an article on the Arduino playground.

http://www.arduino.cc/playground/Main/Smooth

Thanks lilpunk, smoothing is indeed what I envision to do.

I think I was a bit unclear though... what I want to do is to control the IC without the arduino.
I need some sort of hardware smoothing coupled with a compressor to convert the button's rippled signal to a clean square signal without the use of software. Some kind of hardware debounce.

I actually have 2 projects that would need this kind of stuff. One of them is reading a rotary encoder.
The other one involves a bike speedometer working off a magnetic switch - here my arduino won't be available for constant value polling, that's why I want to record the clicks on a counter.

If you can figure out the period of the bouncing, you can send the pushbutton output through a low-pass (RC) filter with a similar time constant, then use this filtered signal as your clock input.

  • Ben

You can use a simple circuit based on a 555 timer IC to debounce the switch. This gives you a very stable pulse out when you press the switch. The length of the pulse can be configured based on the components used.

Check this:

http://www.freeinfosociety.com/electronics/schemview.php?id=1624

many other examples are floating around the net, just google "555 debounce" or "debounce switch"

The definitive paper on debouncing (both hardware and software) is
this: Debouncing Contacts and Switches

It shows you how to use an RC filter, for example. Plus many other solutions.

If an RC filter will do the trick it's of course much easier than the 555 timer circuit.

Thanks guys!
Cool, as a matter of fact I have a 556 lie around somewhere under a pile of electronics :).
The RC looks even easier, even though I will have to check for the right resistor and capacitor values to use.

Handi