Fow Seng Joe (B1757) - LAB 4-Arduino (LED Binary Counter)
Fow Seng Joe (B1757) - LAB 4-Arduino (LED Binary Counter)
1
Laboratory Report Feedback Form
Introduction to Microprocessor
Criteria Q1 Q2 Q3 Q4 Total
Lab 4 –
/5 /5 /10 /5 /25
Part 2
Discussion
and /5
Conclusion
Marks:
/30
General Comments:
2
General Instructions
Use the following format for the preparation of the laboratory report submission.
• Paper size: A4
• Number all pages sequentially
• Number all Figures and Tables sequentially and refer them in the text
WARNING
• Laboratory report submitted after the due date will be considered late.
• Laboratory report submitted not later than two weeks after the due date will be
marked, but the marks will be capped to a maximum of 40%.
• Laboratory report submitted later than two weeks will be marked, but carry zero
marks.
• First City University College takes allegations of plagiarism very seriously.
Submissions involving plagiarism will be marked, but given zero marks. Plagiarism is
the attempt to pass off the work of another as your own. Information taken from the
work of others should be acknowledged by reference to obviate the charge of
copying.
• Collusion is an academic irregularity within the First City University College
assessment regulations. Any student found colluding in the production of any
assessment will be subject to an investigation with the imposition of any penalty
deemed appropriate. Students must ensure they are familiar with the definition of
collusion.
Submission Requirements
Your answers should include theoretical calculations, simulation results, graphs and
discussions. Please submit your laboratory report along with the attached cover sheet
and assignment feedback form latest on the specified date.
Assessment
Learning Outcomes
Question
Design digital logic circuit using standard logic
CLO1
gates.
Describe the operation of a microprocessor-based
CLO2 Lab 4
system.
Create simple microprocessor’s interfacing circuit
CLO3 Lab 4
using simple peripherals.
3
Write simple programs using microprocessor’s
CLO4 Lab 4
software development process.
4
BME2007 – Introduction to Microprocessor (ITM)
LABORATORY 4: Arduino (LED Binary Counter)
Objectives:
To build an LED Binary Counter that counting UP with some delays using Arduino.
Equipments:
You need the following equipment or item to execute this Lab 4:
(a) A Personal Computer with Arduino IDE software
(b) Arduino UNO board
(c) Four (4) Light-emitting diodes (LEDs)
Part 1:
Below is the example of code to build an LED Binary Counter that count from 0 to 3
with interval delay of 1 second using Arduino.
5
digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);
delay(waittime);
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
delay(waittime);
}
Example of circuit with Arduino with 3 LEDs:
6
Part 2:
Modify the code and circuit consruction in Part 1 to build an LED Binary Counter that
count from 0 to 15 with interval delay of 2 seconds using Arduino, and answer all the
following questions.
7
Question 1: (5 marks)
Shows a table that convert Decimal to Binary (from 0 to 15)
1 2 3 4 Decimal
0 0 0 0 0
0 0 0 1 1
0 0 1 0 2
0 0 1 1 3
0 1 0 0 4
0 1 0 1 5
0 1 1 0 6
0 1 1 1 7
1 0 0 0 8
1 0 0 1 9
1 0 1 0 10
1 0 1 1 11
1 1 0 0 12
1 1 0 1 13
1 1 1 0 14
1 1 1 1 15
Question 2: (5 marks)
1. Construct the circuit physically by using four (4) LED’s to represent the counting
UP from 0 to 15 operation.
8
2. Identify the pin number that is connected to the Arduino UNO board for each
respective LED.
• LED 1 =Pin number 4
• LED 2 =Pin number 3
• LED 3 =Pin number 2
• LED 4 =Pin number 1
9
delay(2000);
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,HIGH);
digitalWrite(led4,LOW);
delay(2000);
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,HIGH);
digitalWrite(led4,HIGH);
delay(2000);
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,HIGH);
digitalWrite(led4,HIGH);
delay(2000);
digitalWrite(led1,LOW);
digitalWrite(led2,HIGH);
digitalWrite(led3,LOW);
digitalWrite(led4,LOW);
delay(2000);
digitalWrite(led1,LOW);
digitalWrite(led2,HIGH);
digitalWrite(led3,LOW);
digitalWrite(led4,HIGH);
delay(2000);
digitalWrite(led1,LOW);
digitalWrite(led2,HIGH);
digitalWrite(led3,LOW);
digitalWrite(led4,HIGH);
delay(2000);
10
digitalWrite(led1,LOW);
digitalWrite(led2,HIGH);
digitalWrite(led3,HIGH);
digitalWrite(led4,LOW);
delay(2000);
digitalWrite(led1,LOW);
digitalWrite(led2,HIGH);
digitalWrite(led3,HIGH);
digitalWrite(led4,HIGH);
delay(2000);
digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
digitalWrite(led4,LOW);
delay(2000);
digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
digitalWrite(led4,HIGH);
delay(2000);
digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);
digitalWrite(led3,HIGH);
digitalWrite(led4,LOW);
delay(2000);
digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);
digitalWrite(led3,HIGH);
digitalWrite(led4,HIGH);
delay(2000);
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led3,LOW);
11
digitalWrite(led4,LOW);
delay(2000);
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led3,LOW);
digitalWrite(led4,HIGH);
delay(2000);
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led3,HIGH);
digitalWrite(led4,LOW);
delay(2000);
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led3,HIGH);
digitalWrite(led4,HIGH);
delay(2000);
2. Shows the code, analyze, and discuss line by line of the provided code.
Code Explanation
int led1=4; The integer variables declare led1, led2,
int led2=3; led3, and led4, representing the pin
int led3=2; numbers for four LEDs, and waittime,
int led4=1; representing the delay time in
int waittime=2000; milliseconds.
void setup() { In setup() function, you set each LED pin
// put your setup code here, to run once: as an output using the pinMode function.
pinMode(led1,OUTPUT); This function configures the specified pin
12
pinMode(led2,OUTPUT); to behave either as an input or an output.
pinMode(led3,OUTPUT);
pinMode(led4,OUTPUT);
}
void loop() { This section turns off all four LEDs and
// put your main code here, to run then introduces a delay specified by
repeatedly waittime milliseconds.
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
digitalWrite(led4,LOW);
delay(waittime);
digitalWrite(led1,HIGH); This part of the code turns on all four
digitalWrite(led2,HIGH); LEDs simultaneously and then
digitalWrite(led3,HIGH); introduces a delay specified by the
digitalWrite(led4,HIGH); variable waittime. During this delay, all
delay(waittime); LEDs will remain in the HIGH state
13
Question 4: (5 marks)
Capture the results and attach here as a proof.
Code Proof
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
digitalWrite(led4,LOW);
delay(2000);
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH;
digitalWrite(led3,HIGH);
digitalWrite(led4,HIGH);
delay(2000);
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH;
digitalWrite(led3,LOW);
digitalWrite(led4,LOW);
delay(2000);
digitalWrite(led1,LOW);
digitalWrite(led2,HIGH);
digitalWrite(led3,HIGH);
digitalWrite(led4,HIGH);
delay(2000);
14
digitalWrite(led1,LOW);
digitalWrite(led2,HIGH);
digitalWrite(led3,LOW);
digitalWrite(led4,HIGH);
delay(2000);
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
digitalWrite(led4,HIGH);
delay(2000);
Discussion
In this laboratory use 4 LED light because it can produce maximum number of decimals so
that convert binary to decimal from 0 to 15 can increase the number of leds.
Conclusion
In conclusion, increase the decimal numbers represented using leds can cause the LEDS to
blink according somewhat similar to morse code [1].
15