Docsity
Docsity

Prepare-se para as provas
Prepare-se para as provas

Estude fácil! Tem muito documento disponível na Docsity


Ganhe pontos para baixar
Ganhe pontos para baixar

Ganhe pontos ajudando outros esrudantes ou compre um plano Premium


Guias e Dicas
Guias e Dicas


arduino - book4, Notas de estudo de Eletrônica

arduino-book4

Tipologia: Notas de estudo

2017

Compartilhado em 07/11/2017

vinicius-tomaz-4
vinicius-tomaz-4 🇧🇷

4.5

(2)

14 documentos

1 / 441

Toggle sidebar

Esta página não é visível na pré-visualização

Não perca as partes importantes!

bg1
iv
Contents at a Glance
About the Author .................................................................................................... xvii
About the Technical Reviewer ............................................................................... xviii
Acknowledgments ................................................................................................... xix
Introduction .............................................................................................................. xx
Chapter 1: Introduction ........................................................................................... 1
Chapter 2: Light ’Em Up ......................................................................................... 21
Chapter 3: LED Effects ........................................................................................... 51
Chapter 4: Simple Sounders and Sensors ............................................................. 81
Chapter 5: Driving a DC Motor ............................................................................... 99
Chapter 6: Binary Counters ................................................................................. 111
Chapter 7: LED Displays ....................................................................................... 129
Chapter 8: Liquid Crystal Displays ....................................................................... 171
Chapter 9: Servos ................................................................................................ 191
Chapter 10: Steppers and Robots ........................................................................ 207
Chapter 11: Pressure Sensors ............................................................................. 231
Chapter 12: Touch Screens
.................................................................................. 259
Chapter 13: Temperature Sensors
....................................................................... 279
Chapter 14: Ultrasonic Rangefinders ................................................................... 293
Chapter 15: Reading and Writing to an SD Card ................................................. 317
Chapter 16: Making an RFID Reader .................................................................... 343
Chapter 17: Communicating over Ethernet.......................................................... 359
Index ....................................................................................................................... 417
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Pré-visualização parcial do texto

Baixe arduino - book4 e outras Notas de estudo em PDF para Eletrônica, somente na Docsity!

iv

Contents at a Glance

About the Author .................................................................................................... xvii

About the Technical Reviewer ............................................................................... xviii

Acknowledgments ................................................................................................... xix

Introduction .............................................................................................................. xx

■Chapter 1: Introduction ........................................................................................... 1

■Chapter 2: Light ’Em Up ......................................................................................... 21

■Chapter 3: LED Effects ........................................................................................... 51

■Chapter 4: Simple Sounders and Sensors ............................................................. 81

■Chapter 5: Driving a DC Motor ............................................................................... 99

■Chapter 6: Binary Counters ................................................................................. 111

■Chapter 7: LED Displays ....................................................................................... 129

■Chapter 8: Liquid Crystal Displays....................................................................... 171

■Chapter 9: Servos ................................................................................................ 191

■Chapter 10: Steppers and Robots ........................................................................ 207

■Chapter 11: Pressure Sensors ............................................................................. 231

■Chapter 12: Touch Screens .................................................................................. 259

■Chapter 13: Temperature Sensors ....................................................................... 279

■Chapter 14: Ultrasonic Rangefinders ................................................................... 293

■Chapter 15: Reading and Writing to an SD Card ................................................. 317

■Chapter 16: Making an RFID Reader .................................................................... 343

■Chapter 17: Communicating over Ethernet.......................................................... 359

Index ....................................................................................................................... 417

v

Contents

About the Author .................................................................................................... xvii

About the Technical Reviewer ............................................................................... xviii

Acknowledgments ................................................................................................... xix

Introduction .............................................................................................................. xx

■Chapter 1: Introduction ........................................................................................... 1

How to Use This Book ........................................................................................................ 1

What You Will Need ........................................................................................................... 2

What Exactly is an Arduino? .............................................................................................. 3

Getting Started................................................................................................................... 6

Windows XP Installation ........................................................................................................................... 7 Windows 7 & Vista Installation ................................................................................................................. 7 Mac OSX Installation................................................................................................................................. 7 Board and Port Selection .......................................................................................................................... 8

Upload Your First Sketch ................................................................................................. 10

The Arduino IDE ............................................................................................................... 12

■Chapter 2: Light ’Em Up ......................................................................................... 21

