0% found this document useful (0 votes)
13 views

Lab 01 MP MC

Microxontroller Lab01

Uploaded by

Rizwan Latif
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Lab 01 MP MC

Microxontroller Lab01

Uploaded by

Rizwan Latif
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

International Islamic University Islamabad

Faculty of Engineering and Technology


Department of Electrical Engineering

MICROPROCESSORS AND MICROCONTROLLER LAB

Lab 1 : I/O Ports Programming & LED Interfacing with Arduino

Name:

Reg. No:

Date of
Experiment:

OBE Rubrics Evaluation

a) PSYCHOMOTOR (To be judged in the field/lab during experiment)


Sr. Level 1 Level 2 Level 3 Level 4 Level 5 Marks
Criteria
No. (0%) (25%) (50%) (75%) (100%) Obtained
0 1.25 2.5 3.75 5
Practical
With several With few With some Without
Implementation/
1 critical errors, errors, errors, errors,
Arrangement of Absent
incomplete incomplete complete complete
Equipment
and not neat and not neat but not neat and neat
Use of 0 0.5 1 1.5 2
Equipment or
2 Limited Some Considerable
Simulation/ Absent Competence
competence competence competence
Programming Tool

(b) COGNITIVE (To be judged on the copy of experiment submitted)


Sr. Level 1 Level 2 Level 3 Level 4 Level 5 Marks
Criteria
No. (0%) (25%) (50%) (75%) (100%) Obtained
Algorithm Design 0 0.25 0.5 0.75 1
or Data Record, Complete
3 Complete with Complete
Analysis and Absent Incorrect with few
some errors and Accurate
Evaluation errors

(c) AFFECTIVE (To be judged in the field/lab during experiment)


Sr. Level 1 Level 2 Level 3 Level 4 Level 5 Marks
Criteria
No. (0%) (25%) (50%) (75%) (100%) Obtained
Level of 0 0.5 1 1.5 2
Participation &
Good Encouraging
4 Attitude to Achieve Rare sensible Some sensible
Absent sensible sensible
Individual/Group interaction interaction
interaction interaction
Goals

5 Total Marks Obtained (Out of 10):

Lab 1: I/O Ports Programming & LED Interfacing with Arduino Page 6
Objectives:
 To familiarize the student with the basic operation of the Arduino Uno board, and
Integrated Development Environment (IDE). By the end of the exercise, the student
should be able to know the basic functionalities of the IDE.
 To understand that how to make a port input or output
 First C++ Program to blink LEDs
Arduino Overview:
Arduino is a prototype platform (open-source) based on an easy-to-use hardware
and software. It consists of a circuit board, which can be programed (referred to as a
microcontroller) and a ready-made software called Arduino IDE (Integrated
Development Environment), which is used to write and upload the computer code to
the physical board.
The key features are:
 Arduino boards are able to read analog or digital input signals from different
sensors and turn it into an output such as activating a motor, turning LED on/off,
connect to the cloud and many other actions.
 You can control your board functions by sending a set of instructions to the
microcontroller on the board via Arduino IDE (referred to as uploading software).
Unlike most previous programmable circuit boards, Arduino does not need an extra
piece of hardware (called a programmer) in order to load a new code onto the
board. You can simply use a USB cable.
 Additionally, the Arduino IDE uses a simplified version of C++, making it easier to
learn to program.
 Finally, Arduino provides a standard form factor that breaks the functions of the
microcontroller into a more accessible package
Arduino UNO Component View:
 Analog Input Pins – Pins (A0-A5) that take-in analog values to be converted to
be represented with a number range 0-1023 through a 10-bit Analog to Digital
Converter (ADC).
 ATmega328 Chip – 8-bit microcontroller that processes the sketch you
programmed.
 Built-in LED – in order to gain access or control of this pin, you have to change
the configuration of pin 13 where it is connected to.
 Crystal Oscillator – Clock that has a frequency of 16MHz
 DC Jack – where the power source (AC-to-DC adapter or battery) should be
connected. It is limited to input values between 6-20V but recommended to be
around 7-12V.
 Digital I/O Pins – Input and Output pins (0-13) of which 6 of them (3, 5, 6, 9, 10
and 11) also provide PWM (Pulse Width Modulated) output by using the
analogWrite() function. Pins (0 (RX) and 1 (TX)) are also used to transmit and
receive serial data.
 ICSP Header – Pins for “In-Circuit Serial Programming” which is another method
of programming.

Lab 1: I/O Ports Programming & LED Interfacing with Arduino Page 7
 ON indicator – LED that lights up when the board is connected to a power source.
 Power Pins – pins that can be used to supply a circuit with values VIN (voltage
from DC Jack), 3.3V and 5V.
 Reset Button – a button that is pressed whenever you need to restart the sketch
programmed in the board.
 USB port – allows the user to connect with a USB cable the board to a PC to
upload sketches or provide a voltage supply to the board. This is also used for
serial communication through the serial monitor from the Arduino software.

Arduino Program Structure:


Arduino programs (also called sketches) can be divided in three main parts:
Structure, Values (variables and constants), and Functions. In this session, we will
learn about the Arduino software program, step by step, and how we can write the
program without any syntax or compilation error.
Let us start with the Structure. Software structure consist of two main functions:
 void setup( ) function
 void loop( ) function

Lab 1: I/O Ports Programming & LED Interfacing with Arduino Page 8
void setup ( )
{

 The setup() function is called when a sketch starts. Use it to initialize the variables,
pin modes, start using libraries, etc. The setup function will only run once, after
each power up or reset of the Arduino board.

void loop ( )
{

 After creating a setup() function, which initializes and sets the initial values, the
loop() function does precisely what its name suggests, and loops consecutively,
allowing your program to change and respond. Use it to actively control the Arduino
board

First Arduino Sketch:


Write a program to toggle LED connected to PD1 (Pin No.1) with delay of 500 ms

Solution:

#define LED 1

void setup( )
{
DDRD = DDRD | (1<<LED); // Set PD1 as output pin
}

void loop( )
{
PORTD = PORTD & ~(1<<LED); // Turn OFF LED
delay(500); // keep it OFF for 500 ms

PORTD = PORTD | (1<<LED); // Turn ON LED


delay(500); // keep it ON for 500 ms
}

Lab 1: I/O Ports Programming & LED Interfacing with Arduino Page 9
Lab Task:
Write a program to blink built-in LED (Pin No.13, PB5) on UNO board at a frequency
of 4Hz with 50% duty cycle.

Lab 1: I/O Ports Programming & LED Interfacing with Arduino Page 10
Lab 1 Task Solution:

Lab 1: I/O Ports Programming & LED Interfacing with Arduino Page 11

You might also like