0% found this document useful (0 votes)
5 views9 pages

Getting started with Arduino by BGN

The document provides an introduction to Arduino, a small programmable computer used for various electronic projects. It covers the Arduino Uno board, its components, and how to set it up, including using breadboards and jumper wires. Additionally, it explains programming the Arduino using the Arduino IDE and includes a simple project to blink an LED as a practical demonstration.
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)
5 views9 pages

Getting started with Arduino by BGN

The document provides an introduction to Arduino, a small programmable computer used for various electronic projects. It covers the Arduino Uno board, its components, and how to set it up, including using breadboards and jumper wires. Additionally, it explains programming the Arduino using the Arduino IDE and includes a simple project to blink an LED as a practical demonstration.
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/ 9

PKFokam Institute of Excellence

School of Science and Technology


Department of Electrical and Telecommunication Engineering
Introduction to Mechatronics Engineering Lab MTRE 1000L

Getting started with Arduino

1. Introduction
The Arduino is a small, inexpensive computer that can be programmed to control endless
creations limited only by your imagination. As you’ll soon see, the Arduino can be used to make a
whole host of projects, like a ghost detector, joystick-controlled laser, electronic die, laser trip wire
alarm, motion sensor alarm, keypad entry system, and many others. All of these projects are easy to
build and have one thing in common: they use the power of the Arduino.

2. The Arduino Revolution

In simple terms, the Arduino is a small computer that can be programmed to connect and control
various electronic parts. The Arduino has a number of pins that can be set as either input, which
means they can receive data from items such as switches, buttons, and sensors, or output, which
means they send data to control items such as motors, lights, and buzzers. This type of programmable
development board is better known as a microcontroller.

The Arduino project began in Ivrea, Italy, in 2005 with the goal of creating a device to control
student-built interactive design projects that would be less expensive than other prototyping
systems available at the time. Founders Massimo Banzi and David Cuartielles named the project
after a local bar called Arduino (an Italian masculine first name meaning “strong friend”).

The Arduino board is composed of two main elements:

 the hardware, or microcontroller, which is the brain of the board,


 and the software that you’ll use to send your program to the brain. The software is called the
Arduino integrated development environment (IDE),

The Arduino can be powered by batteries, USB, or an external power supply. Once the Arduino is
programmed, it can be disconnected from your computer and will run independently using a power
supply or batteries.

Page 1
Project 0: GETTING STARTED WITH ARDUINO
0.1 Hardware

First let’s look at the Arduino Uno board and a few pieces of hardware that you’ll use in almost every
project.

0.2 The Arduino uno

There are numerous types of Arduino boards available, but here we will exclusively use the most
popular one: the Arduino Uno, shown in Figure 0.1. The Arduino Uno is open source (meaning its
designs may be freely copied). Let’s walk through the different elements of the Arduino Uno.

Figure 0.1: The Arduino Uno

The Arduino controls components you attach to it, like motors or LEDs, by sending information to
them as output (information sent out from the Arduino). Data that the Arduino reads from a sensor
is input (information going into the Arduino). There are 14 digital input/output pins (pins 0–
13). Each can be set to either input or output, and Appendix B has a full pin reference table.

Page 2
0.3 Power

The Arduino Uno board is powered from your computer’s USB port when you connect it to your PC
to upload a program. When the Arduino is not linked to your PC, you can run it independently by
connecting a 9-volt AC adapter or 9-volt battery pack with a 2.1 mm jack, with the centre pin
connected to the positive wire, shown in Figure 0-2. Simply insert the jack into the power socket of
the Arduino.

Figure 0.2: 9V Arduino battery adapter


0.4 Breadboards
A breadboard acts as a construction base for electronics prototyping. All of the projects in this course
start with the use of a breadboard instead of soldering. The word breadboard dates back to when
electronics projects were created on wooden boards. Nails were hammered into the wood and wires
wrapped around them to connect components without the use of solder. Today’s breadboards, such
as the one shown in Figure 0.3, are made of plastic with predrilled holes (called tie points) into which
you insert components or wires that are held in place by clips. The holes are connected by strips of
conductive material that run underneath the board.

Figure 0.3: A Breadboards

