0% found this document useful (0 votes)
213 views7 pages

Lab 2 - Introduction To Arduino & Its Coding

This document provides instructions for an Arduino lab experiment on understanding the Arduino structure and coding. It describes downloading and installing the Arduino IDE, connecting an Arduino board to the computer, and uploading a basic "Blink" code to turn on and off the onboard LED. The lab tasks involve writing Arduino codes to control an LED using delays, PWM fading, and a pushbutton switch. Schematics are to be provided for the pushbutton switch tasks.

Uploaded by

Saif Ullah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
213 views7 pages

Lab 2 - Introduction To Arduino & Its Coding

This document provides instructions for an Arduino lab experiment on understanding the Arduino structure and coding. It describes downloading and installing the Arduino IDE, connecting an Arduino board to the computer, and uploading a basic "Blink" code to turn on and off the onboard LED. The lab tasks involve writing Arduino codes to control an LED using delays, PWM fading, and a pushbutton switch. Schematics are to be provided for the pushbutton switch tasks.

Uploaded by

Saif Ullah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 7

EEE342 - Microprocessor Systems and Interfacing

Introduction to Arduino
Lab. Experiment # 2

Objective:
 To understand structure of Arduino.
 Understanding Coding of Arduino.
 Digital Inputs, Outputs, and Pulse-Width Modulation.
 Getting Up and Blinking with the Arduino.

Objective:
Arduino is an open source physical computing platform based on a simple input/output (I/O)
board and a development environment that implements the Processing language.

Unique Features:
Arduino is different from other platforms on the market because of these features:

 It is a multiplatform environment; it can run on Windows, Macintosh, and Linux.


 It is based on the Processing programming IDE, an easy-to-use development
environment used by artists and designers.
 You program it via a USB cable, not a serial port.
 It is open source hardware and software.
 The hardware is cheap.
 There is an active community of users, so there are plenty of people who can help you.
 The Arduino Project was developed in an educational environment and is therefore
great for newcomers to get things working quickly.

Arduino Components:
All Arduino boards have a few key capabilities and functions. Take a moment to examine the
Arduino Uno in Figure 1.

 Atmel microcontroller
 USB programming/communication interface(s)
 Voltage regulator and power connections
 Breakout I/O pins
66 | P a g e Department of Electrical & Computer Engineering | CUI Wah
EEE342 - Microprocessor Systems and Interfacing

 Debug, Power, and RX/TX LEDs


 Reset button
 In-circuit serial programmer (ICSP) connector(s)

Figure 11.1: Arduino UNO R3


Pins Description:
The upper and header socket has 16 and 13 ports on it, respectively;
Lower Header Socket
Label Description
IOREF Provides the reference voltage used by the microcontroller if not 5V.
RESET Resets the Arduino when set to LOW.
3.3V Provides a reduced 3.3V for powering low-voltage external circuits.

67 | P a g e Department of Electrical & Computer Engineering | CUI Wah


EEE342 - Microprocessor Systems and Interfacing

5V Provides the standard 5V for powering external circuits.


GND Provides the ground connection for external circuits.
GND A second ground connection for external circuits.
Vin An external circuit can supply 5V to this pin to power the Arduino, instead of
using the USB or power jacks.
A0 The first analog input interface.
A1 The second analog input interface.
A2 The third analog input interface.
A3 The fourth analog input interface.
A4 The fifth analog input interface, also used as the SDA pin for TWI
communications.
A5 The sixth analog input interface, also used as the SCL pin for TWI
communications.

Upper Header Socket


Label Description
GND The Arduino ground signal.
13 Digital port 13, and the SCK pin for SPI communication.
12 Digital port 12, and the MISO pin for SPI communication.
~11 Digital port 11, a PWM output port, and MOSI pin for SPI communications.
~10 Digital port 10, a PWM output port, and the SS pin for SPI communication.
~9 Digital port 9, and a PWM output port.
8 Digital port 8.
7 Digital port 7.
~6 Digital port 6, and a PWM output port.
~5 Digital port 5, and a PWM output port.
4 Digital port 4.
68 | P a g e Department of Electrical & Computer Engineering | CUI Wah
EEE342 - Microprocessor Systems and Interfacing

~3 Digital port 3, and a PWM output port.


2 Digital port 2.
TX -> 1 Digital port 1, and the serial interface transmit port.
RX -> 1 Digital port 0, and the serial interface receive port.

