0% found this document useful (0 votes)
24 views26 pages

Mpi L

The document provides information about a lab report for a Microprocessor and Interfacing course. It includes the course code, credit hours, semester, instructor details, lab objectives, learning outcomes, a complex engineering activity involving a semester project, the relationship between assessments and learning outcomes, and the grading policy. The lab aims to develop skills in Arduino programming, interfacing hardware modules, designing systems, simulation software, and troubleshooting. Students will be assessed based on a lab manual, project, and exam.

Uploaded by

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

Mpi L

The document provides information about a lab report for a Microprocessor and Interfacing course. It includes the course code, credit hours, semester, instructor details, lab objectives, learning outcomes, a complex engineering activity involving a semester project, the relationship between assessments and learning outcomes, and the grading policy. The lab aims to develop skills in Arduino programming, interfacing hardware modules, designing systems, simulation software, and troubleshooting. Students will be assessed based on a lab manual, project, and exam.

Uploaded by

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

SIR SYED UNIVERSITY OF ENGINEERING & TECHNOLOGY

BIOMEDICAL ENGINEERING DEPARTMENT

MICRO PROCESSOR & INTERFACING


LAB REPORT
Course Code: BM-321(L)
Credit Hours: 1
Semester: 5th
Session: Fall 2023
Batch: 2021F

Prepared By

Name:
Roll Number:

Submitted To
Engr. S. M. Omair
Assistant Professor
BMED
(SSUET/QR/111)
SIR SYED UNIVERSITY OF ENGINEERING & TECHNOLOGY
BIOMEDICAL ENGINEERING DEPARTMENT

LAB INFORMATION SHEET

Session: Fall 2023


Course Title: Micro Processor & Interfacing
Course Code: BM-321(L)
Credit Hours: 1
Semester: 5th
Pre-Requisites: EE-220 Digital Logic Design
Instructor Name: Syed Muhammad Omair
Email and Contact Information: [email protected]
WhatsApp Group BM 321-MPI-Batch-2021F
Office Hours: 8:30am to 5:00pm
Mode of Teaching:
Synchronous

LAB OBJECTIVE:

The lab facilitates the students in learning and improving their skills in Arduino programming, hardware /
modules interfacing, system designing, software simulation and troubleshooting.
Furthermore, the lab objectives are to achieve the following Program Learning Outcomes:
PLO-5 Modern Tool Usage
PLO-11 Project Management

COURSE LEARNING OUTCOMES (CLOs) and its mapping with Program Learning Outcomes (PLOs):

CLO Bloom’s
Course Learning Outcomes (CLOs) PLOs
No. Taxonomy
Display Arduino’s effectiveness by applying its basic
program structure, generate various logics and PLO 5 P4
4 sequences on LEDBARs and Seven segment LEDs. (Modern Tool Usage) (Mechanism)
Construct various circuits and logics using LCDs,
Keypad, sensors and motors.

Combine resources to design various semester PLO 11 A3


5
projects. (Project Management) (Organization)
(SSUET/QR/111)
SIR SYED UNIVERSITY OF ENGINEERING & TECHNOLOGY
BIOMEDICAL ENGINEERING DEPARTMENT

COMPLEX ENGINEERING ACTIVITY:

Complex Engineering Activity Details Included: Yes


Activity: Project Assigned to 2-3 students in a group

Nature and details of Complex Engineering Activity (CEA): It will


be given as a semester project

CEA will be based on CLO-5 " Combine resources to design


various semester projects”. To investigate the problem, students
have to use in-depth knowledge related to the following concepts:
Arduino programming, LEDs, LEDBAR, shift registers, seven
segments.

Attributes could be: EA1, EA2, EA5, WK5, WA11


EA1: Range of resources
EA2: Level of interaction
EA5: Familiarity
WK5: Engineering design
WA11: Project Management
Assessment in: Project Demonstration

RELATIONSHIP BETWEEN ASSESSMENT TOOLS AND CLOS:

CLO 4 CLO 5
Assessment Tools
(35) (15)
Lab Manual 43% (15) -----

Lab Project ----- 100% (15)

Lab Exam 57% (20) -----

GRADING POLICY:

Assessment Tools Percentage Marks


Lab Manual 30% 15
Lab Project 30% 15
Lab Exam 40% 20
TOTAL 100% 50
SSUET/QR/118
[Form-IIb]
Sir Syed University of Engineering & Technology, Karachi
Biomedical Engineering Department
Rubric Guideline for Software Based Lab
Micro Processor & Interfacing (BM-321L), 5th Semester, Batch

Name of Student: Roll No.