Page 3
Breadboards come in various sizes. To build some of the projects in this course, you’ll need four
breadboards: two full-size, typically with 830 holes; one half-size with 420 holes; and one mini with
170 holes. The full-size breadboard is ideal for projects that use an LCD screen or a lot of components,
and the half-size and mini boards are best for smaller projects.

The main board area of the breadboard shown in Figure 0.3 has 30 columns of tie points that are
connected vertically. There is a break in the center of the board, which you’ll often have to straddle
with components to make your circuit. This break helps to connect the pins individually so they are
not shorted together unintentionally, which can doom your project and even damage your
components. The blue and red lines at the top and bottom are power rails that you use to power the
components inserted in the main breadboard area (see Figure 0.4). The power rails connect all the
holes in the rail horizontally; the red lines are for positive power and the blue lines for negative
power (or ground, as you’ll often see it referred to).

Figure 0.4: Power rails of a breadboard


0.5 Jumper wires

You’ll use jumper wires to make connections on the breadboard. Jumper wires are solid-core wires
with a molded plastic holder on each end that makes it easier to insert and remove the wires. (You
could use your own wire if you have it, but make sure to use solid core wire, as stranded wire is not
strong enough to push into the hole clips). When you insert a jumper wire into a breadboard hole,
it’s held in place beneath the board by a small spring clip, making an electrical connection in that row
that typically consists of five holes. You can then place a component in an adjoining hole to help create
a circuit, as shown in Figure 0.5.

Page 4
Figure 0.5: Use of Jumpers on a breadboard

0.6 Programming the Arduino

To make our projects do what we want, we need to write programs that give the Arduino instructions.
We do so using a tool called the Arduino integrated development environment (IDE). It enables you
to write computer programs (a set of step-by-step instructions, known as sketches in the Arduino
world) that you then upload to the Arduino using a USB cable. Your Arduino will carry out the
instructions based on its interaction with the outside world.

0.7 The ide interface

When you open the Arduino IDE, it should look very similar to Figure 0.6. The IDE is divided into a
toolbar at the top, with buttons for the most commonly used functions; the code or sketch window in
the centre, where you’ll write or view your programs; and the Serial Output window at the bottom.
The Serial Output window displays communication messages between your PC and the Arduino, and
will also list any errors if your sketch doesn’t compile properly.

Page 5
Figure 0.6: Arduino IDE

0.8 Arduino sketches

I’ll give you the sketch for each project within the relevant project, and talk through it there. All of
the sketches are available to download from http://www.nostarch.com/arduinohandbook/. Like
any program, sketches are a very strict set of instructions, and very sensitive to errors. To make
sure you’ve copied the sketch correctly, press the green check mark at the top of the screen. This is
the Verify button, and it checks for mistakes and tells you in the Serial Output window whether the
sketch has compiled correctly. If you get stuck, you can always download the sketch and then copy
and paste it into the IDE.

0.9 Libraries

In the Arduino world, a library is a small piece of code that carries out a specific function. Rather than
enter this same code repeatedly in your sketches, you can add a command that borrows code from
the library. This shortcut saves time and makes it easy for you to connect to items such as a sensor,
display, or module.

The Arduino IDE includes a number of built-in libraries, such as the Liquid Crystal library, which
makes it easy to talk to LCD displays and there are many more available online. To create some of the
projects for this course, you will need to import the following libraries: RFID, Tone, Pitches, Keypad,

Page 6
Password, Ultrasonic, New Ping, IR Remote, and DHT. You’ll find all of the libraries you need at
http://www.nostarch.com/arduinohandbook/. Once you’ve downloaded the libraries, you’ll need to
install them.

To install a library in Arduino version 1.0.6 and higher, follow these steps:

1. Choose Sketch → include Library → Add .ZiP Library.


2. Browse to the ZIP file you downloaded and select it. For older versions of Arduino, you’ll need
to unzip the library file and then put the whole folder and its contents into the
sketchbook/libraries folder on Linux, My Documents\ Arduino\ Libraries on Windows, or
Documents/Arduino/libraries on OS X.

