Lab 01 MP MC
Lab 01 MP MC
Name:
Reg. No:
Date of
Experiment:
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.
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
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
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