Criteria Exceeds Expectations Meets Expectations Developing Unsatisfactory


(2) (1.8) (1.2) (0.8)
Able to use software Able to use software Able to use Unable to use the
Software with its standard and with its standard and software with its software
Handling advanced features advanced features with standard features
without assistance minimal assistance with assistance
(5) (4) (3) (2)
Programming/ Able to program/ Able to program/ Able to program/ Unable to
Simulation simulate the lab tasks simulate the lab tasks simulate lab tasks program/simulate
with simplification without errors with errors
(2) (1.8) (1.2) (0.8)
Able to achieve all the Able to achieve all the Able to achieve Unable to
Results desired results with desired results most of the achieve the
alternate ways desired results desired results
with errors
(1) (0.8) (0.6) (0.4)
Laboratory manual has Laboratory manual has Laboratory Laboratory
no grammatical and/ or very few grammatical/ manual has manual has
spelling errors. spelling errors. multiple several
Laboratory All sections of the All sections of the grammatical/ grammatical/
Manual report are very well report are technically spelling errors. spelling errors
written and technically accurate. Few sections of and sentence
accurate. the report contain construction is
technical errors. poor.
SSUET/QR/118
[Form-IIb]

Sir Syed University of Engineering & Technology, Karachi


Biomedical Engineering Department
Rubric-Laboratory Manual
Micro Processor & Interfacing (BM-321L), 5th Semester, Batch
Name of Student: Roll No.

Lab Description & Score

1. Software Handling Programming/ Simulations Results Lab Report Score


( )/2 ( )/5 ( )/2 ( )/1 ( )/10

2. Software Handling Programming/ Simulations Results Lab Report Score


( )/2 ( )/5 ( )/2 ( )/1 ( )/10

3. Software Handling Programming/ Simulations Results Lab Report Score


( )/2 ( )/5 ( )/2 ( )/1 ( )/10

4. Software Handling Programming/ Simulations Results Lab Report Score


( )/2 ( )/5 ( )/2 ( )/1 ( )/10

5. Software Handling Programming/ Simulations Results Lab Report Score


( )/2 ( )/5 ( )/2 ( )/1 ( )/10

6. Software Handling Programming/ Simulations Results Lab Report Score


( )/2 ( )/5 ( )/2 ( )/1 ( )/10

7. Software Handling Programming/ Simulations Results Lab Report Score


( )/2 ( )/5 ( )/2 ( )/1 ( )/10

8. Software Handling Programming/ Simulations Results Lab Report Score


( )/2 ( )/5 ( )/2 ( )/1 ( )/10

9. Software Handling Programming/ Simulations Results Lab Report Score


( )/2 ( )/5 ( )/2 ( )/1 ( )/10

10. Software Handling Programming/ Simulations Results Lab Report Score


( )/2 ( )/5 ( )/2 ( )/1 ( )/10

11. Software Handling Programming/ Simulations Results Lab Report Score


( )/2 ( )/5 ( )/2 ( )/1 ( )/10

12. Software Handling Programming/ Simulations Results Lab Report Score


( )/2 ( )/5 ( )/2 ( )/1 ( )/10

13. Software Handling Programming/ Simulations Results Lab Report Score


( )/2 ( )/5 ( )/2 ( )/1 ( )/10

14. Software Handling Programming/ Simulations Results Lab Report Score


( )/2 ( )/5 ( )/2 ( )/1 ( )/10

15. Software Handling Programming/ Simulations Results Lab Report Score


( )/2 ( )/5 ( )/2 ( )/1 ( )/10
TOTAL SCORE

Overall Score: out of 15 Examined by:


(Obtained Score / Total Score) x 15 (Name and Signature of concerned lab instructor)
SSUET/QR/118
(Form IIIb)
Sir Syed University of Engineering & Technology, Karachi
Biomedical Engineering Department
Rubric for Lab Exam
Micro Processor & Interfacing (BM-321L), 5th Semester, Batch

Name of Student: Roll No.

Exceeds Meets
Criteria Developing Unsatisfactory Score
Expectations Expectations
(5-6) (<5) Obtained
(9-10) (7-8)
Performanc
e Able to present full Able to present Able to present No or very less
knowledge of both adequate knowledge sufficient knowledge knowledge of both
(10 Marks) problem and solution. of both problem and of both problem and problem and solution
solution solution

Viva Able to answer the Able to answer the Able to answer the Unable to answer
(10 Marks) questions easily and questions related to questions but with the questions
correctly across the the project mistakes
project.
Total Score (20 Marks)

Final Lab Assessment

CLO Bloom's Criteria Score


