Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Discover millions of ebooks, audiobooks, and so much more with a free trial

From $11.99/month after trial. Cancel anytime.

Arduino For Dummies
Arduino For Dummies
Arduino For Dummies
Ebook660 pages5 hours

Arduino For Dummies

Rating: 3.5 out of 5 stars

3.5/5

()

Read preview
  • Arduino

  • Electronics

  • Programming

  • Technology

  • Arduino Programming

  • Diy

  • Mentor

  • Experimentation

  • Step-By-Step Instructions

  • Power of Friendship

  • Hero's Journey

  • Chosen One

  • Power of Knowledge

  • Power of Community

  • Mad Scientist

  • Sensors

  • Soldering

  • Prototyping

  • Software

  • Learning

About this ebook

Bring your ideas to life with the latest Arduino hardware and software

Arduino is an affordable and readily available hardware development platform based around an open source, programmable circuit board. You can combine this programmable chip with a variety of sensors and actuators to sense your environment around you and control lights, motors, and sound. This flexible and easy-to-use combination of hardware and software can be used to create interactive robots, product prototypes and electronic artwork, whether you’re an artist, designer or tinkerer.

Arduino For Dummies is a great place to start if you want to find out about Arduino and make the most of its incredible capabilities. It helps you become familiar with Arduino and what it involves, and offers inspiration for completing new and exciting projects.

•     Covers the latest software and hardware currently on the market

•     Includes updated examples and circuit board diagrams in addition to new resource chapters

•     Offers simple examples to teach fundamentals needed to move onto more advanced topics

•     Helps you grasp what’s possible with this fantastic little board

Whether you’re a teacher, student, programmer, hobbyist, hacker, engineer, designer, or scientist, get ready to learn the latest this new technology has to offer! 

 

LanguageEnglish
PublisherWiley
Release dateAug 10, 2018
ISBN9781119489573
Arduino For Dummies

Related to Arduino For Dummies

Related ebooks

Software Development & Engineering For You

View More

Related articles

Reviews for Arduino For Dummies

Rating: 3.6666666666666665 out of 5 stars
3.5/5

3 ratings1 review

What did you think?

Tap to rate

Review must be at least 10 words

  • Rating: 4 out of 5 stars
    4/5
    Good primer. If weak on Arduino code in general it makes up for it explaining the "whys" of what is in here. Now to dig into really using the micro-controller...

Book preview

Arduino For Dummies - John Nussey

Foreword

The moment a For Dummies book comes out, it's definitely a milestone in the history of a product.

Programming embedded computers used to be a very difficult task, reserved only to experienced engineers willing to master the obscure assembly language. In recent years, however, many platforms have tried to make this task simpler and more accessible to everyday people. Arduino is one of the latest attempts at making technology less scary and more creative.

With John, this book’s author, we watched this creative tool being adopted by designers and artists in London, making its way into many memorable projects. Now Arduino has escaped the lab of Arts & Design and spread like a virus, becoming the tool of choice for all kinds of people who have great ideas they want to realize.

I'm really glad that John decided to write this book, because he's an early user of the Arduino platform from back in the days when it was still quite experimental. Having taught Arduino classes for many years, he has the ability to introduce the subject to all audiences.

Any newcomer to Arduino will, with the right tools and teaching — such as those found in this book — show true genius in no time.

— Massimo Banzi

Introduction

Arduino is a tool, a community, and a way of thinking that is affecting how we use and understand technology. It has rekindled a love and understanding of electronics for many people, including myself, who felt that electronics was something that they had left behind at school.

Arduino is tiny circuit board that has huge potential. It can be used to blink a Morse-code signal using a single light-emitting diode (LED) or to control every light in a building, depending on how far you take it. Its capabilities are limited only by your imagination.

Arduino is also providing a new, practical approach to technical education, lowering the entry level for those wanting to use electronics to complete small projects and, I hope, encouraging you to read further to take on big ones.

A huge and ever-growing community of Arduinists has emerged — users and developers who learn from each other and contribute to the open-source philosophy by sharing the details of their projects. This open-source attitude is responsible for the huge popularity of Arduino.

