Laboratory Experiment 3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 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