0% found this document useful (0 votes)
52 views6 pages

DigiELECS 2 Lab Act 2

The document provides examples of using LEDs and Arduino. It includes 5 examples: 1) Blinking an LED; 2) Running light using a boolean; 3) Running lights using digitalWrite; 4) Using a for loop to control pins; 5) An LED controlled by a pushbutton. It also presents 2 problems: 1) Controlling 8 LEDs in 3 sequences; 2) Controlling the LED sequences using 3 pushbuttons. The document shows how to declare pins, write programs, and control LEDs through coding on an Arduino board.

Uploaded by

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

DigiELECS 2 Lab Act 2

The document provides examples of using LEDs and Arduino. It includes 5 examples: 1) Blinking an LED; 2) Running light using a boolean; 3) Running lights using digitalWrite; 4) Using a for loop to control pins; 5) An LED controlled by a pushbutton. It also presents 2 problems: 1) Controlling 8 LEDs in 3 sequences; 2) Controlling the LED sequences using 3 pushbuttons. The document shows how to declare pins, write programs, and control LEDs through coding on an Arduino board.

Uploaded by

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

Activity #2 Interfacing LED

Name: Date:

Rating:

Introduction

Arduino is a single-board microcontroller to make using electronics in multidisciplinary projects more


accessible. The hardware consists of a simple open source hardware board designed around an 8-bit
Atmel AVR microcontroller, or a 32-bit Atmel ARM. The software consists of a standard programming
language compiler and a boot loader that executes on the microcontroller.

Example #1: This simple program makes a LED connected to pin 13 blink.
Example#2: Running Light using boolean

Schematic Diagram

void loop()
{
digitalWrite(cea,HIGH);
delay(50);
digitalWrite(cea,LOW);
if(ece == true)
{
cea = cea - 1;
}
else
{
cea = cea + 1;
}
if(cea < 4)
{
cea = 5;
ece = false;
boolean ece = true;
}
int cea = 12;
if(cea > 12)
void setup()
{
{
cea= 11;
pinMode(12,OUTPUT);
ece = true;
pinMode(11,OUTPUT);
}
pinMode(10,OUTPUT);
pinMode(9,OUTPUT); }
pinMode(8,OUTPUT);
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);
pinMode(5,OUTPUT);
pinMode(4,OUTPUT);
}
Example#3: Running Lights using digitalWrite

const int ledRed = 11; digitalWrite(ledRed, HIGH);

const int ledGreen = 10; digitalWrite(ledGreen, LOW);

const int ledYellow = 9; digitalWrite(ledYellow, LOW);

void setup(){ delay(200);

pinMode(ledRed, OUTPUT); }

pinMode(ledGreen, OUTPUT); Example#4: Using For Loop

pinMode(ledYellow, OUTPUT); int timer = 100;

} void setup() {
// use a for loop to initialize each pin as an
void loop()
output:
{ for (int ece = 2; ece < 8; ece++) {
pinMode(ece, OUTPUT);
digitalWrite(ledRed, HIGH);
}
digitalWrite(ledGreen, LOW); }

digitalWrite(ledYellow, LOW); void loop() {


delay(200); // loop from the lowest pin to the highest:
for (int ece = 2; ece < 8; ece++) {
digitalWrite(ledRed, LOW); // turn the pin on:
digitalWrite(ledGreen, HIGH); digitalWrite(ece, HIGH);
delay(timer);
digitalWrite(ledYellow, LOW); // turn the pin off:
digitalWrite(ece, LOW);
delay(200);
}
digitalWrite(ledRed, LOW);

digitalWrite(ledGreen, LOW); // loop from the highest pin to the lowest:


for (int ece = 7; ece >= 2; ece--) {
digitalWrite(ledYellow, HIGH);
// turn the pin on:
delay(200); digitalWrite(ece, HIGH);
delay(timer);
digitalWrite(ledRed, LOW); // turn the pin off:
digitalWrite(ledGreen, HIGH); digitalWrite(ece, LOW);
}
digitalWrite(ledYellow, LOW);
}
delay(200);
Example#5: LED with Pushbutton

int pinButton = 8;

int LED = 2;

void setup() {

pinMode(pinButton, INPUT);

pinMode(LED, OUTPUT);

void loop() {

int stateButton = digitalRead(pinButton);

if(stateButton == 1) {

digitalWrite(LED, HIGH);

} else {

digitalWrite(LED, LOW);

}
Problem #1:

1. Given: 8 pcs of LED


100-ohm resistor
Arduino UNO
Breadboard
Wires

Condition:

Provide a program that will run the following sequence:

Sequence 1:

• Once the power has been plug, it will have a delay of 2s to turn on the first LED. After 2s, the
first LED will turn on and won’t turn off. After 4s after the power has been plug, the second
LED will turn on and also won’t turn off. The third LED will turn on after 6s until the last LED
has been reached, and additional of 2s delay to turn on is being add in each LED.
• After the last LED turn on, they will turn off individually starting from the last LED with a delay
of 500 ms each interval.

Sequence 2:

• LED # 2,4,6,8 will turn on for 2s and turn off. Without delay, the remaining LED will turn on
for the same delay. This sequence will repeat 3 times.

Sequence 3:

• Binary Counting starting from 0 to 256

Problem #2:

1. Given: 8 pcs of LED


100-ohm resistor
Arduino UNO
Breadboard
Wires
3 Push button

Condition:

• When the first button is pressed, the first condition of the led will run. When the 2 nd
button is pressed, the first sequence will stop, and the 2 nd sequence of led will run and
when the last button is pressed, the last sequence will run.

Note:

Utilize variables for all declarations.


Introduction:

Observation:

Conclusion:

References:

You might also like