Arduino is more than just a gadget; it’s a tool. A piece of technology that makes understanding and using today’s technology easier.

So if the prospect of understanding the limitless possibilities of technology doesn’t sound interesting to you, please put this book down and back away.

Otherwise, read on!

About This Book

This is a technical book, but it’s not for technical people only. Arduino is designed to be usable by anyone, whether they’re technical, creative, crafty, or just curious. All you need is an open mind or a problem to fix and you’ll soon find ways that using Arduino can benefit you.

This book starts on the most basic level to get you started with using and understanding Arduino. At times throughout the book, I may refer to a number of technical things that will, like anything, take time to understand. I guide you through all the basics and then on to more advanced activities.

Much of what is in this book is based on my learning and teaching experiences. I learned all about Arduino from scratch, but have always found that the best way to learn is in practice, by making your own projects. The key is to understand the basics that I cover in this book and then build on that knowledge by thinking about how you can apply it to solve problems, create things, or just entertain yourself.

Foolish Assumptions

I assume nothing about your technical knowledge. Arduino is an easy-to-use platform for learning about electronics and programming. It is for people from all walks of life, whether you’re a designer, an artist, or a hobbyist.

It can also be a great platform for people who are already technical. Maybe you’ve done a bit of coding but want to bring your projects into the physical world in some way. Or maybe you’ve worked with electronics and want to see what Arduino can bring to the table.

Whoever you are, you’ll find that Arduino has great potential. It’s really up to you to decide what to make of it.

Icons Used in This Book

Arduino For Dummies uses icons to highlight important points for you. Keep an eye out for the following:

tip This icon highlights a bit of helpful information. That info may be a technique to help you complete a project more easily or the answer to a common problem.

warning Arduinos aren’t dangerous on their own; indeed, they’re made to be extremely safe and easy to use. But if you use them in a circuit without proper planning as well as care and attention, they can damage your circuit, your computer, and yourself. When you see a Warning icon, please take special note.

remember Often, you must consider certain points before proceeding with a task. I use Remember icons to remind you of such points.

technicalstuff Some information is more technical than others and is not for the faint-hearted. The joy of Arduino is that you don’t need to fully understand the technical details immediately. You can skip anything that’s marked with this icon if it’s more complicated than you want to deal with at the moment; you can always return to it when you’re ready.

Beyond the Book

In addition to what you’re reading right now, this product comes with a free access-anywhere Cheat Sheet that provides information on using resistors, getting the tools you'll need, and some system shortcuts. To get this Cheat Sheet, simply go to www.dummies.com and type Arduino For Dummies 2nd Edition Cheat Sheet in the Search box. I also provide a bonus chapter that teaches you all about using your Arduino to hack other hardware, such as games, controllers, and toys.

Where to Go from Here

If you’re uncertain about where to start, I suggest the beginning. By the end of Chapter 2, you’ll have acquired a simple understanding of Arduino and will know where you can get a kit to continue learning.

If you’ve used Arduino before, you may want to jump straight to Chapter 4 to cover the basics again, or head straight to the area that interests you.

Part 1

Getting to Know Arduino

IN THIS PART …

Find out all about the little blue circuit board.

Discover everything you need to get started with Arduino and where to get them.

Learn how to wield the awesome power of an LED, blinking in on command with a few simple lines of code.

Chapter 1

Discovering Arduino

IN THIS CHAPTER

check Discovering what Arduino is

check Learning where Arduino came from

check Introducing the basic principles

Arduino is made up of both hardware and software.

The Arduino board is a printed circuit board (PCB) designed to use a microcontroller chip as well as other input and outputs. The board has many other electronic components that are needed for the microcontroller to function or to extend its capabilities.

A microcontroller is a small computer contained in a single, integrated circuit or computer chip. Microcontrollers are an excellent way to program and control electronics. Microcontroller boards have a microcontroller chip and other useful connectors and components that allow a user to attach inputs and outputs. Some examples of devices with microcontroller boards are the Wiring board, the PIC, and the Basic Stamp.

