Digielecs 2 Lab Experiment 2

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Don Honorio Ventura State

University
College of Engineering and Architecture
Electronics Engineering Department
Villa de Bacolor, Pampanga

NAME OF STUDENT:
GROUP NUMBER: 11 DATE PERFORMED: 3/6/23
COURSE CODE: ELECS 3 DATE SUBMITTED:3/14/23
COURSE TITLE: Digital Electronics 2 Lab YEAR AND SECTION: ECE – 3A
LAB. INSTRUCTOR: Engr. Enmar T. Tuazon GRADE:

LABORATORY EXPERIMENT NO. 2


INTERFACING LED’S ON A MICROCONTROLLER

OBJECTIVE
1. Interfacing output devices on Arduino.
2. Utilizing functions

DISCUSSION

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.
INSTRUMENTS AND MATERIALS:
- Laptop
- Arduino Development Board
- Breadboard
- Connecting Wires
- 10pcs LED’s any color
- 10pcs 100-200 ohm’s Limiting Resistors

PROCEDURE:

Example #1: This simple program makes a LED


connected to pin 13 blink.

Example #2: Running Lights using digitalWrite

Connection Diagram

const int ledRed = 11; pinMode(ledRed, OUTPUT);


const int ledGreen = 10; pinMode(ledGreen, OUTPUT);
const int ledYellow = 9; pinMode(ledYellow, OUTPUT);
void setup(){ }
void loop() delay(200);
{ digitalWrite(ledRed, LOW);
digitalWrite(ledRed, HIGH); digitalWrite(ledGreen, HIGH);
digitalWrite(ledGreen, LOW); digitalWrite(ledYellow, LOW);
digitalWrite(ledYellow, LOW); delay(200);
delay(200);
digitalWrite(ledRed, LOW);
digitalWrite(ledGreen, HIGH); digitalWrite(ledRed, HIGH);
digitalWrite(ledYellow, LOW); digitalWrite(ledGreen, LOW);
delay(200); digitalWrite(ledYellow, LOW);
digitalWrite(ledRed, LOW); delay(200);
digitalWrite(ledGreen, LOW); }
digitalWrite(ledYellow,
HIGH);

Example#3: Running Light using boolean

Connection Diagram

boolean ece = true;


int cea = 12;
void setup()
{
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
pinMode(10,OUTPUT);
pinMode(9,OUTPUT);
pinMode(8,OUTPUT);
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);
pinMode(5,OUTPUT);
pinMode(4,OUTPUT);
}
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;
}
if(cea > 12)
{
cea= 11;
ece = true;
}
}

Example#4: Using For Loop

Connection Diagram
int timer = 100;

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

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

// loop from the highest pin to the lowest:


for (int ece = 7; ece >= 2; ece--) {
// turn the pin on:
digitalWrite(ece, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ece, LOW);
}
}

ACTIVITY

Given: 8 pcs of LED


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 an additional of 2s delay to turn on is being added to each LED.
After the last LED turn on, they will turn off individually starting from the last LED with a delay
of 500 ms for 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
DISCUSSIONS:

OBSERVATIONS:
PHOTODOCUMENTATIONS:

Sequence 1:

Sequence 2:
Sequence 3:

CONCLUSION:

REFERENCES:
CODES:

Sequence 1:
const int ledWhite = 11;
const int ledGreen = 10;
const int ledYellow = 9;
const int ledRed = 8;
const int ledBlue = 7;
const int ledWhite2 = 6;
const int ledGreen2 = 5;
const int ledYellow2 = 4;

void setup(){

pinMode(ledWhite, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(ledYellow, OUTPUT);
pinMode(ledRed, OUTPUT);
pinMode(ledBlue, OUTPUT);
pinMode(ledWhite2, OUTPUT);
pinMode(ledGreen2, OUTPUT);
pinMode(ledYellow2, OUTPUT);
}

void loop()
{
digitalWrite(ledWhite, HIGH);
delay(2000);

digitalWrite(ledGreen, HIGH);
delay(2000);

digitalWrite(ledYellow, HIGH);
delay(2000);

digitalWrite(ledRed, HIGH);
delay(2000);

digitalWrite(ledBlue, HIGH);
delay(2000);

digitalWrite(ledWhite2, HIGH);
delay(2000);

digitalWrite(ledGreen2, HIGH);
delay(2000);

digitalWrite(ledYellow2, HIGH);
delay(500);

digitalWrite(ledYellow2, LOW);
delay(500);

digitalWrite(ledGreen2, LOW);
delay(500);

digitalWrite(ledWhite2, LOW);
delay(500);

digitalWrite(ledBlue, LOW);
delay(500);

digitalWrite(ledRed, LOW);
delay(500);

digitalWrite(ledYellow, LOW);
delay(500);

digitalWrite(ledGreen, LOW);
delay(500);

digitalWrite(ledWhite, LOW);
delay(2000);

Sequence 2:
const int LED1 = 4;
const int LED2 = 5;
const int LED3 = 6;
const int LED4 = 7;
const int LED5 = 8;
const int LED6 = 9;
const int LED7 = 10;
const int LED8 = 11;
int Repeat = 0;

void setup() {
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
pinMode(LED4,OUTPUT);
pinMode(LED5,OUTPUT);
pinMode(LED6,OUTPUT);
pinMode(LED7,OUTPUT);
pinMode(LED8,OUTPUT);
}
void loop(){
if(Repeat<3) {
digitalWrite(LED2, HIGH);
digitalWrite(LED4, HIGH); A
digitalWrite(LED6, HIGH);
digitalWrite(LED8, HIGH);
delay(2000);

digitalWrite(LED2, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED8, LOW);
digitalWrite(LED1, HIGH);
digitalWrite(LED3, HIGH);
digitalWrite(LED5, HIGH);
digitalWrite(LED7, HIGH);
delay(2000);

digitalWrite(LED1, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED7, LOW);
Repeat = Repeat + 1;
}
}

Sequence 3:

void setup()
{
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
}

void loop()
{

for(byte i=0;i<255;i++)
{ byte v=i%2;
byte j=i/2 %2;
byte a=i/4 %2;
byte y=i/8 %2;
byte d=i/16 %2;
byte u=i/32 %2;
byte k=i/64 %2;
byte s=i/128 %2;

digitalWrite(4,v);
digitalWrite(5,j);
digitalWrite(6,a);
digitalWrite(7,y);
digitalWrite(8,d);
digitalWrite(9,u);
digitalWrite(10,k);
digitalWrite(11,s);

delay(200);
}
}

You might also like