You are on page 1of 17

COMPUTER ARCHITURE II

DESIGN LABORATORY 1
EMBEDDED C PROGRAMMING & ARDUINO BASICS

JOHN ELMER P. LORETIZO

OBJECTIVES
At the end of the laboratory activities the student should be able to:
Create, modify and debug programs written in Embedded C.
Interface system components to Arduino
Design and create a system using Arduino

ACTIVITY 1
CODES AND SETUPS
1. Write a program to display the sum of the numbers from 1 to 500 to the
serial monitor.
void setup() {
Serial.begin(9600);
long sum;
for(int i = 1; i <= 500; i++) {
sum += i;
}
Serial.println(sum);
}
void loop() {
}

Simulation from circuits.io for Activity 1 Item 1.

2. Write a program to display the first 20 terms of the Fibonacci Series starting
from 0, 1, 1, 2 and so on.
int numbers[20];
void setup() {
Serial.begin(9600);
for(int i = 0; i < 20; i++){
if (i < 2) {
numbers[i] = i;
} else {
numbers[i] = numbers[i-2] + numbers[i-1];
}
}
for(int i = 0; i < 20; i++){
Serial.println(numbers[i]);
}
}
void loop() {
}

Simulation from circuits.io for Activity 1 Item 2.

ACTIVITY 2
BLINKING LIGHTS
1. Explain every instruction on the blink program and explain how does the
program work.
The first 2 lines of code instantiate pin numbers into a
variables of personal choice for easier identification.
The pinMode() method in the setup sets the identified pins as
to what role they are going to take. In this case, the pins are
set to display output.
Inside the loop function, the first two digitalWrite() methods
light up led1 and turns off led 2 and this is in a 1000 ms
delay time followed by the lighting up of led 2 and led 1 is
turned off for another 1000 ms delay time. Algorithms in the
loop function recur infiinitely.

2. How do we select the value of the resistor connected to the LEDs.


The value of the resistor depends upon the voltage required by the LED based
on its color. The following are basic forward voltage at a given 5V source of
LED:
Blue, Green, White, or UV = 3.3V
Red, Yellow, or Yellow-Green = 1.8V
The resistor required can then be computed using the basic principle of V=IR;
wherein V is the volt source, I is the current and R is the resistance. It can also be
noted that the desired current running through LED lights is 25mA.

3. Modify the code, this time use at least 4 LEDs. You are free to program your
own light sequence.
int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;
const int leds[4] = {led1, led2, led3, led4};
void setup(){
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
}
void loop() {
for(int i = 0; i < 4; i++){
digitalWrite(leds[i], HIGH);
delay(500);
}
}

This code sequentially lights the LEDs


with an interval of 500ms.

DESIGN PROBLEM
Design and implement a system that uses any of the following components
below. Explain, what problems are you trying to solve by your design?

ONE DIGIT COUNTDOWN


TIMER WITH RESET BUTTON
The inspiration for this design project are day to day activities that are limited
into specific time allocations like cooking times and exercise times. This design
project illustrates the implementation of such system in a small scale approach
which can then be enhanced later into multiple number of digits.

MATERIALS

Microcontroller

7 Segment Display
(Common Cathode)

Breadboard

Push Button

Connecting Wires

2 220 Ohm Resistors

SCHEMATIC DIAGRAM

BREADBOARD DIAGRAM

int e = 2;
int d = 3;
int g = 4;
int c = 5;
int f = 6;
int a = 7;
int b = 8;
const int segs[7] = { a, b, c, d, e, f, g };
const byte numbers[10] = { 0b1000000, 0b1111001, 0b0100100, 0b10110000, 0b10011001, 0b10010010, 0b0000010, 0b1111000, 0b0000000,
0b10010000 };
void setup() {
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
}
void loop() {
for (int i = 9; i >= 0; i--) {
delay(1000); l
ightSegments(numbers[i]);
}
}
void lightSegments(byte number) {
for (int i = 0; i < 7; i++) {
int bit = bitRead(number, i);
digitalWrite(segs[i], bit);
}
}

ACTUAL OUTPUT

LEARNING EXPERIENCES
During the laboratory, it was also discovered that different LED require
varying values of resistors. Furthermore, this laboratory activity provided us
with the basics of using Arduino including its basic syntax. The use of Arduino
has also opened our minds into its real life applications which can benefit man.

You might also like