Logic Gates may be used to remove
oscillations or unwanted pulses (bouncing) produced by mechanical
switches and relays during the mechanical switching process. Below
is an
example of a switch debouncing circuit that utilizes NAND gates.

Figure 1. Bounce-free
Mechanical Switching with NAND Gates
Figure 1
shows a circuit that uses two NAND gates to stabilize the output of a
mechanical switch or relay. The output of the circuit as shown
is '0'. Thus, at this point, X1 is '0'.
When the switch is thrown from '0' to '1', the 1.2 k-ohm resistor pulls
up Y1 to '1', but this does not cause the output of NAND A to change,
i.e., it remains to be '1'. Thus X2 is still '1'. However, the switching
action causes Y2 to be pulled to ground, causing the output to
switch from '0' to '1'. This causes X1 to also switch to '1'.
Since at this
point, Y1 is still '1', the output of NAND A switches to '0', which
keeps the output at logic '1'. In effect, the switching action of
the mechanical switch was transformed by the two NAND gates into a clean
digital transition from '0' to '1' at the circuit's output.
Throwing the
mechanical switch back to '0' causes Y1 to go to '0' and Y2 to go to
'1'. This causes the output of NAND A to go to '1' and the output
of the circuit to go to '0' since both X2 and Y2 are now '1'.
Again, the mechanical switching action was transformed by the circuit
into a clean digital transition from '1' to '0'.
See Also:
Logic Gates;
NOR-Based Debouncing Circuit;
555-Based Debouncing Circuit