0% found this document useful (0 votes)
407 views3 pages

Lab # 4 Push Button Mechatronics

The document describes an experiment to create a circuit using an Arduino that turns on an LED when a button is pressed and keeps it on after the button is released. It includes the objectives, an explanation of debouncing buttons, the C code used, a description of the Proteus circuit simulation, and a picture of the circuit. The code uses variables to track the button state and LED state, introduces a delay to debounce the button, and toggles the LED state each time the button transition is detected.

Uploaded by

jawad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
407 views3 pages

Lab # 4 Push Button Mechatronics

The document describes an experiment to create a circuit using an Arduino that turns on an LED when a button is pressed and keeps it on after the button is released. It includes the objectives, an explanation of debouncing buttons, the C code used, a description of the Proteus circuit simulation, and a picture of the circuit. The code uses variables to track the button state and LED state, introduces a delay to debounce the button, and toggles the LED state each time the button transition is detected.

Uploaded by

jawad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

POWER PLANT LAB ME-306(L)

DEPARTMENT OF MECHANICAL ENGINEERING


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, PESHAWAR

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

// and keep it on after it is released

// including simple de-bouncing

// Now with another new and improved formula!!

const int LED = 13; // the pin for the LED

const int BUTTON = 7; // the input pin where the

FRIDAY, MARCH 16, 2018


POWER PLANT LAB ME-306(L)
DEPARTMENT OF MECHANICAL ENGINEERING
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, PESHAWAR

// pushbutton is connected

int val = 0; // val will be used to store the state

// of the input pin

int old_val = 0; // this variable stores the previous

// value of "val"

int state = 0; // 0 = LED off and 1 = LED on

void setup() {

pinMode(LED, OUTPUT); // tell Arduino LED is an output

pinMode(BUTTON, INPUT); // and BUTTON is an input

void loop(){

val = digitalRead(BUTTON); // read input value and store it

// check if there was a transition

if ((val == HIGH) && (old_val == LOW)){

state = 1 - state;

delay(10);

old_val = val; // val is now old, let's store it

if (state == 1) {

digitalWrite(LED, HIGH); // turn LED ON

} 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

You might also like