No Taxonomy Obtained
Laboratory Manual
P4 Marks (15)
CLO 4
(Mechanism) Lab Exam
Marks (20)
A3 Lab Project
CLO 5
(Organization) Marks (15)
Total
Marks (50)

Examined by:
(Name and Signature of concerned lab instructor)
Micro Processor & Interfacing (BM-321L) Lab Report

Micro Processor & Interfacing


Index
Lab Page Remark
List of Experiments Sign
# # s

10

Department of Biomedical Engineering


Sir Syed University of Engineering & Technology, Karachi
Micro Processor & Interfacing (BM-321L) Lab Report

11

12

13

14

15

Department of Biomedical Engineering


Sir Syed University of Engineering & Technology, Karachi
Micro Processor & Interfacing (BM-321L) Lab Report

LAB #1

Display the Arduino UNO board pinout and understand its basic program structure

THEORETICAL BACKGROUND
 MICRO-CONTROLLER:
A microcontroller is a chip optimized to control electronic devices. It is stored in a single integrated circuit
which is dedicated to performing a particular task and execute one specific application. It is specially
designed circuits for embedded applications and is widely used in automatically controlled electronic
devices. It contains memory, processor, and programmable I/O.

 MICRO-PROCESSOR:
A microprocessor is a controlling unit of a micro-computer wrapped inside a small chip. It performs
Arithmetic Logical Unit (ALU) operations and communicates with the other devices connected with it. It is
a single Integrated Circuit in which several functions are combined.

 DIFFERENCE B/W MICRO CONTROLLER AND MICRO PROCESSOR:

MICRO PROCESSOR MICRO CONTROLLER


Microprocessor consists of only a Central Micro Controller contains a CPU, Memory,
Processing Unit I/O all integrated into one chip
Microprocessor is used in Personal Micro Controller is used in an embedded
Computers system
Microprocessor uses an external bus to
Microcontroller uses an internal controlling
interface to RAM, ROM, and other
bus
peripherals
Microprocessor is complicated and Microcontroller is inexpensive and
expensive, with a large number of straightforward with fewer instructions to
instructions to process process

 ARDUINO:
Arduino is an open-source platform (Often referred as Micro-controller) used for building electronics
projects. Arduino consists of both a Programmable hardware and a software which is used to over write the
Arduino Programmable Hardware by using language Which in terms called embedded C and C.

 ARDUINO PIN CONFIGURATIONS:


Digital pins on the Arduino are pins designed to be configured as inputs or outputs according to the needs of
the user.

 DIGITAL PINS:
There are 14 digital input and output pins (0-13) operating at 5v and approximately 20 – 30 mA.

 ANALOG PINS:
There are 6 analog pins which are default input and are used for analog device interfacing [A0-A5].

Department of Biomedical Engineering Page 9


Sir Syed University of Engineering & Technology,
Karachi
Micro Processor & Interfacing (BM-321L) Lab Report

 PWM PINS:
PWM stands for Pulse Width Modulation Pins which has a sign of tilde (~); used for controlling the speed
of dc motors and brightness of a LED [3,5,6,9,10,11].

 AREF
This pin is used to set analog reference voltage other than the supply voltage for precise analog to digital
conversion.

 IOREF:
IOREF stands for INPUT/OUTPUT Reference which helps Arduino Shield identify power options in use by
Arduino board.

 Serial Communications:
There are various serial communication options available in Arduino in the form of RX/TX, I2C and SPI.

 External Interrupts:
External hardware interrupt option is available on digital pins 2 and 3 in Arduino UNO.

 ARDUINO POWER OPTIONS:


Arduino can be operated by 3 methods which are very well-known.
i. USB:
We can operate Arduino by its USB plug In Port which connects with your Laptop/Personal Computer by
a USB cable. It can provide up to (5V and 200mA-300mA).

ii. ADAPTOR JACK:


There is an option of Adaptor Jack present on hardware of Arduino; it works at 7V TO 12V.

iii. CELL/BATTERY:
We can directly Operate Arduino Micro Controller by giving directly a DC supply of 5v to its Vin Pin.

OBJECTIVE 1
To operate a LED by using Arduino IDE and simulate that program on Proteus Professional Software.

COMPONENTS REQUIED
1. Arduino UNO Board
2. 100 Ω resistor
3. Animated LED

Department of Biomedical Engineering Page 10


Sir Syed University of Engineering & Technology,
Karachi
Micro Processor & Interfacing (BM-321L) Lab Report

CIRCUIT DIAGRAM

SOURCE CODE

void setup()
{
pinMode(13,OUTPUT);
}

void loop()
{
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(1000);
}

RESULTS
When program is switching led high:

