Getting Started With Arduino: Digital Logic Design Lab 11

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Digital Logic Design Lab 11

Getting Started with Arduino

Content
The focus of this lab is to become familiar with the basic
working of the Arduino. It conveys a basic idea regarding dif-
ferent components of Arduino. We will perform our first and
simplest arduino experiment of blinking an LED that will help
us to increase our practical understanding of arduino.

COMPILED BY:
Hassan Raza
hassan.raza@nu.edu.pk
NUCES, Islamabad Digital Logic Design Lab, Spring 2019

Important Terminologies

1. LED: A light-emitting diode (LED) is a small electronic component that is a bit like a
lightbulb, but is more efficient and requires a lower voltage to operate.
2. Sensors and Actuators: An actuator is the opposite of a sensor: a sensor senses something
in the physical world and converts it to a signal a computer can understand, while an actuator
converts a signal from a computer into an act in the physical world.
3. Arduino: Arduino is an open source physical computing platform for creating interactive
objects that stand alone or collaborate with software on your computer. Arduino is composed
of two major parts:
i The Arduino board, which is the piece of hardware you work on when you build your
objects.
ii Arduino Integrated Development Environment, or IDE, is the piece of software you run
on your computer. The IDE is used to create a sketch (a little computer program) that
you upload to the Arduino board. The sketch tells the board what to do.
4. Arduino Hardware: The Arduino board Figure 1 is a small microcontroller board, which
is a small circuit (the board) that contains a whole computer on a small chip (the microcon-
troller). Arduino has a row of strips at the top and the bottom with lots of labels. These
strips are the connectors, which are used to attach to sensors and actuators.

Figure 1: Arduino Board

Given below is a brief intoduction of the input and output pins:


i 14 Digital I/O pins (pins 0 - 13): These pins can be either inputs or outputs. Inputs
are used to read information from sensors, while outputs are used to control actuators.

1
NUCES, Islamabad Digital Logic Design Lab, Spring 2019

You will specify the direction (in or out) in the sketch you create in the IDE. Digital
inputs can only read one of two values, and digital outputs can only output one of two
values (HIGH and LOW).
ii 6 Analogue In pins (pins 0 - 5): The analogue input pins are used for reading voltage
measurements from analogue sensors. In contrast to digital inputs, which can distinguish
between only two different levels (HIGH and LOW), analogue inputs can measure 1,024
different levels of voltage.
iii 6 Analogue Out pins (pins 3, 5, 6, 9, 10, and 11): These are actually six of the digital
pins that can perform a third function: they can provide analogue output. As with the
digital I/O pins, you specify what the pin should do in your sketch.

The board can be powered from your computers USB port, most USB chargers, or an AC
adapter. Whenever power is provided at the power socket, Arduino will use that, and if there
is no power at the power socket, Arduino will use power from the USB socket.
5. The Software Integrated Development Environment (IDE): The IDE is a special
program running on your computer that allows you to write sketches for the Arduino board
in a simple language modeled after the Processing language. The magic happens when you
press the button that uploads the sketch to the board: the code that you have written is
translated into the C language, and is passed to the avr-gcc compiler, an important piece of
open source software that makes the final translation into the language understood by the
microcontroller. Arduino makes your life simple by hiding away most of the complexities of
programming microcontrollers.
The programming cycle on Arduino is basically as follows:
i Plug your board into a USB port on your computer.
ii Write a sketch that will bring the board to life.
iii Upload this sketch to the board through the USB connection and wait a couple of seconds
for the board to restart.
iv The board executes the sketch that you wrote.

Getting started with Arduino

Installing the IDE


• To program the Arduino board, you must first install the IDE by downloading the appropriate
file from the Arduino website. Choose the right version for your operating system, and then
proceed with the appropriate instructions.

• When the file download has finished, double-click to open the installer and follow the instruc-
tions.
• After the files are installed, a window will pop up asking for permission to install the drivers.
Click Install. When the installer has completed, click Close to finish.

2
NUCES, Islamabad Digital Logic Design Lab, Spring 2019

Port Identification

Now that the driver has been configured, you need to select the proper port to communicate
with the Arduino Uno.
• Run the Arduino IDE, either using a desktop shortcut or the Start menu.
• From the Tools menu in the Arduino IDE, select Serial Port. You will see one or more COM
ports with different numbers. Make a note of which numbers are available.
• Now unplug your Arduino from your computer, look at the list of ports again, and see which
COM port vanishes. It might take a moment or two, and you may have to leave the Tools
menu and open it again to refresh the list of ports.
• Once you have figured out the COM port assignment, you can select that port from the Tools
go to Serial Port menu in the Arduino IDE.

Experiment 01

The LED blinking sketch is the first program that we will run to test whether the Arduino board
is working and is configured correctly. We will integrate a single LED in this task and let it blink
continuously with a noticeable delay. The circuit and code required for this is given in the upcoming
sections.

Circuit Detail
The Arduino board comes with an LED preinstalled. It is marked L on the board. This preinstalled
LED is connected to pin number 13. But for this experiment we will connect our own LED as shown
in figure 2. As this is the simplest testing experiment, we are not building a huge circuit at the
start and will move slowly towards a little more advanced example in the upcoming labs.

Figure 2: Connecting an LED to Arduino

3
NUCES, Islamabad Digital Logic Design Lab, Spring 2019

K indicates the cathode (negative), or shorter lead; A indicates the anode (positive), or longer lead.
Note that its plugged into the connector hole that is labeled 13.

Code
On your computer, run the Arduino IDE. Select File - New and choose a sketch folder name: this
is where your Arduino sketch will be stored. Name the sketch without any extension and type the
following sketch into the Arduino sketch editor

const i n t LED = 1 3 ;

void s e t u p ( ) {
pinMode (LED, OUTPUT) ;
}

void l o o p ( ) {
d i g i t a l W r i t e (LED, HIGH ) ;
delay (1000);
d i g i t a l W r i t e (LED, LOW) ;
delay (1000);
}

Figure 3: The Arduino IDE with your first sketch loaded

1. Verify: Now that the code is in your IDE, you need to verify that it is correct. Click
the Verify button shown in figure 3 if everything is correct, you will see the message Done

4
NUCES, Islamabad Digital Logic Design Lab, Spring 2019

compiling appear at the bottom of the Arduino IDE. This message means that the Arduino
IDE has translated the sketch into an executable program that can be run by the board, a
bit like an .exe file in Windows.
2. Upload: Once your code verifies correctly, you can upload it into the board by clicking the
Upload button shown in figure 3. This will tell the IDE to start the upload process, which first
resets the Arduino board, forcing it to stop what its doing and listen for instructions coming
from the USB port. The Arduino IDE will then send the sketch to the Arduino board, which
will store the sketch in its permanent memory. Once the IDE has sent the entire sketch, the
Arduino board will start running your sketch.

Sketch Details:
1. setup() where you put all the code that you want to execute once at the beginning of your
program.

2. loop() contains the core of your program, which is executed over and over again.
3. pinMode() tells Arduino how to configure a certain pin. Digital pins can be used either as
input or output, but we need to tell Arduino how we intend to use the pin. In this case, we
need an output pin to control our LED.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy