Académique Documents
Professionnel Documents
Culture Documents
Lab Report # 4:
Turn on LED when the button is pressed
and keep it on after it is released.
Objectives:
i. To make C program for Turning on LED when the button is pressed and keep it on after
it is released.
ii. Testing the circuit on Proteus
iii. Making the circuit on Bread Board.
De-Bouncing:
Pushbuttons are very simple devices: two bits of metal kept apart by a spring. When you press
the button, the two contacts come to gather, and electricity can flow. This sounds fine and simple,
but in real life the connection is not that perfect, especially when the button is not completely
pressed, and it generates some spurious signals called bouncing.
When the pushbutton is bouncing, the Arduino sees a very rapid sequence of on and off
signals. There are many techniques developed to do de-bouncing, but in this simple piece of
code, that it’s usually enough to add a 10- to 50-millisecond delay when the code detects a
transition.
C program:
//Turn on LED when the button is pressed
// pushbutton is connected
// value of "val"
void setup() {
void loop(){
state = 1 - state;
delay(10);
if (state == 1) {
} else {
digitalWrite(LED, LOW);
PAGE 2
POWER PLANT LAB ME-306(L)
DEPARTMENT OF MECHANICAL ENGINEERING
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, PESHAWAR
Proteus Circuit:
Picture of Circuit:
Bar Code:
PAGE 3