Department of Biomedical Engineering Page 11


Sir Syed University of Engineering & Technology,
Karachi
Micro Processor & Interfacing (BM-321L) Lab Report

When program is switching led low:

CONCLUSION
Arduino is an open-source electronics platform that consists of a hardware and software ecosystem. It
provides a flexible and easy-to-use platform for creating interactive projects and prototypes. The Arduino
platform is built around microcontroller boards, which are programmable devices that can interact with
inputs and outputs to control various electronic components.

Department of Biomedical Engineering Page 12


Sir Syed University of Engineering & Technology,
Karachi
Micro Processor & Interfacing (BM-321L) Lab Report

LAB #2

Generate various logical sequences on LEDBAR.

COMPONENTS REQUIED

1. Arduino UNO Board


2. LED-BARGRAPH
3. Animated LED

CIRCUIT DIAGRAM

TASK 1: To make LED glow successively.

SOURCE CODE
void setup() digitalWrite(4,LOW);
{ digitalWrite(5,HIGH);
pinMode(2,OUTPUT); delay(300);
pinMode(3,OUTPUT); digitalWrite(5,LOW);

Department of Biomedical Engineering Page 13


Sir Syed University of Engineering & Technology,
Karachi
Micro Processor & Interfacing (BM-321L) Lab Report
pinMode(4,OUTPUT); digitalWrite(6,HIGH);
pinMode(5,OUTPUT); delay(300);
pinMode(6,OUTPUT); digitalWrite(6,LOW);
pinMode(7,OUTPUT); digitalWrite(7,HIGH);
pinMode(8,OUTPUT); delay(300);
pinMode(9,OUTPUT); digitalWrite(7,LOW);
pinMode(10,OUTPUT); digitalWrite(8,HIGH);
pinMode(11,OUTPUT); delay(300);
} digitalWrite(8,LOW);
digitalWrite(9,HIGH);
void loop() { delay(300);
digitalWrite(2,HIGH); digitalWrite(9,LOW);
delay(300); digitalWrite(10,HIGH);
digitalWrite(2,LOW); delay(300);
digitalWrite(3,HIGH); digitalWrite(10,LOW);
delay(300); digitalWrite(11,HIGH);
digitalWrite(3,LOW); delay(300);
digitalWrite(4,HIGH); digitalWrite(11,LOW);
delay(300); }
RESULTS
ARD1

AREF
13
PB5/SCK U1
12
PB4/MISO
RESET 11 1 20
~PB3/MOSI/OC2A
10 2 19
~ PB2/SS/OC1B
9 3 18
~ PB1/OC1A
8 4 17
PB0/ICP1/CLKO
5 16
ATMEGA328P-PU
1121

DIGITAL(~PWM)

7 6 15
ANALOG IN

PD7/AIN1
6 7 14
A0 ~ PD6/AIN0
PC0/ADC0 5 8 13
A1 ~ PD5/T1
PC1/ADC1 4 9 12
A2 PD4/T0/XCK
PC2/ADC2 3 10 11
A3 ~ PD3/INT1
PC3/ADC3 2
A4 PD2/INT0
PC4/ADC4/SDA 1 LED-BARGRAPH-GRN
A5 TX PD1/TXD
PC5/ADC5/SCL 0
RX PD0/RXD

ARDUINO UNO R3

TASK 2: To make LED glow from bottom to top


SOURCE CODE RESULTS

Department of Biomedical Engineering Page 14


Sir Syed University of Engineering & Technology,
Karachi
Micro Processor & Interfacing (BM-321L) Lab Report
int a, duration=300;
void setup()
{
for(a=2;a<=11;a++)
{
pinMode(a,OUTPUT);
}
}

void loop() {
for(a=2;a<=11;a++)
{
digitalWrite(a,HIGH);
delay(duration);
digitalWrite(a,LOW);
}
}

TASK 3: To make LED glow from top to bottom


SOURCE CODE RESULTS
int a, duration=500;
void setup() {
for(a=11;a>=2;a--)
{
pinMode(a,OUTPUT);
}
}

void loop() {
for(a=11;a>=2;a--)
{
digitalWrite(a,HIGH);
delay(duration);
digitalWrite(a,LOW);
}
}

TASK 4: To make LED glow by moving bottom to top and vice versa

Department of Biomedical Engineering Page 15


