Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Lab No.

5: Switch Debouncing
1. Objectives
After successfully completing this lab, students should be able to:
a. Interface a pushbutton switch to a microcontroller
b. Learn about debouncing button presses
c. Debug a given program

2. Required Material
1. Arduino UNO board
2. USB Cable
3. Breadboard
4. Power Supply
5. Computer with Atmel Studio 7 and Programmer Utility installed
6. Push Button
7. LED

3. Background
Due to the mechanical nature of pushbuttons, they often generate spurious open/close transitions
when pressed. For a microcontroller that performs operations millions of times per second, these
transitions may be read as multiple presses in a very short time resulting in wrong input to the
program. This lab demonstrates how to debounce the button presses in software. Hardware solutions
also exist.

4. Procedure
a. Select a pushbutton and insert it into a section of the breadboard.
Figure 2

b. Build the schematic diagram shown in Figure 2 both in Proteus and on breadboard.

Figure 3

c. Start a new C/C++ project in Atmel Studio and type in the following code. Compile it (making
sure there are no errors) and then download the resulting HEX file to the microcontroller.
d. Simulate the whole project in Proteus and blink an LED (turn ON) connected to PINB5 when the
button is pressed. According to the code, the LED will be OFF when you are not pushing the button,
and ON when you press the button (see Figures 3 and 4).

Figure 4
Figure 5

e. Show a working demon of the circuit task on a breadboard.


f. The following code will debounce the button press. Try it downloading it to the microcontroller.

g. Change the program such that the LED toggles i.e., on every button press, the LED turns ON if it
was previously OFF, and turns OFF if it was ON.

You might also like