To install a library manually, go to the ZIP file containing the library and uncompressed it. For
example, if you were installing a library called “keypad” in a compressed file called keypad.zip, you
would uncompressed keypad.zip, which would expand into a folder called keypad, which in turn
contains files like keypad.cpp and keypad.h. Once the ZIP file was expanded, you would drag the
keypad folder into the libraries folder on your operating system: sketchbook/libraries in Linux, My
Documents\ Arduino\ Libraries on Windows, and Documents/Arduino/libraries on OS X. Then
restart the Arduino application.

Libraries are listed at the start of a sketch and are easily identified because they begin with the
command #include. Libraries are surrounded by angle brackets, <>, and end with .h, as in the
following call to the Servo library: #include <Servo.h>. Go ahead and install the libraries you’ll need
for the others projects the teacher will give you.

0.10 Testing your Arduino: Blinking a led

Now that you’ve seen the hardware and software, let’s begin our tour with the classic first Arduino
project: blinking a light emitting diode (LED). Not only is this the simplest way to make sure that your
Arduino is working correctly, but it will also introduce you to a simple sketch. As we mentioned
earlier, a sketch is just a series of instructions that run on a computer. The Arduino can hold only one
sketch at a time, so once you upload your sketch to your Arduino, that sketch will run every time the
Arduino is switched on until you upload a new one.

For this project we’ll use the Blink example sketch that comes with the Arduino IDE. This program
turns on an LED for 1 second and then off for 1 second, repeatedly. An LED emits light when a small
current is passed through it. The LED will work only with current flowing in one direction, so the
longer wire must connect to a positive power connection. LEDs also require a current limiting
resistor; otherwise, they may burn out. There is a built-in resistor in line with pin 13 of the Arduino.

Follow these steps to set up your test:

Page 7
1. Insert the long positive leg (also known as +5V or anode) of the LED into pin 13 on the
Arduino, as shown in Figure 0.7. Connect the short negative leg (also known as cathode) to
the GND pin next to pin 13.

Figure 0.7: Illustration Diagram


2. Connect the Arduino to your computer with the USB cable; Figure 0.7.
3. Enter the following sketch into the IDE.

4. Click the Verify button (which looks like a check mark) to confirm that the sketch is working
correctly.
5. Now click the upload button to send the sketch to your Arduino.

0.11 Understanding the Sketch


Here’s what’s happening on each line of the sketch:
1. This is a comment. Any line in your program starting with //is meant to be read by the user
only, and is ignored by the Arduino, so use this technique to enter notes and describe your
code (called Commenting your code). If a comment extends beyond one line, start the first line
with /*and end the comment with */. Everything in between will be ignored by the Arduino.
2. This gives pin 13 the name led. Every mention of led in the sketch refers to pin 13.
3. This means that the code between the curly brackets, { }, that follow this statement will run
once when the program starts. The open curly bracket, {, begins the setup code.

Page 8
4. This tells the Arduino that pin 13 is an output pin, indicating that we want to send power to
the LED. The close curly bracket, { }, ends the setup code.
5. This creates a loop. Everything between the curly brackets, { }, after the loop () statement will
run once the Arduino is powered on and then repeat until it is powered off.
6. This tells the Arduino to set led (pin 13) to HIGH, which sends power to that pin. Think of it
as switching the pin on. In this sketch, this turns on the LED.
7. This tells the Arduino to wait for 1 second. Time on the Arduino is measured in milliseconds,
so 1 second = 1,000 milliseconds.
8. This tells the Arduino to set led (pin 13) to LOW, which removes power and switches off the
pin. This turns off the LED.
9. Again the Arduino is told to wait for 1 second.
10. This closing curly bracket ends the loop. All code that comes after the initial setup must be
enclosed within curly brackets. A common cause of errors in a sketch is missing open or close
brackets, which will prevent your sketch from compiling correctly. After this curly bracket,
the sketch goes back to the start of the loop at 1.

Running this code should make your LED flash on and off. Now that you’ve tested your Arduino and
understand how a sketch works and how to upload it, we’ll take a look next at the components you’ll
need to carry out all of the projects in this book. Appendix A has more details about each component,
what it looks like, and what it does.

Page 9

You might also like