Anda di halaman 1dari 6

CS 11/Group_4_Borromeo,Galanida,Pabilan,Paypa,Tejero

Lab 4
LED LIGHTING USING PUSH BUTTON

INTRODUCTION

The pushbutton is a component that connects two points in a circuit when you press it. The example
turns on an LED when you press the button.

In this activity, we connect two wires to the Arduino and bread board from the two legs of pushbutton.
The black jumper wire goes from the corresponding leg of the pushbutton to the negative trail of the
breadboard while the orange jumper wire is connected to a digital i/o pin which reads the button's
state.

OBJECTIVES

1. To light an LED using push buttons as switches and Arduino IDE


2. To execute blinking and fading effect on the LEDs controlled by buttons
3. To familiarize the codes for button sketch

MATERIALS

• Arduino UNO board with USB cable


• 10 LEDs (9 red, 1 yellow)
• 10 Resistors (270Ω)
• 13 Jumper wires
• 1 pushbutton
• long breadboard
• laptop

PROCEDURES

1. Insert the 10 LEDs


CS 11/Group_4_Borromeo,Galanida,Pabilan,Paypa,Tejero

2. Connect the 270-ohm resistors below the cathode pins of the 10 LEDs.
The breadboard has signs for positive (power) and negative (ground) connections. Place the
resistors on the breadboard, with one leg on the negative column (gnd) of the breadboard and
the other leg in a different hole located somewhere else on the breadboard as shown in the
diagram below.

3. Insert the pushbutton to the breadboard.

4. Connect the 10 jumper wires to the anode pins of the LEDs and two jumper wires to the
pushbutton.
5. From the LEDs, plug in the 10 jumper wires to the Arduino UNO board in digital I/O pin
number 3,4,5,6,7,8,9,10,11 and 12.
6. From the pushbutton, plug in the jumper wire to the digital I/O pin number 2 while the other
one, connect to the negative trail of the breadboard.
7. Connect a black jumper wire from GND to the Arduino UNO board.
CS 11/Group_4_Borromeo,Galanida,Pabilan,Paypa,Tejero

8. Open up the Arduino IDE.


9. Program the Arduino UNO.
Encode or copy then edit the code for this section.

10. Plug the Arduino UNO board into the laptop with a USB cable.
11. Upload onto board.
Make sure the serial port is set. In this case, COM4 and the correct board is selected,
that is Arduino UNO is selected from the dropdown menu at the top left corner of the
Arduino application. Then upload the code unto the board by clicking upload at the top left
corner.
12. Monitor the Arduino board and the circuit.
13. Press the push button and see how LEDs react.

RESULTS AND DISCUSSION

Here is the code of blinking LEDs that we encode in the sketch:

int buttonPin = 2;
int ledPin1 = 3;
int ledPin2 = 4;
int ledPin3 = 5;
int ledPin4 = 6;
int ledPin5 = 7;
int ledPin6 = 8;
int ledPin7 = 9;
int ledPin8 = 10;
int ledPin9 = 11;
int ledPin10 = 12;
int buttonState = 0;

void setup() {
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
CS 11/Group_4_Borromeo,Galanida,Pabilan,Paypa,Tejero

pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPin7, OUTPUT);
pinMode(ledPin8, OUTPUT);
pinMode(ledPin9, OUTPUT);
pinMode(ledPin10, OUTPUT);
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH);
}
void loop() {
buttonState=digitalRead(buttonPin);

if (buttonState==HIGH) {
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);
digitalWrite(ledPin6, LOW);
digitalWrite(ledPin7, LOW);
digitalWrite(ledPin8, LOW);
digitalWrite(ledPin9, LOW);
digitalWrite(ledPin10, LOW);
}

else {
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
CS 11/Group_4_Borromeo,Galanida,Pabilan,Paypa,Tejero

digitalWrite(ledPin5, HIGH);
digitalWrite(ledPin6, HIGH);
digitalWrite(ledPin7, HIGH);
digitalWrite(ledPin8, HIGH);
digitalWrite(ledPin9, HIGH);
digitalWrite(ledPin10, HIGH);
}
}
CS 11/Group_4_Borromeo,Galanida,Pabilan,Paypa,Tejero

DOCUMENTATION

Anda mungkin juga menyukai