Вы находитесь на странице: 1из 6

De La Salle University – Dasmarinas

College of Engineering, Architecture, and Technology

Digital Input and Output

Experiment # 2

Submitted By:
Kyle Janssen M. Villanueva
ECE41

Date Submitted:
September 20, 2018

Engr. Klarenz Pantaleon

Instructor
I. Introduction

The pins on the Arduino can be configured as either inputs or outputs. The pins is one of
the determinants on how the circuit connected to it will work. The configurations that are
available to the pins of Arduino shall tackled in this experiment. The function and concept of
pull-up and pull-down resistors will also be determined in this experiment.

II. Result / Data gathered

• Procedure

1. Connect an LED on pin 2,3,4,5 and 6


2. Connect a button on pin 8.
3. Create a source code with the following specifications.
a. All LED must be OFF at start.
b. For every button press, the LED with ON state will move to the next pin, and the
previous LED will turn OFF.
c. The button must be wait 50ms before accepting a valid input.
d. When the last pin is reached, it will go back to the first LED.
4. What if the pull-up resistor is changed to pull-down resistor? Describe the
behavior of the LED.
5. Create a source code with the following specification.
a. Waits for a button input before running the sequence.
b. After a button input, a running LED sequence from left to right will be displayed
with delay of 1 second per shift.
c. The button must be wait 50ms before accepting a valid input.
d. Every cycle the delay between the LED shift, will be increased by 1 second.
e. After 5 cycle. the program will stop and waits for button input again.
• Data / Source Code

• Automatic

void setup() {

Serial.begin (9600);

pinMode(8, INPUT_PULLUP);

pinMode(2, OUTPUT);

pinMode(3, OUTPUT);

pinMode(4, OUTPUT);

pinMode(5, OUTPUT);

pinMode(6, OUTPUT);

void loop() {

int a = 0;

int b = 0;

int c = 1000;

int i;

int x;

d:

if (digitalRead(8)) {

digitalWrite(a, LOW);

} else {

e:

for (x = 0; x < 5; x++) {

if (a == 0) {

a = 2;

}
else {

a++;

Serial.println("ON");

digitalWrite(a, HIGH);

delay(c);

Serial.println("OFF");

digitalWrite(a, LOW);

if (b == 4) {

c = 1000;

a = 0;

goto d;

else {

c = c + 1000;

a = 0;

b++;

goto e;

}
• Manual

void setup() {

Serial.begin(9600);

int a;

a=2;

pinMode(8, INPUT_PULLUP);

pinMode(2,OUTPUT);

pinMode(3,OUTPUT);

pinMode(4,OUTPUT);

pinMode(5,OUTPUT);

pinMode(6,OUTPUT);

int b=0;

void loop() {

if(digitalRead(8)) {

} else {

digitalWrite(b,LOW);

if(b==0) {

b=2;

} else{

b++;

if(b>6) {

b=0; }

delay(500); }

digitalWrite(b,HIGH); }
III. Observation

In this experiment that we conducted, it is observed that the code “INPUT_PULLUP” has
the default value for the input which is HIGH, unless it is changed in the state of LOW
pressing the “push to break” button included in the circuit. The use of digital input is for the
program to determine how will it handle the high and low output of the source code. We tried
to change the INPUT_PULLUP into INPUT_PULLDOWN for us to be able to observe what
will be the difference in the output that it is producing. It is observed that the difference
between the two is that with an INPUT_PULLUP the state will stay ON if the button
provided is not pressed, but will produce a state that is OFF if the button is pressed. While in
INPUT_PULLDOWN, the state will remain OFF if the button provided is not pressed, but
will produce an ON state if the button is to be pressed.

IV. Conclusion

This experiment shows the importance of how will one decide what digital input shall be
encoded, either INPUT_PULLUP or INPUT_PULLDOWN. Also, this experiment explained
how pullup and pulldown resistors work and how they function inside an Arduino circuit. The
main difference of pull up and pulldown resistor is that the pullup function is originally ON
even if you don’t press any buttons and turns into an OFF state if one pressed the button,
while pull down resistor work in vice versa.

Вам также может понравиться