100% found this document useful (1 vote)
137 views14 pages

Getting Started With Arduino

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 14

Chapter 1

Getting Started with Arduino

1.1 Introduction

In 2005, Massimo Banzi, David Cuartielles, Tom Igoe, Gianluca Martino, and
David Mellis came up with an idea for an easy-to-use programmable device for
interactive art design projects at the Interaction Design Institute Ivrea in Ivrea, Italy.
The device needed to be simple, easy to connect to various things (such as relays,
motors, and sensors), and easy to program. It also needed to be inexpensive to make
it cost-effective for students and artists. They selected an AVR family of 8-bit
microcontroller (MCU or µC) devices from Atmel and designed a self-contained
circuit board with easy-to-use connections, wrote bootloader firmware for the
microcontroller, and integrated it all into a simple development environment that
used programs called “sketches.” The result was Arduino.
Arduino is an open-source microcontroller that enables programming and
interaction; it is programmed in C/C++ with an Arduino library to allow it to access
the hardware. This allows for more flexible programmability and the ability to use
electronics that can interface with Arduino. Because Arduino is open source, the
plans for the circuits are available online for free to anyone who wants to use and
create their own board based on the schematics, as long as they share what they
create. This allows for considerable customizability in projects; till date, users have
built Arduinos of different sizes, shapes, and power levels to control their projects.
Arduino is composed of two major parts:
1. The Arduino board, which is a piece of hardware you work on when you build
your objects.
2. The Arduino IDE, which is a piece of software you run on your computer. You
use the IDE to create a sketch (a small computer program) that you upload to the
Arduino board.
Arduino is different from other platforms in the market because of the following
features:

© Springer Nature Singapore Pte Ltd. 2018 3


T. Pan and Y. Zhu, Designing Embedded Systems with Arduino,
DOI 10.1007/978-981-10-4418-2_1
4 1 Getting Started with Arduino

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


Linux.
2. It is based on a processing programming IDE, which is an easy-to-use devel-
opment environment used by artists and designers.
3. You program it via a USB cable, not a serial port. This feature is useful, because
many modern computers do not have serial ports.
4. It is open-source hardware and software—if you wish, you can download the
circuit diagram, buy all the components, and make your own Arduino board,
without paying anything to the makers of Arduino.
5. The hardware is cheap.
6. There is an active community of users, so there are many people who can assist
you.
7. The Arduino project was developed in an educational environment, and is
therefore, great for newcomers to get things working quickly.
Owing to these special features, there are many potential applications:
1. Real-world monitoring
• Automated weather station
• Lightning detection
• Sun tracking for solar panels
• Background radiation monitor
• Automatic wildlife detector
• Home or business security system
2. Small-scale control
• Small robots
• Model rockets
• Model aircrafts
• Quadrotor UAVs
• Simple CNCs for small machine tools
3. Small-scale Automation
• Automated greenhouse
• Automated aquarium
• Laboratory sample shuttle
• Precision thermal chamber
• Automated electronic test system
4. Performance Art
• Dynamic lighting control
• Dynamic sound control
• Kinematic structures
• Audience responsive artwork
1.2 Arduino Variants 5

1.2 Arduino Variants

Arduino is rapidly becoming one of the most popular microcontrollers used in


robotics. There are many different types of Arduino microcontrollers that differ not
only in design and features, but also in size and processing capabilities. However,
there are only two models that use completely different chips: the Standard and the
Mega. The Standard is the basic Arduino that uses the Atmega8/168/328 chip,
whereas the Mega is a different Arduino board with more I/O pins and uses the
beefier Atmega1280 chip.
The makers of Arduino also developed software that is compatible with all
Arduino microcontrollers. The software, also called “Arduino,” can be used to
program any of the Arduino microcontrollers by selecting them from a drop-down
menu. Being open source, and based on C, Arduino users are not necessarily
restricted to this software, and can use a variety of other software to program their
microcontrollers.
There are many additional manufacturers who use open-source schematics
provided by Arduino to make their own boards (either identical to the original, or
with variations to add to the functionality), e.g., DFRobot.
In this chapter, the Arduino Uno R3 and DFRobot Romeo BLE boards are
introduced.
1. Arduino Uno R3
The Arduino Uno is a microcontroller board based on the ATmega328. It has 14
digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs,
a 16 MHz ceramic resonator, a USB connection, a power jack, an ICSP header, and
a reset button. It contains everything needed to support the microcontroller; simply
connect it to a computer with a USB cable or power it with an AC-to-DC adapter or
battery to get started. Central to the Arduino interface board, shown in Fig. 1.1, is
an onboard microcontroller.
Specifications of the Arduino UNO R3 are as follows:
• Microcontroller: ATmega328
• Operating Voltage: 5 V
• Input Voltage (recommended): 7–12 V
• Input Voltage (limits): 6–20 V
• Digital I/O Pins: 14 (of which 6 provide PWM outputs)
• Analog Input Pins: 6
• DC Current per I/O Pin: 40 mA
• DC Current for 3.3 V Pin: 50 mA
• Flash Memory: 32 KB of which 0.5 KB is used by the bootloader
• SRAM: 2 KB (ATmega328)
• EEPROM: 1 KB (ATmega328)
• Clock Speed: 16 MHz (Fig. 1.2)
6 1 Getting Started with Arduino