Sir Syed University of Engineering & Technology,
Karachi
Micro Processor & Interfacing (BM-321L) Lab Report
SOURCE CODE
int a, duration1=300; for(a=2;a<=11;a++)
int b, duration2=100; {
int c, duration3=500; digitalWrite(a,LOW);
void setup() }
{ delay(2000);
for(a=2;a<=11;a++) for(b=11;b>=2;b--)
{ {
pinMode(a,OUTPUT); digitalWrite(b,HIGH);
} delay(duration2);
} digitalWrite(b,LOW);
}
void loop() { delay(1000);
for(a=2;a<=11;a++) for(c=2;c<=11;c+=3)
{ {
digitalWrite(a,HIGH); digitalWrite(c,HIGH);
delay(duration1); delay(duration3);
digitalWrite(a,LOW);
} }
delay(2000); for(c=2;c<=11;c++)
for(a=2;a<=11;a++) {
{ digitalWrite(c,LOW);
digitalWrite(a,HIGH); }
} delay(2000);
delay(2000); }

RESULTS

Department of Biomedical Engineering Page 16


Sir Syed University of Engineering & Technology,
Karachi
Micro Processor & Interfacing (BM-321L) Lab Report

CONCLUSION
In Arduino programming, a for loop is important when controlling or "glowing" an LED because it allows
you to repeat a series of instructions for a specific number of times. By using a for loop, you can easily
control the on and off states of an LED to create various patterns or effects.By using a for loop, you can
easily control the number of times the LED blinks and manipulate the timings to achieve different blinking
patterns or effects. The for loop simplifies the code by eliminating the need to write repetitive instructions
multiple times, making the code more efficient and easier to understand.

LAB #3

Construct 7 segment circuits and generate an up down counter.

COMPONENTS REQUIED

1. Arduino UNO Board


2. 7 Seg-MPx1-CA
3. 7 Seg decoder IC- 7447, 7448

TASK 1: Display the number 35 on 7-segment display.