Project 1 – LED Flasher ................................................................................................... 21

Parts Required ........................................................................................................................................ 21 Connecting Everything ............................................................................................................................ 22 Enter the Code ........................................................................................................................................ 23

■ CONTENTS

■ CONTENTS

■ CONTENTS

■ CONTENTS

■ CONTENTS

■ CONTENTS

■ CONTENTS

 - Project 1 – LED Flasher – Code Overview vi - Project 1 – LED Flasher – Hardware Overview 
  • Project 2 – S.O.S. Morse Code Signaler...........................................................................
    • Project 2 – S.O.S. Morse Code Signaler – Code Overview
  • Project 3 – Traffic Lights
    • Parts Required
    • Connect It Up
    • Enter the Code
  • Project 4 – Interactive Traffic Lights................................................................................
    • Parts Required
    • Connect It Up
    • Enter the Code
    • Project 4 – Code Overview
    • Project 4 – Interactive Traffic Lights - Hardware Overview
    • Logic States
    • Pull-Down Resistors
    • Pull-Up Resistors
    • The Arduino’s Internal Pull-Up Resistors
  • Summary
  • ■Chapter 3: LED Effects
    • Project 5 – LED Chase Effect
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 5 – LED Chase Effect – Code Overview
    • Project 6 – Interactive LED Chase Effect
      • Parts Required
      • Connect It Up
      • Enter The Code vii
      • Project 6 – Interactive LED Chase Effect – Code Overview
      • Project 6 – Interactive LED Chase Effect – Hardware Overview.............................................................
    • Project 7 – Pulsating Lamp
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 7 – Pulsating Lamp – Code Overview
    • Project 8 – RGB Mood Lamp
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 8 – RGB Mood Lamp – Code Overview
    • Project 9 – LED Fire Effect
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 9 – LED Fire Effect – Code Overview
    • Project 10 – Serial Controlled Mood Lamp
      • Enter the Code
      • Project 10 – Serial Controlled Mood Lamp – Code Overview
    • Summary
  • ■Chapter 4: Simple Sounders and Sensors
    • Project 11 – Piezo Sounder Alarm
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 11 – Piezo Sounder Alarm – Code Overview viii
      • Project 11 – Piezo Sounder Alarm – Hardware Overview
    • Project 12 – Piezo Sounder Melody Player
      • Enter the Code
      • Project 12 – Piezo Sounder Melody Player – Code Overview
    • Project 13 – Piezo Knock Sensor
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 13 – Piezo Knock Sensor – Code Overview
    • Project 14 – Light Sensor
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 14 – Light Sensor – Hardware Overview
    • Summary
      • Subjects and Concepts covered in Chapter 4:
  • ■Chapter 5: Driving a DC Motor
    • Project 15 – Simple Motor Control...................................................................................
      • Parts Required
      • Connect It Up
      • Enter The Code
      • Project 15 – Simple Motor Control – Code Overview............................................................................
      • Project 15 – Simple Motor Control – Hardware Overview
    • Project 16 – Using an L293D Motor Driver IC
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 16 – Using an L293D Motor Driver IC – Code Overview ix
      • Project 16 – Using an L293D Motor Driver IC – Hardware Overview
    • Summary
      • Subjects and concepts covered in Chapter
  • ■Chapter 6: Binary Counters
    • Project 17 – Shift Register 8-Bit Binary Counter
      • Parts Required
      • Connect It Up
      • Enter The Code
      • The Binary Number System
      • Project 17 – Shift Register 8-Bit Binary Counter - Hardware Overview
      • Project 17 – Shift Register 8-Bit Binary Counter – Code Overview
      • Bitwise Operators
      • Project 17 – Code Overview (continued)
    • Project 18 – Dual 8-Bit Binary Counters
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 18 - Code & Hardware Overview
    • Summary
      • Subjects and Concepts covered in Chapter
  • ■Chapter 7: LED Displays
    • Project 19 – LED Dot Matrix Display – Basic Animation
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 19 – LED Dot Matrix – Basic Animation – Hardware Overview
      • Project 19 – LED Dot Matrix – Basic Animation – Code Overview
    • Project 20 – LED Dot Matrix Display – Scrolling Sprite x
      • Enter the Code
      • Project 20 – LED Dot Matrix – Scrolling Sprite – Code Overview .......................................................
    • Project 21 – LED Dot Matrix Display – Scrolling Message
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 21 – LED Dot Matrix – Scrolling Message – Hardware Overview ............................................
      • Project 21 – LED Dot Matrix – Scrolling Message – Code Overview
    • Project 22 – LED Dot Matrix Display – Pong Game
      • Parts Required
      • Connect It Up
      • Upload the Code
      • Project 22 – LED Dot Matrix – Pong Game
    • Summary
      • Subjects and concepts covered in Chapter 7:
  • ■Chapter 8: Liquid Crystal Displays.
    • Project 23 – Basic LCD Control
      • Parts Required
      • Connect It Up
      • Enter The Code
      • Project 23 – Basic LCD Control – Code Overview
      • Project 23 – Basic LCD Control – Hardware Overview
    • Project 24 – LCD Temperature Display
      • Parts Required
      • Connect It Up
      • Enter The Code
      • Project 24 – LCD Temperature Display – Code Overview ...................................................................
    • Summary xi
      • Subjects and Concepts Covered in Chapter 8.......................................................................................
  • ■Chapter 9: Servos
    • Project 25 – Servo Control
      • Parts Required
      • Connect It Up
      • Enter The Code
      • Project 25 – Servo Control – Code Overview
      • Project 25 – Servo Control – Hardware Overview
    • Project 26 – Dual Servo Control
      • Parts Required
      • Connect It Up
      • Enter The Code
      • Project 26 – Dual Servo Control – Code Overview................................................................................
    • Project 27 – Joystick Servo Control
      • Parts Required
      • Connect It Up
      • Enter The Code
      • Project 27 – Joystick Servo Control – Code Overview..........................................................................
    • Summary
      • Subjects and Concepts Covered in Chapter 9.......................................................................................
  • ■Chapter 10: Steppers and Robots
    • Project 28 – Basic Stepper Control
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 28 – Basic Stepper Control – Code Overview
      • Project 28 – Basic Stepper Control – Hardware Overview
    • Project 29 – Using a Motor Shield xii
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 29 – Using a Motor Shield – Code Overview
      • Project 29 – Using a Motor Shield – Hardware Overview.....................................................................
    • Project 30 – Line Following Robot
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 30 – Line Following Robot – Code Overview
    • Summary
      • Subjects and Concepts covered in Chapter
  • ■Chapter 11: Pressure Sensors
    • Project 31 – Digital Pressure Sensor
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 31 – Digital Pressure Sensor – Code Overview
      • Project 31 – Digital Pressure Sensor – Code Overview (cont.)
    • Project 32 – Digital Barograph.......................................................................................
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 32 – Digital Barograph – Code Overview
    • Summary
      • Subjects and Concepts covered in Chapter
  • ■Chapter 12: Touch Screens xiii
    • Project 33 – Basic Touch Screen
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 33 – Basic Touch Screen – Hardware Overview
      • Project 33 – Basic Touch Screen – Code Overview
    • Project 34 – Touch Screen Keypad
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 34 –Touch Screen Keypad – Code Overview............................................................................
    • Project 35 – Touch Screen Light Controller
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 35 – Touch Screen Controller – Code Overview
    • Summary
      • Subjects and Concepts covered in Chapter
  • ■Chapter 13: Temperature Sensors
    • Project 36 – Serial Temperature Sensor........................................................................
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 36 – Serial Temperature Sensor – Code Overview...................................................................
    • Project 37 – 1-Wire Digital Temperature Sensor
      • Parts Required
      • Connect It Up
      • Enter the Code xiv
      • Project 37 – 1-Wire Digital Temperature Sensor – Code Overview
    • Summary
      • Subjects and Concepts covered in Chapter
  • ■Chapter 14: Ultrasonic Rangefinders
    • Project 38 – Simple Ultrasonic Rangefinder
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 38 – Simple Ultrasonic Range Finder – Code Overview
      • Project 38 – Simple Ultrasonic Range Finder – Hardware Overview
    • Project 39 – Ultrasonic Distance Display
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 39 – Ultrasonic Distance Display – Code Overview
    • Project 40 – Ultrasonic Alarm
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 40 – Ultrasonic Alarm – Code Overview
    • Project 41 – Ultrasonic Theremin
      • Enter the Code
      • Project 41 – Ultrasonic Theremin – Code Overview
    • Summary
      • Subjects and Concepts covered in Chapter
  • ■Chapter 15: Reading and Writing to an SD Card xv
    • Project 42 – Simple SD Card/Read Write
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 42 – Simple SD Card Read/Write – Code Overview
    • Project 43 – Temperature SD Datalogger
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 43 – Temperature SD Datalogger – Code Overview
      • Project 43 – Temperature SD Datalogger – Hardware Overview
    • Summary
      • Subjects and Concepts covered in Chapter
  • ■Chapter 16: Making an RFID Reader
    • Project 44 – Simple RFID Reader
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 44 – Simple RFID Reader – Hardware Overview
    • Project 45 – Access Control System
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 45 – Access Control System – Code Overview
    • Summary
      • Subjects and Concepts covered in Chapter
  • ■Chapter 17: Communicating over Ethernet.......................................................... xvi
    • Project 46 – Ethernet Shield
      • Parts Required
      • Connect It Up
      • Enter the Code
      • Project 46 – Ethernet Shield – Code Overview
    • Project 47 – Internet Weather Display
      • Enter the Code
      • Project 47 – Internet Weather Display – Code Overview
    • Project 48 – Email Alert System
      • Enter the Code
      • Project 48 – Email Alert System – Code Overview
    • Project 49 – Twitterbot
      • Enter the Code
      • Project 49 – Twitterbot – Code Overview
    • Project 50 – RSS Weather Reader
      • Enter the Code
      • Project 50 – RSS Weather Reader – Code Overview
    • Summary
  • Index