You write code in the Arduino software to tell the microcontroller what to to-do. For example, by writing a line of code, you can tell an light-emitting diode (LED) to blink on and off. If you connect a pushbutton and add another line of code, you can tell the LED to turn on only when the button is pressed. Next, you may want to tell the LED to blink only when the pushbutton is held down. In this way, you can quickly build a behavior for a system that would be difficult to achieve without a microcontroller.

Similar to a conventional computer, an Arduino can perform a multitude of functions, but it’s not much use on its own. It requires inputs or outputs to make it useful. These inputs and outputs allow a computer — and an Arduino — to sense objects in the world and to affect the world.

Before you move forward, it might help you to understand a bit of the history of Arduino.

Where Did Arduino Come From?

Arduino started its life in Italy, at Interaction Design Institute Ivrea (IDII), a graduate school for interaction design that focuses on how people interact with digital products, systems, and environments and how they in turn influence us.

The term interaction design was coined by Bill Verplank and Bill Moggridge in the mid-1980s. The sketch in Figure 1-1 by Verplank illustrates the basic premise of interaction design: If you do something, you feel a change, and from that you can know something about the world.

Courtesy of Bill Verplank

FIGURE 1-1: The principle of interaction design, illustrated by Bill Verplank.

Although interaction design is a general principle, it more commonly refers specifically to how we interact with conventional computers by using peripherals (such as mice, keyboards, and touchscreens) to navigate a digital environment that is graphically displayed on a screen.

Another avenue, referred to as physical computing, is about extending the range of these computer programs, software, or systems through electronics. By using electronics, computers can sense more about the world and have a physical effect on the world themselves.

Both areas — interaction design and physical computing — require prototypes to fully understand and explore the interactions, which presented a hurdle for non-technical design students.

In 2001, a project called Processing, started by Casey Reas and Benjamin Fry, aimed to get non-programmers into programming by making it quick and easy to produce onscreen visualizations and graphics. The project gave the user a digital sketchbook on which to try ideas and experiment with a small investment of time. This project in turn inspired a similar project for experimenting in the physical world.

In 2003, building on the same principles as Processing, Hernando Barragán started developing a microcontroller board called Wiring. This board was the predecessor to Arduino.

In common with the Processing project, the Wiring project also aimed to involve artists, designers, and other non-technical people. However, Wiring was designed to get people into electronics as well as programming. The Wiring board (shown in Figure 1-2) was less expensive than some other microcontrollers, such as the PIC and the Basic Stamp, but it was still a sizable investment for students.

FIGURE 1-2: An early Wiring board.

In 2005, the Arduino project began in response to the need for affordable and easy-to-use devices for interaction design students to use in their projects. It is said that Massimo Banzi and David Cuartielles named the project after Arduin of Ivrea, an Italian king, but I’ve heard from reliable sources that it also happens to be the name of the local pub near the university, which may have been of more significance to the project.

The Arduino project drew from many of the experiences of both Wiring and Processing. For example, an obvious influence from Processing is the graphic user interface (GUI) in the Arduino software. This GUI was initially borrowed from Processing, and even though it still looks similar, it has since been refined to be more specific to Arduino. I cover the Arduino interface in more depth in Chapter 3.

Arduino also kept the naming convention from Processing, calling its programs sketches. In the same way that Processing gives people a digital sketchbook to create and test programs quickly, Arduino gives people a way to sketch their hardware ideas as well. Throughout this book, I show many sketches that allow your Arduino to perform a huge variety of tasks. By using and editing the example sketches in this book, you can quickly build up your understanding of how they work. You'll be writing your own in no time. Each sketch is followed with a line-by-line explanation of how it works to ensure that no stone is left unturned.

The Arduino board, shown in Figure 1-3, was made to be more robust and forgiving than Wiring and other earlier microcontrollers. It was not uncommon for students, especially those from a design or arts background, to break their microcontroller within minutes of using it, simply by getting the wires the wrong way around. This fragility was a huge problem, not only financially but also for the success of the boards outside technical circles. You can also change the microcontroller chip on an Arduino; if the chip becomes damaged, you can replace just it rather than the entire board.