SOURCE CODE
Int count=99, convert=0 , bit_value; Count++;
Int a,b,pins[]={13,12,11,10,5,4,3,2}; If(count==100)
Void setup() { {
For(a=0;a<=7;a++) Count=0;
{ Convert=0;

Department of Biomedical Engineering Page 17


Sir Syed University of Engineering & Technology,
Karachi
Micro Processor & Interfacing (BM-321L) Lab Report
pinMode(pins[a],OUTPUT); }
}} }
Void loop() { Int bintobcd(int recv)
Convert=bintobcd(count); {
For(a=0;a<=7;a++) Int q,r;
{ Q=recv/10;
Bit_value=bitRead(convert,a); R=recv%10;
digitalWrite(pins[a],bit_value); Q=q<<4;
} Q=q|r;
Delay(300); Return 0;

RESULTS

TASK 2: To display numbers from ‘0-99’ using two seven segment displays
SOURCE CODE
Int count=99, convert=0 , bit_value; Delay(300);
Int a,b,pins[]={13,12,11,10,5,4,3,2}; Count--;
Void setup() If(count<=0)
{ {
For(a=7;a>=0;a--) Count=99;
{ Convert=0;
pinMode(pins[a],OUTPUT); }
} }
} Int bintobcd(int recv)
Void loop() {
{ Int q,r;
Convert=bintobcd(count); Q=recv/10;
For(a=7;a>=0;a--) R=recv%10;
{ Q=q<<4;
Bit_value=bitRead(convert,a); Q=q|r;
digitalWrite(pins[a],bit_value);} Return q;
RESULTS

Department of Biomedical Engineering Page 18


Sir Syed University of Engineering & Technology,
Karachi
Micro Processor & Interfacing (BM-321L) Lab Report

TASK 3: To display numbers from ’99-0’ using two seven segment displays.
SOURCE CODE
int pins[]={13,12,11,10,5,4,3,2}; }
int count=99,convert=99,a,bit_value; delay(300);
void setup() { count--;
// put your setup code here, to run once: if(count<=0)
for(a=0;a<=7;a++) {
{ count=99;
pinMode(pins[a],OUTPUT); convert=99;
} }}
} int bintobcd(int recv)
{
void loop() { int q,r;
// put your main code here, to run repeatedly: q=recv/10;
convert=bintobcd(count); r=recv%10;
for(a=0;a<=7;a++) q=q<<4;
{ q=q|r;
bit_value=bitRead(convert,a); return q;
digitalWrite(pins[a],bit_value); }
RESULTS

TASK 4: Generate code for first 0-99 countdown then 99-0 countdown.
SOURCE CODE
Int a,count=0,convert=0,bit_value; }
Int pins[]={13,12,11,10,5,4,3,2}; for(count=99;count>=0;count--)
void setup() {
{ convert=bintobcd(count);
for(a=0;a<=7;a++) for(a=0;a<=7;a++)

Department of Biomedical Engineering Page 19


Sir Syed University of Engineering & Technology,
Karachi
Micro Processor & Interfacing (BM-321L) Lab Report
{ {
pinMode(pins[a],OUTPUT); bit_value=bitRead(convert,a);
} digitalWrite(pins[a],bit_value);
} }
void loop() delay(200);
{ }
for(count=0;count<=99;count++) }
{ intbintobcd(intrecv) {
convert=bintobcd(count); intq,r;
for(a=0;a<=7;a++) q=recv/10;
{ r=recv%10;
bit_value=bitRead(convert,a); q=q<<4;
digitalWrite(pins[a],bit_value); q=q|r;
} return q;
delay(200); }
RESULTS

CONCLUSION
In this lab, we utilize Arduino to perform various tasks involving a 7-segment screen in different ways. One
possible method involves using an LED bar graph with the Arduino to display the 7-segment output.

LAB #4

Construct 7 segment circuit and generate an even-odd counter.


COMPONENTS REQUIED

Department of Biomedical Engineering Page 20


Sir Syed University of Engineering & Technology,
Karachi
Micro Processor & Interfacing (BM-321L) Lab Report
1. Arduino UNO Board
2. LED 7SEG
3. BCD to seven segment decoder.

TASK 1: Generate a 2 digit even up-down counter


SOURCE CODE RESULTS
const byte LED = 4, button = 3;
byte check;
void setup()
{
pinMode(LED, OUTPUT);
pinMode(button, INPUT);
}
void loop()
{
check = digitalRead(button);
if (check == 1)
{
digitalWrite(LED, 1);

delay(800);
digitalWrite(LED, 0);
}}

TASK 2: To display up counting by using 7 segment display by reducing inputs in Arduino.


SOURCE CODE
const byte UP = 13, LED=12, CLOCK = 11, DATA = }
10, LATCH = 9; convert = bintobcd(count);
byte check, count = 0, displayvalue(convert);
convert = 0; }
void setup(){ }
pinMode(UP, INPUT); digitalWrite(LED, 1);
pinMode(LED, OUTPUT); delay(1000);
pinMode(CLOCK, OUTPUT); digitalWrite(LED, 0);
pinMode(DATA, OUTPUT); }
pinMode(LATCH, OUTPUT); byte bintobcd(byte recv)
displayvalue(convert);} {
void loop(){ byte q, r;
while (1){ q = recv / 10;
check = digitalRead(UP); r = recv % 10;
if (check == 1) q = q << 4;
{ q = q | r;
delay(250); return q;
count++; }
if (count == 99) void displayvalue(byte recv)
{ {
count = 0; digitalWrite(LATCH, 0);
convert = 0; shiftOut(DATA, CLOCK, MSBFIRST, recv);
displayvalue(convert); digitalWrite(LATCH, 1);
break; }
RESULTS

Department of Biomedical Engineering Page 21


Sir Syed University of Engineering & Technology,
Karachi
Micro Processor & Interfacing (BM-321L) Lab Report

TASK 3: Generate a 2-digit odd up-down counter.


SOURCE CODE
int count = 0, convert= count += 2;
0, bit_value; if (count == 100)
int a, pins[] = {13, 12, {
11, 10, 5, 4, 3, 2}; count = 99;
bool upDirection = true; upDirection = false;
//true for up, false for down }
void setup() }
{ void odd_down_counting()
for (a = 0; a < 8; a++) {
{ convert = bintobcd(count);
pinMode(pins[a], OUTPUT);
} for (a = 7; a >= 0; a--)
} {
void loop() bit_value = bitRead(convert, a);
{ digitalWrite(pins[a], bit_value);
if (upDirection) }
{ delay(300);
even_up_counting(); count -= 2;
} if (count < 0)
else {
{ count = 0;
odd_down_counting(); upDirection = true;
} }
} }
void even_up_counting() int bintobcd(int recv)
{ {
convert = bintobcd(count); int q, r;
for (a = 0; a < 8; a++) q = recv / 10;
{ r = recv % 10;
bit_value = bitRead(convert, a); q = q << 4;
digitalWrite(pins[a], bit_value); q = q | r;
} return q;
delay(300); }

Department of Biomedical Engineering Page 22


Sir Syed University of Engineering & Technology,
Karachi
Micro Processor & Interfacing (BM-321L) Lab Report
RESULTS
Event up: Odd down:

CONCLUSION
Arduino boards have multiple digital pins that can be configured as inputs or outputs. The digitalRead(pin)
function can be used to read the digital value (HIGH or LOW) of a specific pin. This is commonly used to
read the status of buttons, switches, or other digital sensors.

Department of Biomedical Engineering Page 23


Sir Syed University of Engineering & Technology,
Karachi
Micro Processor & Interfacing (BM-321L) Lab Report

LAB #5

Exploring the reading inputs in Arduino


COMPONENTS REQUIED

1. Arduino UNO Board


2. LED
3. Resistors
4. Push button
5. Virtual wirings.

TASK 1: To make LED glow with the help of push button by reducing inputs in Arduino.
SOURCE CODE RESULTS
const byte LED = 4, button = 3;
byte check; R1
void setup() PWR
10k
GND

ARD1
{
GND
pinMode(LED, OUTPUT);

B U TTO N
pinMode(button, INPUT);
ON
R eset B T N

PWR

w w w .T h e E n g in e e rin g P ro je c ts .co m
} D1
AREF
R2
void loop() PB5/SCK
13 LED GND

{ RESET
PB4/MISO
~ PB3/MOSI/OC2A
12
11
100
LED-RED
10
check = digitalRead(button); ~ PB2/OC1B
~ PB1/OC1A
9
8
if (check == 1) PB0/ICP1/CLKO
AT M E G A328P -P U
1121

7
A N A L O G IN

{ A0
PD7/AIN1
~ PD7/AIN1
6
5
PC0/ADC0 ~ PD5/T1/OC0B
digitalWrite(LED, 1); A1
A2
PC1/ADC1 PD4/T0/XCK
4
3
LED
PC2/ADC2 ~ PD3/INT1/OC2B
A3 2 BUTTON
PC3/ADC3 PD2/INT0
A4 PD1/TXD 1
PC4/ADC4/SDA
delay(800); A5
PC5/ADC5/SCL PD0/RXD 0

digitalWrite(LED, 0); ARDUINO UNO R3

}}

TASK 2: To display up counting by using 7 segment display by reducing inputs in Arduino.


SOURCE CODE
const byte UP = 13, LED=12, CLOCK = 11, DATA = }
10, LATCH = 9; convert = bintobcd(count);
byte check, count = 0, displayvalue(convert);
convert = 0; }
void setup(){ }
pinMode(UP, INPUT); digitalWrite(LED, 1);
pinMode(LED, OUTPUT); delay(1000);
pinMode(CLOCK, OUTPUT); digitalWrite(LED, 0);
pinMode(DATA, OUTPUT); }
pinMode(LATCH, OUTPUT); byte bintobcd(byte recv)
displayvalue(convert);} {
void loop(){ byte q, r;
while (1){ q = recv / 10;
check = digitalRead(UP); r = recv % 10;
if (check == 1) q = q << 4;
{ q = q | r;
delay(250); return q;
count++; }
if (count == 99) void displayvalue(byte recv)

Department of Biomedical Engineering Page 24


Sir Syed University of Engineering & Technology,
Karachi
Micro Processor & Interfacing (BM-321L) Lab Report
{ {
count = 0; digitalWrite(LATCH, 0);
convert = 0; shiftOut(DATA, CLOCK, MSBFIRST, recv);
displayvalue(convert); digitalWrite(LATCH, 1);
break; }
RESULTS
GND

PWR
ARD1

R1
PWR GND
10k

ON
Reset BTN

www.TheEngineeringProjects.com

UP
AREF
13 UP
PB5/SCK
PB4/MISO
12 LED D1
RESET ~ PB3/MOSI/OC2A
11 CLOCK R2
10 DATA LED GND
~ PB2/OC1B
9 LATCH 100
~ PB1/OC1A LED-RED
8
PB0/ICP1/CLKO

ATMEGA328P-PU
1121
7
ANALOG IN

PD7/AIN1
6
~ PD7/AIN1
A0 5
PC0/ADC0 ~ PD5/T1/OC0B
A1 4
PC1/ADC1 PD4/T0/XCK
A2 3
PC2/ADC2 ~ PD3/INT1/OC2B
A3 2
PC3/ADC3 PD2/INT0
A4 PD1/TXD 1
PC4/ADC4/SDA
A5 PD0/RXD 0
PC5/ADC5/SCL

ARDUINO UNO R3

PWR

PWR
A2
B2
C2
D2
E2
F2
G2

A1
B1
C1
D1
E1
F1
G1
U1 U3
11 15 U2 7 13
CLOCK SH_CP Q0 0 4 A QA A2
14 1 7 13 1 12
DATA DS Q1 1 0 A QA A1 5 B QB B2
2 1 12 2 11
Q2 2 1 B QB B1 6 C QC C2
12 3 2 11 6 10
LATCH ST_CP Q3 3 2 C QC C1 7 D QD D2
4 6 10 4 9
Q4 4 3 D QD D1 BI/RBO QE E2
5 4 9 5 15
Q5 5 BI/RBO QE E1 PWR RBI QF F2
6 5 15 3 14
Q6 6 PWR RBI QF F1 LT QG G2
10 7 3 14
PWR MR Q7 7 LT QG G1
13 9 74LS47
GND OE Q7'
74LS47
74HC595

TASK 3: To display down counting by using 7 segment display by reducing inputs in Arduino.
SOURCE CODE
const byte UP = 13, LED = 12, CLOCK = 11, DATA = 10, DOWNcheck = digitalRead(DOWN);
LATCH = 9, DOWN = 8; if (UPcheck == 1)
byte UPcheck, DOWNcheck, count = 0, convert = 0; break;
void setup() if (DOWNcheck == 1)
{
pinMode(UP, INPUT); {
pinMode(DOWN, INPUT); delay(250);
pinMode(LED, OUTPUT); count--;
pinMode(CLOCK, OUTPUT); if (count == 0)
pinMode(DATA, OUTPUT); {
pinMode(LATCH, OUTPUT); count = 99;
displayvalue(convert); convert = 0;
} displayvalue(convert);
void loop() break;
{ }
while (1) convert = bintobcd(count);
{ displayvalue(convert);
UPcheck = digitalRead(UP); }
DOWNcheck = digitalRead(DOWN); }
if (DOWNcheck == 1) digitalWrite(LED, 1);
break; delay(1000);
if (UPcheck == 1) digitalWrite(LED, 0);
{ }
delay(250); byte bintobcd(byte recv)
count++; {
if (count == 100) byte q, r;
{ q = recv / 10;
count = 0; r = recv % 10;
convert = 0; q = q << 4;
displayvalue(convert); q = q | r;
break; return q;
} }
convert = bintobcd(count); void displayvalue(byte recv)

Department of Biomedical Engineering Page 25


Sir Syed University of Engineering & Technology,
Karachi
Micro Processor & Interfacing (BM-321L) Lab Report
displayvalue(convert); {
} digitalWrite(LATCH, 0);
} shiftOut(DATA, CLOCK, MSBFIRST, recv);
while (1) { digitalWrite(LATCH, 1);
UPcheck = digitalRead(UP); }
RESULTS
GND

PWR
ARD1

R1
PWR GND
10k

ON
Reset BTN

www.TheEngineeringProjects.com

UP
AREF
13 UP
PB5/SCK
PB4/MISO
12 LED D1
RESET ~ PB3/MOSI/OC2A
11 CLOCK R2
10 DATA LED GND
~ PB2/OC1B
9 LATCH 100
~ PB1/OC1A LED-RED
8
PB0/ICP1/CLKO

ATMEGA328P-PU
1121
7
ANALOG IN

PD7/AIN1
6
~ PD7/AIN1
A0 5
PC0/ADC0 ~ PD5/T1/OC0B
A1 4
PC1/ADC1 PD4/T0/XCK
A2 3
PC2/ADC2 ~ PD3/INT1/OC2B
A3 2
PC3/ADC3 PD2/INT0
A4 PD1/TXD 1
PC4/ADC4/SDA
A5 PD0/RXD 0
PC5/ADC5/SCL

ARDUINO UNO R3

PWR

PWR
A2
B2
C2
D2
E2
F2
G2

A1
B1
C1
D1
E1
F1
G1
U1 U3
11 15 U2 7 13
CLOCK SH_CP Q0 0 4 A QA A2
14 1 7 13 1 12
DATA DS Q1 1 0 A QA A1 5 B QB B2
2 1 12 2 11
Q2 2 1 B QB B1 6 C QC C2
12 3 2 11 6 10
LATCH ST_CP Q3 3 2 C QC C1 7 D QD D2
4 6 10 4 9
Q4 4 3 D QD D1 BI/RBO QE E2
5 4 9 5 15
Q5 5 BI/RBO QE E1 PWR RBI QF F2
6 5 15 3 14
Q6 6 PWR RBI QF F1 LT QG G2
10 7 3 14
PWR MR Q7 7 LT QG G1
13 9 74LS47
GND OE Q7'
74LS47
74HC595

CONCLUSION
Arduino boards have multiple digital pins that can be configured as inputs or outputs. The digitalRead(pin)
function can be used to read the digital value (HIGH or LOW) of a specific pin. This is commonly used to
read the status of buttons, switches, or other digital sensors.

Department of Biomedical Engineering Page 26


Sir Syed University of Engineering & Technology,
Karachi

You might also like