0% found this document useful (0 votes)
82 views

Laboratory Experiment 3

This document provides instructions and code examples for two laboratory exercises using Arduino to control LEDs with push buttons. Exercise 1 demonstrates using a push button to turn an LED on and off. It involves setting the button as an input, writing high to activate the internal pull-up resistor, and writing high to the output pin to light the LED when the button is pressed. Exercise 2 shows changing an LED's brightness with two push buttons. It can be done by changing the resistor size or using pulse-width modulation to rapidly turn the LED on and off. The code example uses analogWrite to set the LED brightness from 0-255 based on button presses. The activity asks students to modify the

Uploaded by

joshua paliza
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

Laboratory Experiment 3

This document provides instructions and code examples for two laboratory exercises using Arduino to control LEDs with push buttons. Exercise 1 demonstrates using a push button to turn an LED on and off. It involves setting the button as an input, writing high to activate the internal pull-up resistor, and writing high to the output pin to light the LED when the button is pressed. Exercise 2 shows changing an LED's brightness with two push buttons. It can be done by changing the resistor size or using pulse-width modulation to rapidly turn the LED on and off. The code example uses analogWrite to set the LED brightness from 0-255 based on button presses. The activity asks students to modify the

Uploaded by

joshua paliza
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Laboratory Experiment 3

COE 5
INPUTS

Push Buttons
Potentiometers

Light Dependent Resistors (LDR)


Push Buttons
Most common type of pushbutton are called “normally open” (NO).
There is a less common type called “normally closed” (NC) that is
closed (connected) when not pushed and open when pushed..

symbol (NO)
Exercise 1: Button-Led Circuit 1
 The purpose of the Button-Led Circuit 1 is to demo how Arduino
will be controlling an LED via pushbutton.
Exercise 1: Button-Led Circuit 1
Write the sketch below and verify the result.

setup the button Pin as INPUT

write HIGH to the INPUT pin

sets up the pin to be OUTPUT

write HIGH out when the value read


from the pin connected to the button
is LOW. (to light the LED when the
button is pressed)
Exercise 1: Button-Led Circuit 1
Writing HIGH to the INPUT pin - Activating internal pull-up resistors

For electricity to flow, a complete circuit from the power to ground shall be
established by the push button.
Exercise 2: Button-Led Circuit 2
 The purpose of the Button-Led Circuit 2 is to demo how Arduino
can change the brightness of an LED via two pushbuttons.
Exercise 2: Button-Led Circuit 2
Two ways to change the brightness of an LED

 Change the amount of current going through the LED by changing


the size of the resistor.

 Turn the LED on and OFF faster or slower

“The more time that the LED is on in a given period of time, the
“brighter” it will appear
Exercise 2: Button-Led Circuit 2
PWM – Pulse Width Modulator

 Arduino supports PWM on certain pins (3, 4,5,9,10 and 11) at


500Hz.
 One can analogWrite() a value between 0 and 255.(never and
always 5V)
 A PWM output that is ON half the time is said to have a duty cycle
(ratio of“ON” time to total time) of 50%.
Exercise 2: Button-Led Circuit 2- Sample Program

guarantees the value of LED


Brightness will be between 0 and 255
(including 0 and 255)

uses analogWrite to perform PWM


Should be kept small ! on that pin with the set value.
Activity
1. Modify the sketch of exercise 1 so that the LED is normally on and
pressing the button turns it OFF

2. Upload the sketch of exercise 2 verify the result. What happens if both
pushbuttons are pressed? Why?

Include comments in your program codes to explain/dissect the overall


program.
Have your work checked by your lab professor…..
Yours Program Codes Here!

(paste your program codes here)


Observations and Conclusions

(one/two pager only)


References

Arduino Cookbook
Recipes to Begin, Expand, and Enhance Your Projects
By Michael Margolis

Introduction to Arduino
by Alan G. Smith

Arduino On Line Courses

You might also like