FIGURE 1-3: The original Arduino Serial board.

Another important difference between Arduino and other microcontroller boards is the cost. Back in 2006, another popular microcontroller, the Basic Stamp, cost nearly four times as much ($119) as an Arduino ($32). Today, an Arduino Uno costs just $22.

In one of my first Arduino workshops, I was told that the price was intended to be affordable for students. The price of a nice meal and a glass of wine at that time was about $42, so if you had a project deadline, you could choose to skip a nice meal that week and make your project instead.

The range of Arduino boards on the market is a lot bigger than it was back in 2006. In Chapter 2, you learn about just a few of the most useful Arduino and Arduino-compatible boards and how they differ to provide you with a variety of solutions for your own projects. Also, in Chapter 12, you learn all about a special type of circuit board called a shield, which can add useful, and in some cases phenomenal, features to your Arduino, turning it into a GPS (Global Positioning System) receiver, a mobile phone, or even a Geiger counter, to name just a few.

Learning by Doing

People have used technology in many ways to achieve their own goals without needing to delve into the details of electronics. Following are just a few related schools of thought that have allowed people to play with electronics.

Patching

Patching is a technique for experimenting with systems using wires. The earliest popular example of patching is in phone switchboards. For an operator to put you through to another line, he or she had to physically attach a cable.

This technique was also popular for synthesizing music, such as with the Moog synthesizer. When an electronic instrument generates a sound, it's really generating a voltage. Different collections of components in the instrument manipulate that voltage before it is outputted as an audible sound. The Moog synthesizer works by changing the path that that voltage takes, sending it through a number of different components to apply different effects.

Because so many combinations are possible, the musician proceeds largely through trial and error. But the simple interface means that this process is extremely quick and requires little preparation to get going.

Hacking

Hacking is a term that typically refers to the subversive use of technology. More generally, though, it refers to exploring systems and making full use of them or repurposing them to suit your needs.

Hacking in this sense is possible in hardware as well as software. A great example of hardware hacking is a keyboard hack. Say that you want to use a big red button to move through a slideshow. Most software programs contain keyboard shortcuts, and most PDF viewers move to the next page in a slideshow when the user presses the spacebar. If you know this, you ideally want a keyboard with only a spacebar.

Today's keyboards have a small circuit board, a bit smaller than a credit card (see Figure 1-4), containing lots of contacts that are connected when you press different keys. If you can find the correct combination, you can connect two contacts by using a pushbutton. Now every time you press that button, you send a space to your computer.

FIGURE 1-4: The insides of a keyboard, ready to be hacked.

This technique is great for sidestepping the intricacies of hardware and getting the results you want. In the Hacking Other Hardware bonus chapter (www.dummies.com/go/arduinofd), you learn more about the joy of hacking and how you can weave hacked pieces of hardware into your Arduino project to control remote devices, cameras, and even computers with ease.

Circuit bending

Circuit bending flies in the face of traditional education and is all about spontaneous experimentation. Children's toys are the staple diet of circuit benders, but really any electronic device has the potential to be experimented with.

By opening a toy or device and revealing the circuitry, you can alter the path of the current to affect its behavior. Although this technique is similar to patching, it's a lot more unpredictable. However, after you find a combination that produces a pleasing result, you can add or replace components, such as resistors or switches, to give the user more control over the instrument.

Most commonly, circuit bending is about sound, and the finished instrument becomes a rudimentary synthesizer or drum machine. Two of the most popular devices are the Speak & Spell (see Figure 1-5) and the Nintendo GameBoy. Musicians such as the Modified Toy Orchestra (modifiedtoyorchestra.com), in their own words, explore the hidden potential and surplus value latent inside redundant technology. So think twice before putting your old toys on eBay!

Courtesy of Modified Toy Orchestra

FIGURE 1-5: A Modified Toy Orchestra Speak & Spell after circuit bending.

Electronics

Although there are many ways to work around technology, eventually you’ll want more of everything: more precision, more complexity, and more control.

If you learned about electronics at school, you were most likely taught how to build circuits using specific components. These circuits are based solely on the chemical properties of the components and need to be calculated in detail to make sure that the correct amount of current is going to the correct components.