CHAPTER 1 ■ INTRODUCTION 4 Figure 1-2. A dot matrix display controlled by an Arduino (image courtesy of Bruno Soares) The Arduino board is made up of an Atmel AVR Microprocessor, a crystal or oscillator (a crude clock that sends time pulses at a specified frequency to enable it to operate at the correct speed), and a 5-volt linear regulator. Depending on what type of Arduino you have, it may also have a USB socket to connect to a PC or Mac for uploading or retrieving data. The board exposes the microcontroller’s I/O (input/output) pins so that you can connect those pins to other circuits or to sensors. The latest Arduino board, the Uno, differs from the previous versions of the Arduino in that it does not use the FTDI USB-to-serial driver chip. Instead, it uses an Atmega8U2 programmed as a USB-to- serial converter. This gives the board several advantages over its predecessor, the Duemilanove. First, the Atmega chip is a lot cheaper than the FTDI chip, bringing the prices of the boards down. Secondly, and most importantly, it enables the USB chip to have its firmware reflashed to make the Arduino show up on your PC as another device, such as a mouse or game controller. This opens up a whole array of new uses for the Arduino. Unfortunately, moving over to this new USB chip has made it a lot more difficult for clone manufacturers to make Arduino Uno clones. To program the Arduino (make it do what you want it to) you use the Arduino IDE (Integrated Development Environment), which is a piece of free software in which you write code in the language that the Arduino understands (a language called C). The IDE lets you to write a computer program , which is a set of step-by-step instructions that you then upload to the Arduino. Your Arduino will then carry out these instructions and interact with whatever you have connected to it. In the Arduino world, programs are known as sketches. The Arduino hardware and software are both open source, which means that the code, schematics, design, etc. can be taken freely by anyone to do what they like with them. Hence, there are many clone boards and other Arduino-based boards available to purchase or to make from a schematic. Indeed, there is nothing stopping you from purchasing the appropriate components and making your own Arduino on a breadboard or on your own homemade PCB (Printed Circuit Board). The only caveat that the Arduino team imposes is that you cannot use the word “Arduino.” This name is reserved for the official board. Hence, the clone boards have names such as Freeduino, Roboduino, etc. As the designs are open source, any clone board is 100% compatible with the Arduino and therefore any software, hardware, shields, etc. will also be 100% compatible with a genuine Arduino.

