Book Image

Arduino Development Cookbook

By : Cornel M Amariei
Book Image

Arduino Development Cookbook

By: Cornel M Amariei

Overview of this book

Table of Contents (16 chapters)
Arduino Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

The year was 2005 when a few guys from the Interaction Design Institute Ivrea, Italy wanted to create a simple microcontroller board for their students—a board that was more modern, cheaper, and easier to use than the designs available at that moment. And they named it Arduino, after the local bar, which was named after King Arduino.

The initial version was bulky, complicated to connect, and lacked USB, and other features commonly found these days, but the board had potential. Now, Arduino is renowned for its simplicity and ease of use. Children are building projects using Arduino that only 10 years ago would have required engineers.

The whole design is open sourced and clones of the board can be found everywhere in the world. There is no known number of Arduino boards but it is in the range of hundreds of thousands or even more. Everybody can design their own custom implementation of the standard invented in 2005.

Today, Arduino has been to every corner of the planet and even above it. It has fueled other revolutions such as the maker, the open source and 3D printing movements. It is continuously upgraded to be faster and handle more. But what is Arduino?

Arduino is a microcontroller board, designed to connect to electronics and control them. We can write code for the Arduino that will get data from the environment, and make decisions and take actions based on the data. Robots, 3D printers, toys, even toasters may have an Arduino inside, powering up all the interaction.

This book contains recipes that show how to implement key topics of the Arduino, starting from basic interaction with buttons and LEDs, going up to interaction with the Global Positioning System (GPS), making music, or communicating with the Internet. It is intended for programming or electronics enthusiasts who want to combine the best of both worlds to build interactive projects.

What this book covers

Chapter 1, Power on – Arduino Basics, will teach you to connect, install, and transfer the first program to the Arduino board. This chapter covers the basics of how to use the Arduino board, the types of boards, and how to use the Arduino IDE.

Chapter 2, Blinking LEDs, covers one of the basic uses of Arduino, controlling LEDs. Various types and implementations have been covered, RGB LEDs, blinking and fading LEDs, 7-segment displays, or more advanced control techniques.

Chapter 3, Working with Buttons, will show you how to detect and use buttons as a key input method. Several types of buttons have been covered along with solutions to the most common button implementation issues. Also, ways of connecting more buttons than available digital pins have been shown.

Chapter 4, Sensors, covers the most important sensors that can be connected to the Arduino. Probably the most important thing for Arduino is to be able to read as many parameters from the environment as possible. Using sensors, it can read distance, temperature, light intensity, or even global localization.

Chapter 5, Motor Control, will show you how to connect and control multiple types of motors. Making things move is incredibly easy using motors and Arduino. Small and large, brushless and servos motor along with speed and direction control, have all been covered here.

Chapter 6, More Output Devices, talks about getting more out of Arduino. This chapter covers how to control different loads, how to make sound, how to isolate and protect the board, and how to command more outputs.

Chapter 7, Digital Communication with Arduino, covers several communication protocols such as UART, I2C, Serial, and Ethernet, to get the most out of the communication interfaces available on Arduino. Arduino can communicate with other boards, computers, and even the Internet.

Chapter 8, Hacking, talks about the small hacks that can help an Arduino design go further. It includes speeding up the PWM, reacting to external interrupts, or even storing data inside the Arduino forever.

Appendix, Electronics – the Basics, covers the basics of electronics, such as breadboards, Ohm's law, and so on.

What you need for this book

In general, for the recipes in this book you will need the following items:

  • An Arduino board

  • A USB cable to connect the Arduino to the computer

  • A breadboard with a jumper wire kit

  • A general set of resistors with values between 100 ohm and 10,000 ohm

  • An assortment of general LEDs

  • A few push buttons and switches

  • 1N4148 and 1N4001/1N4007 diodes

Some of the more focused recipes require specific hardware components in order to implement them. This is a list of specific components required per chapter:

Chapter 2, Blinking LEDs:

  • RGB LED

  • 7-segment display with at least one digit

  • Standard multi-segment bar graph

Chapter 3, Working with Buttons:

  • 4051 or equivalent multiplexer Integrated Circuit (IC)

Chapter 4, Sensors:

  • 10K or other potentiometer

  • LM35 or TMP36 temperature sensor Integrated Circuit (IC)

  • PIR motion sensor

  • Gas sensors such as the MQ-3, MQ-4, MQ-5, and others in the series

  • Sharp IR sensor such as the GP2Y0A21YK

  • Ultrasonic sensor such as the MaxSonar EZ series or similar

  • Simple accelerometer breakout such as the ADXL335

  • Standard I2C

  • Standard GPS receiver with UART communication

  • 4051 or equivalent multiplexer Integrated Circuit (IC)

Chapter 5, Motor Control:

  • Small vibrating motor

  • Standard NPN transistors such as the BC547, 2N3905, or the TIP120

  • Standard Logic Level N Channel MOSFETs such as the IRF510 or IRF520

  • Arduino motor shield

  • Standard RC servo motor

  • ULN2003 or ULN2004 Darlington Array IC

  • Small bipolar stepper motor

  • Brushless motor with suited ESC

Chapter 6, More Output Devices:

  • 8-ohm small speaker

  • Standard NPN transistors such as the BC547, 2N3905, or the TIP120

  • General 5V relay

  • 1.5–3.0 V battery with wire terminals

  • General optocoupler/optoisolator such as the TLP621, 4N35, or LTV-816

  • A 74HC595 shift register

Chapter 7, Digital Communication with Arduino:

  • Another Arduino board

  • RF Link Transmitter and Receiver (434/315 Mhz) or equivalent

  • Arduino compatbile Ethernet Shield

  • LCD character Display

  • Arduino compatible SD shield

Chapter 8, Hacking:

  • A DC motor

  • A resistor between 220 ohm and 4,700 ohm

  • A standard NPN transistor (BC547, 2N3904, N2222A, TIP120) or a logic level-compatible MOSFET (IRF510, IRF520)

  • A standard diode (1N4148, 1N4001, 1N4007)

Who this book is for

If you want to build programming and electronics projects that interact with the environment, this book will offer you dozens of recipes to guide you through all the major applications of the Arduino platform. It is intended for programming or electronics enthusiasts who want to combine the best of both worlds to build interactive projects.

Sections

This book contains the following sections:

Getting ready

This section tells us what to expect in the recipe, and describes how to set up any software or any preliminary settings needed for the recipe.

How to do it…

This section characterizes the steps to be followed for "cooking" the recipe.

How it works…

This section usually consists of a brief and detailed explanation of what happened in the previous section.

There's more…

It consists of additional information about the recipe in order to make the reader more anxious about the recipe.

See also

This section may contain references to the recipe.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "In the loop() function, we first print the half Christmas tree."

A block of code is set as follows:

if (logFile) {
    logFile.print(val1); // Write first value
    logFile.print(" "); // Write a space
    logFile.println(val2); // Write second value
    logFile.close(); // close the file
  }

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: " To easily find information about a card, run the Arduino IDE built-in example found under File | Examples | SD | CardInfo."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/2943OS_ColoredImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.