These are the kind of circuits you find as kits at Radio Shack (or Maplin, in the United Kingdom) that do a specific job, such as an egg timer or a security buzzer that goes off when you open a cookie jar. These kits are good at their specific job, but they can’t do much else.

This is where microcontrollers come in. When used with analog circuitry, microcontrollers can give that circuitry a more advanced behavior. They can also be reprogrammed to perform different functions as needed. Your Arduino is designed around one of these microcontrollers, and in Chapter 2, you look closely at an Arduino Uno to see exactly how it is designed and what it is capable of.

The microcontroller is the brains of a system, but it needs other electronic inputs and outputs to either sense or affect things in its environment.

Inputs

Inputs are senses for your Arduino. They tell it what is going on in the world. At its most basic, an input could be a switch, such as a light switch in your home. At the other end of the spectrum, it could be a gyroscope, telling the Arduino the exact direction it’s facing in three dimensions. You learn all about basic inputs in Chapter 6, and more about the variety of sensors and when to use them in Chapter 11.

Outputs

Outputs allow your Arduino to affect the real world in some way. An output could be subtle and discreet, such as in the vibration of a cellphone, or it could be a huge visual display on the side of a building that can be seen for miles around. The first sketch in the book walks you through blinking an LED (see Chapter 3). From there, you can go on to controlling an electric motor (Chapter 7) and even controlling an LCD screen (Chapter 12).

Open Source

Open source software, in particular Processing, has had a huge influence on Arduino development. In the world of computer software, open source is a philosophy in which people share the details of a program and encourage others to use, remix, and redistribute it, as they like.

Just as the Processing software is open source, so are Arduino software and hardware. This means that the Arduino software and hardware are both released freely to be adapted as needed. You find the same spirit of openness also amongst the community on the Arduino forums.