CHAPTER 1 ■ INTRODUCTION 6 If you do a search on the Internet for “Arduino,” you will be amazed at the large number of websites dedicated to the Arduino or that feature cool project created with an Arduino. The Arduino is an amazing device and will enable you to create anything from interactive works of art (see Figure 1-3) to robots. With a little enthusiasm for learning how to program an Arduino and make it interact with other components as well as a bit of imagination, you can build anything you can think of. This book will give you the necessary skills needed to make a start in this exciting and creative hobby. Now that you know what an Arduino is, let’s get one hooked up to your computer and start using it. Getting Started This section will explain how to set up your Arduino and the IDE for the first time. The instructions for Windows and Macs (running OSX 10.3.9 or later) are given. If you use Linux, refer to the Getting Started instructions on the Arduino website at www.arduino.cc.playground/Learning/Linux. I will also presume you are using an Arduino Uno. If you have a different type of board, such as the Duemilanove (see Figure 1-4), then refer to the corresponding page in the Getting Started guide of the Arduino website. You will also need a USB cable (A to B plug type) which is the same kind of cable used for most modern USB printers. If you have an Arduino Nano, you will need a USB A to Mini-B cable instead. Do not plug in the Arduino just yet, wait until I tell you to do so. Figure 1-4. An Arduino Duemilanove (image courtesy of Snorpey) Next, download the Arduino IDE. This is the software you will use to write your programs (or sketches) and upload them to your board. For the latest IDE go to the Arduino download page at http://arduino.cc/en/Main/Software and obtain appropriate the version for your OS.