Downloading and Installing the Arduino IDE:


Access the Arduino website at www.arduino.cc and download its newest version as in Figure
11.2;

Figure 11.2: How to download Arduino IDE

After completing the download, unzip it. Inside, you’ll find the Arduino IDE. New versions of the
Windows IDE are available as an installer that you can download and run, instead of downloading
a ZIP file.

Running the IDE and Connecting to the Arduino:


Now that you have the IDE downloaded and ready to run, you can connect the Arduino to your
computer via USB, as shown in Figure 11.3.

69 | P a g e Department of Electrical & Computer Engineering | CUI Wah


EEE342 - Microprocessor Systems and Interfacing

Mac and Linux machines install the drivers (mostly) automatically. If you are using OS X, the first
time you plug in an UNO or a Mega 2560, you will get a notification that a new network device
has been added. Click the Network Preferences button. In the new window, click Apply. Even
though the board will appear as “Not Configured” in the network device list, it will be ready to
use. Now, quit System Preferences. If you are using a modern Arduino on a Windows computer,
you will probably need to install drivers. You can skip the following directions if you are not using
a Windows computer that needs to have drivers installed. If you installed the IDE using the
Windows installer, then these steps have been completed for you. If you downloaded the ZIP on
your Windows machine, then you will need to follow the directions shown next.

Figure 11.3: Arduino UNO connected to a Computer via USB

On your Windows computer, follow these steps to install the drivers;


1. Wait for the automatic install process to fail.
2. Open the Start menu, right-click My Computer, and select Properties.
3. Choose Device Manager.
4. Look under Ports (COM and LPT) for the Arduino that you connected.
5. Right-click it and choose Update Driver Software.
6. Choose to browse your computer for software.
7. Select the appropriate driver from the drivers directory of the Arduino IDE that you just
downloaded (not the FTDI drivers directory).
8. Windows will now finish the driver installation.

70 | P a g e Department of Electrical & Computer Engineering | CUI Wah


EEE342 - Microprocessor Systems and Interfacing

Now, launch the Arduino IDE. You’re ready to load your first program onto your Arduino.
To ensure that everything is working as expected, you’ll load the Blink example program, which
will blink the onboard LED.

 Most Arduinos have an LED connected to pin 13.


 Navigate to File  Examples  Basic  Click the Blink program.
 This opens a new IDE window with the Blink program already written for you.
 First, you’ll program the Arduino with this example sketch, and then you’ll analyze the
program to understand the important components so that you can start to write your
own programs in the next lab.
 Before you load the program, you need to tell the IDE what kind of Arduino you have
connected and what port it is connected to.
 Go to Tools  Board and ensure that the right board is selected. This example uses the
Uno, but if you are using a different board, selects that one.
 The last step before programming is to tell the IDE what port your board is connected
to.
 Navigate to Tools  Serial Port and select the appropriate port.
 On Windows machines, this will be COM*, where * is some number representing the
serial port number.
 You’re finally ready to load your first program. Click the Upload button ( ) on the top left
of the IDE.
 The status bar at the bottom of the IDE shows a progress bar as it compiles and uploads
your program.
 When the upload completes, the yellow LED on your Arduino should be blinking once
per second. Congratulations!
 You’ve just uploaded your first Arduino program.

71 | P a g e Department of Electrical & Computer Engineering | CUI Wah


EEE342 - Microprocessor Systems and Interfacing

Lab Tasks

Task 1:
Write following code and observe behavior of LED. (Connect +ve leg of LCD to pin 7 and –ve leg
to ground).Write delay in seconds for which LED remains ON and then turns OFF.
int led1=7; //connect +ve leg of LED on pin7
void setup()
{
pinMode(led1,OUTPUT); //setting LED as output
}
void loop()
{
digitalWrite(led1,HIGH); //setting LED ON
delay(1000);
digitalWrite(led1,LOW); //setting LED OFF
delay(1000);
}

Task 2:
Write a code such that LED remains ON for 2 seconds and then turns OFF for 1 second, also attach
proteus schematic.

Task 3:
Write a code such that LED should remain ON till the pushbutton is pressed, once pushbutton is
released, LED should go OFF, also attach proteus schematic for both cases.

Task 4:
Write a code to fade the LED in and out using Pulse Width Modulation (PWM).

72 | P a g e Department of Electrical & Computer Engineering | CUI Wah

You might also like