On the official Arduino forums (http://forum.arduino.cc/) and many other ones around the world, people have shared their code, projects, and questions for an informal peer review. This sharing allows all sorts of people, including experienced engineers, talented developers, practiced designers, and innovative artists, to lend their expertise to novices in some or all of these areas. It also provides a means to gauge people’s areas of interest, which occasionally filters into the official release of Arduino software or board design with refinements or additions. The Arduino website has an area known as the Playground (playground.arduino.cc/), where people are free to upload their code for the community to use, share, and edit.

This kind of philosophy has encouraged the relatively small community to pool knowledge on forums, blogs, and websites, thereby creating a vast resource for new Arduinists to tap into.

Despite the open-source nature of Arduino, a huge loyalty to Arduino as a brand exists — so much so that there is an Arduino naming convention of adding -duino or -ino to the name of boards and accessories (much to the disgust of Italian members of the Arduino team)!

Chapter 2

Finding Your Board and Your Way Around It

IN THIS CHAPTER

check Inspecting the Arduino Uno

check Discovering other Arduino boards

check Knowing where to shop for Arduinos

check Finding the right Arduino kit to get started

check Setting up a workspace

check Installing Arduino

check Introducing Arduino Web Editor

The name Arduino encompasses a host of concepts. It can refer to an Arduino board, the physical hardware, the Arduino environment — that is, a piece of software that runs on your computer — and, finally, Arduino as a subject in its own right, as in this book: how the hardware and software can be combined with related craft and electronics knowledge to create a tool kit for any situation.

This chapter provides an overview of what you need to get started with Arduino. You may be eager to dive in, so you may want to quickly scan through this chapter, stopping at any areas of uncertainty and referring to them later as needed.

First, you learn about the components used on the Arduino Uno board, which is the starting point for most Arduinists. Beyond that, you get acquainted with the other available Arduino boards, how they differ, and what uses they have. The chapter lists major suppliers that can equip you with all the parts you need and examines some of the starter kits that are ideal for beginners and for accompanying this book. When you have the kit and a workspace, you’re ready to start.

Lastly, you find out where to obtain the software to control your Arduino. I walk you through the steps for downloading and installing the software, and give you a brief tour of the environment in which you develop your Arduino programs.

Getting to Know the Arduino Uno

No one definitive Arduino board exists; many types of Arduino boards are available, each with its own design to suit various applications. Deciding what board to use can be a daunting prospect because the number of boards is increasing, each with new and exciting prospects. However, one board can be considered the archetype of the Arduino hardware, the one that almost all people start with and that is suitable for most applications. It’s the Arduino Uno.

The most recent main board to date is the Arduino Uno R3 (released in 2011). Think of it as the plain vanilla of Arduino boards. It’s a good and reliable workhorse suitable for a variety of projects. If you're just starting out, the Uno R3 is the board for you (see Figures 2-1 and 2-2).

FIGURE 2-1: The front of an Arduino Uno.

FIGURE 2-2: The back of an Arduino Uno.

Uno is Italian for the number one, named for the release of version 1.0 of the Arduino software. Predecessors to this release had a variety of names, such as Serial, NG, Diecimila (10,000 in Italian, to mark that 10,000 boards had been sold), and Duemilanove (2009 in Italian, the release date of the board); the Uno has ushered in some much needed order to the naming of the boards. R3 relates to the revision of the features on the board, which includes updates, refinements, and fixes. In this case, it is the third revision.

The board has many small components, described throughout much of this chapter.

The Brains: ATmega328P microcontroller chip

You can think of the microcontroller chip itself as the brains of the board. The chip used in the Arduino Uno is the ATmega328P, made by Atmel. It’s the large, black component in the center of the board. This chip is known as an integrated circuit, or IC. It sits in a socket; if you were to remove it, it would look like the one shown in Figure 2-3.

FIGURE 2-3: An ATmega328P microcontroller all by itself.

This same chip can come in different forms, referred to as packages. The one in an Arduino Uno is in a plated-through hole, or PTH, package, named because of the way it makes contact with the board. Another variation you may find is the Arduino Uno SMD, or surface mount device, package, which is mounted on the surface of the board rather than in holes that go through it. This chip is much smaller, but it is not replaceable, whereas the PTH chip is. Apart from that, it functions exactly the same as the PTH and differs only in looks.

Header sockets

The microcontroller socket connects all the legs of the ATmega328 microcontroller chip to other sockets, referred to as header sockets, which are arranged around the edge of the board and are labeled for ease of use. These black sockets are divided into three main groups: digital pins, analog input pins, and power pins.

All these pins transfer a voltage, which can be either sent as output or received as an input. Why are these pins important? They allow you to connect additional circuitry to the board quickly and easily when prototyping with a breadboard (described in Chapter 6) and to design additional boards, called shields, that fit neatly on top of your Arduino board (see Chapter 12 for more on shields).

This same process of sending and receiving electrical signals is going on inside modern computers. But because they are so advanced and refined compared to a humble Arduino, it is difficult to directly link a computer accustomed to digital signals (0s and 1s) to an electronic circuit that deals with a range of voltages (0v to 5v in the ATmega328P’s case).

The Arduino (see the sketch in Figure 2-4) is special because it can interpret these electric signals and convert them to digital signals that your computer can understand — and vice versa. It also enables you to write a program using software on a conventional computer that the Arduino IDE (integrated development environment) converts or compiles to electrical signals that your circuit can understand.

FIGURE 2-4: An Arduino Uno with all the important parts labeled.

By bridging this gap, it is possible to use a conventional computer's benefits — ease of use, user-friendly interfaces, and code that is easy for humans to understand — to control a wide range of electronic circuits and even give them complex behaviors with relative ease.

Digital pins

You use digital pins (refer to Figure 2-4) to send and receive digital signals. Digital implies that the pins have two states: off or on. In electrical terms, these states translate to a value of 0 or 5 volts, but no values in between.

Analog in pins

You use analog in pins (refer to Figure 2-4) to receive an analog value. An analog value is taken from a range of values. In this case, the range is the same 0V to 5V as with the digital pins, but the value can be at any point — 0.1, 0.2, 0.3, and so on.

What about analog out?

The shrewd ones among you may have noticed that

Enjoying the preview?
Page 1 of 1