CHAPTER 1 ■ INTRODUCTION 7 Windows XP Installation Once you have downloaded the latest IDE, unzip the file and double-click the unzipped folder to open it. You will see the Arduino files and sub-folders inside. Next, plug in your Arduino using the USB cable and ensure that the green power LED (labeled PWR) turns on. Windows will say “Found new hardware: Arduino Uno” and the Found New Hardware Wizard will appear. Click next and Windows will attempt to load the drivers. This process will fail. This is nothing to worry about; it’s normal. Next, right-click on the My Computer icon on your desktop and choose Manage. The Computer Management window will open up. Now go down to Event Manager in the System Tools list and click it. In the right hand window, you’ll see a list of your devices. The Arduino Uno will appear on the list with a yellow exclamation mark icon over it to show that the device has not been installed properly. Right click on this and choose Update Driver. Choose “No, not this time” from the first page and click next. Then choose “Install from a list or specific location (Advanced)” and click next again. Now click the “Include this location in the search” and click Browse. Navigate to the Drivers folder of the unzipped Arduino IDE and click Next. Windows will install the driver and you can then click the Finish button. The Arduino Uno will now appear under Ports in the device list and will show you the port number assigned to it (e.g. COM6). To open the IDE double-click the Arduino icon in its folder. Windows 7 & Vista Installation Once you have downloaded the latest IDE, unzip the file and double-click the unzipped folder to open it. You will see the Arduino files and sub-folders inside. Next, plug in your Arduino using the USB cable and ensure that the green power LED (labeled PWR) turns on. Windows will attempt to automatically install the drivers for the Arduino Uno and it will fail. This is normal, so don’t worry. Click the Windows Start button and then click Control Panel. Now click System and Security, then click System, and then click Device Manager from the list on the left hand side. The Arduino will appear in the list as a device with a yellow exclamation mark icon over it to show that it has not been installed properly. Right click on the Arduino Uno and choose “Update Driver Software.” Next , choose “Browse my computer for driver software” and on the next window click the Browse button. Navigate to the Drivers folder of the Arduino folder you unzipped earlier and then click OK and then Next_._ Windows will attempt to install the driver. A Windows Security box will open up and will state that “Windows can’t verify the publisher of this driver software_._ ” C lick “Install this driver software anyway_._ ” The Installing Driver Software window will now do its business_. I_ f all goes well , you will have another window saying “Windows has successfully updated your driver software. Finally click Close_._ To open the IDE double-click the Arduino icon in its folder. Mac OSX Installation Download the latest disk image (.dmg) file for the IDE. Open the .dmg file; it will appear like Figure 1-5.

CHAPTER 1 ■ INTRODUCTION 9 Figure 1-6. The Arduino IDE when first opened Now go to the menu and click Tools. Then click Board (See Figure 1-7). Figure 1-7. The Arduino Tools menu You will now be presented with a list of boards (See Figure 1-8). If you have an Uno, choose that. If you have a Duemilanove or another Arduino variant, choose the appropriate one from the list.

CHAPTER 1 ■ INTRODUCTION 10 Figure 1-8. The Arduino Boards menu Next, click the Tools menu again, click Serial Port, and then choose the appropriate port from the list for your Arduino (Figure 1-9). You are now ready to upload an example sketch to test that the installation has worked. Figure 1-9. The Serial Port list Upload Your First Sketch Now that you have installed the drivers and the IDE and you have the correct board and ports selected, it’s time to upload an example sketch to the Arduino to test that everything is working properly before moving on to the first project. First, click the File menu (Figure 1-10) and then click Examples.