Digital Digital I/O In


Ground
Analog Reference

Interrupt 1
Interrupt 0
(SPI)MISO
(SPI)MOSI
(I2C)SCL
(I2C)SDA
In-circuit Serial

(SPI)SCK

(SPI)SS
Programmer for USB Serial Out (TX)
interface Serial In (RX)

Reset Button

In-circuit Serial
USB to Programmer for
Computer Atmega328
MISO VCC
SCK MOSI
/RESET GND

7-12V DC
Input

(I2C)SDA
(I2C)SCL
Reset
Ground
3.3V Power
5V Power Voltage
In
Analog In

Fig. 1.1 Arduino UNO interface board

The Arduino Uno pinout is printed in the silkscreen in the top section. While this
pinout is a good start, it is not a comprehensive guide. At first, you mainly use the
pins in the female headers at the edge of the board (top and bottom in the photo), as
well as the USB, and maybe the power
Tx and Rx are serial UART pins used for RS-232 and USB communications
I2C is another serial communications method that uses a bidirectional data line
(SDA) and a clock line (SCL)
SPI is another serial communications method that uses one line for the master to
transmit (MOSI—Master Out Slave In), another for the master to receive (MISO),
and a third as a clock (SCK)
A/D, the Analog to Digital input, converts an analog voltage into a digital
representation
PWM (Pulse Width Modulator) is used to create a square wave with a specific duty
cycle (high time vs low time)
ICSP is the In Circuit Serial Programming—another way to program the processor
Vcc is the voltage supplied to the processor (+5VDC regulated from a higher input
voltage)
3.3VDC is a regulated voltage (from the higher input voltage) for peripherals
requiring that voltage—50 mA maximum
1.2 Arduino Variants 7

Fig. 1.2 Arduino Uno R3 pinout diagram

IOREF provides a voltage reference so shields can select the proper power source
AREF is a reference INPUT voltage used by the A/Ds
GND is the ground reference
RESET resets the processor (and some peripherals)
2. DFRobot RoMeo BLE
The DFRobot Romeo BLE All-in-one Microcontroller (ATMega 328) is an
all-in-one Arduino-compatible microcontroller specifically designed for robotic
applications. It benefits from the Arduino open-source platform; it is supported by
thousands of open-source codes, and can easily be expanded with your
Arduino-compatible shields.
This robot controller uses an Atmel ATmega328p as the main microcontroller. It
comes preprogrammed with an Arduino bootloader for compatibility with the
user-friendly Arduino Uno platform.
A secondary Texas Instruments CC2540 microcontroller handles the BLE
Bluetooth Low Energy communication services. It comes preprogrammed with a
firmware that supports transparent serial over Bluetooth and an AT command
interpreter. Both microcontrollers are full programmable.
The Romeo robot controller contains a built in L298 dual channel motor driver
chip. This motor driver can be used to drive two 5–23 V DC motors at up to 2
amps. Screw terminals are provided for connecting two motors and an external
motor power supply.
8 1 Getting Started with Arduino

The Romeo BLE microcontroller board also has a large number of pin headers to
simplify connections to your robot project. A full set of 3-pin analog and digital
GPIO headers provide access to signal, voltage, and ground lines at each connec-
tion to simplify wiring arrangements. The digital GPIO headers can also be used to
drive servos and a screw terminal can provide an external servo power supply.
A full set of Arduino Uno compatible headers allow you to choose from a large
number of Arduino-compatible shields for expansion. A triplet of I2C connectors is
also provided.
Additional features include five optional user push buttons, a reset button, and a
number of LED status indicators to assist with diagnostics. The optional user
buttons are conveniently wired to a single analog input. They can be enabled or
disabled via a slider switch (Fig. 1.3).

Fig. 1.3 Romeo BLE interface board


1.2 Arduino Variants 9

Specifications of the RoMeo BLE are as follows:


• Microcontroller: ATmega328P
• Bootloader: Arduino UNO
• Onboard BLE chip: TI CC2540
• 14 Digital I/O ports
• 6 PWM Outputs (Pin11, Pin10, Pin9, Pin6, Pin5, Pin3)
• 8 10-bit analog input ports
• 3 I2Cs
• Two way H-bridged motor driver with 2A maximum current
• 5 Buttons
• Power Supply Port: USB or DC2.1
• External Power Supply Range: 5–23 V
• DC output: 5 V/3.3 V
• Auto sensing/switching external power input
• Size: 94 mm  80 mm

1.3 Install the Drivers

Before beginning your work, you must first download the development environ-
ment (the IDE) from here: www.arduino.cc/en/Main/Software.
1. Choose the right version for your operating system.
2. Download the file and double-click on it to open it; on Windows or Linux, this
creates a folder named Arduino-[version], such as arduino-1.0.
3. Drag the folder to wherever you want it: your desktop, your Program Files
folder (on Windows), etc. On the Mac, double-clicking it will open a disk image
with an Arduino application (drag it to your Applications folder).
4. Whenever you want to run the Arduino IDE, you will need to open up the
Arduino (Windows and Linux) or Applications folder (Mac), and double-click
the Arduino icon. Do not do this yet, though; there is one more step.
5. You must install the drivers that allow your computer to communicate with your
board through the USB port (Fig. 1.4).
10 1 Getting Started with Arduino

Fig. 1.4 The dialog box of “Found New Hardware Wizard”

Plug the Arduino board into the computer; when the Found New Hardware
Wizard window comes up. The Found New Hardware Wizard will open up as
Windows will have detected that you have connected a new piece of hardware
(your DFRobot Remeo board) to your PC. Tell it NOT to connect to Windows
update (Select No, not at this time) and then click Next.
On the next page, select “Install from a list or specific location (Advanced)”
and click Next (Fig. 1.5).
Make sure that “Search for the best driver in these locations” is checked.
Uncheck “Search removable media.” Check “Include this location in the
search” and then click the Browse button. Browse to the location of the USB
drivers and then click Next (Fig. 1.6).
1.3 Install the Drivers 11

Fig. 1.5 Select “Install from a list or specific location (Advanced)”

Fig. 1.6 Select “Search for the best driver in these locations”
12 1 Getting Started with Arduino

Fig. 1.7 Completing the found new hardware wizard

The wizard will now search for a suitable driver and then inform you that a
“USB Serial Convertor” has been found and that the hardware wizard is now
complete. Click “Finish.”
Now, you are ready to upload your first Sketch (Fig. 1.7).

1.4 Arduino IDE

The IDE is split up into the Toolbar across the top, the code, or Sketch Window in
the center and the Serial Output window at the bottom (Fig. 1.8).
The Toolbar consists of 5 buttons, underneath the Toolbar is a tab, or a set of
tabs, with the filename of the code within the tab. There is also one more button on
the far right hand side. Along the top is the file menu with drop-down menus with
the headers File, Edit, Sketch, Tools, and Help. The buttons in the Toolbar provide
convenient access to the most commonly used functions within this file menu.
The Toolbar buttons are listed above. The functions of each button are as follows
(Table 1.1):
1.4 Arduino IDE 13

Upload Open

Verify New Save Serial Monitor

Code goes here

Board Serial Port

Fig. 1.8 Arduino IDE

Table 1.1 Toolbar buttons list


Verify/compile Checks the code for errors

New Creates a new blank Sketch

Open Shows a list of Sketches in your sketchbook

Save Saves the current Sketch

Upload Uploads the current Sketch to Arduino

Serial Monitor Displays serial data being sent from Arduino


14 1 Getting Started with Arduino

Fig. 1.9 “Blink” example in Arduino IDE

Fig. 1.10 Board type selection in Arduino IDE


1.4 Arduino IDE 15

Now, you are ready to test your first program with your Arduino board.
1. Open the Blink example sketch by going to: File ! Examples ! 01.
Basics ! Blink (Fig. 1.9).
2. Select the type of Arduino board you are using: Tools ! Board ! your board
type (Fig. 1.10).
3. Select the serial port that your Arduino is attached to: Tools ! Port ! COMxx
(Fig. 1.11).
4. If you are not sure which serial device is your Arduino, have a look at the
available ports, then unplug your Arduino and look again. The one that dis-
appeared is your Arduino.
5. With your Arduino board connected, and the Blink sketch open, press the
“Upload” button (Fig. 1.12).

Fig. 1.11 Serial port selection in Arduino IDE


16 1 Getting Started with Arduino

Fig. 1.12 Default codes of


“Blink”

6. After a second, you should see some LEDs flashing on your Arduino, followed
by the message “Done Uploading” in the status bar of the Blink sketch.
7. If everything worked, the onboard LED on your Arduino should now be
blinking! You just programmed your first Arduino!

You might also like