Grady Koch

The LEGO Arduino Cookbook

Expanding the Realm of MINDSTORMS EV3 Invention

1st ed.
Grady Koch
Yorktown, VA, USA
ISBN 978-1-4842-6302-0e-ISBN 978-1-4842-6303-7
Apress standard
© Grady Koch 2020
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use.
The publisher, the authors and the editors are safe to assume that the advice and information in this book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the editors give a warranty, expressed or implied, with respect to the material contained herein or for any errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 NY Plaza, New York, NY 10014. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
Introduction

MINDSTORMS EV3 serves as an excellent platform for experimenting with robotics. And with a little push, given in this book, the use of the EV3 Intelligent Brick can be expanded to provide a means for rapid prototyping of all sorts of inventions. There are several single-board host computers for developing inventions, such as the Raspberry Pi, BeagleBone, or LattePanda. There are even hardware adapters to use MINDSTORMS motors on a Raspberry Pi or BeagleBone. But this book keeps LEGO as the foundation, including the MINDSTORMS EV3 Intelligent Brick as a host computer. There are several reasons for this LEGO-centric approach.

First, the mechanical design of inventions is simple by using the vast array of LEGO building bricks that can be attached to the EV3 Intelligent Brick. There’s no need to build an enclosure around the computer heart, since the EV3 Intelligent Brick is already powered, hardened, and enclosed. It has built-in batteries, display, control buttons, speaker, and SD card storage. Mounting points on the rear and sides of the EV3 Intelligent Brick provide quick and easy attachment of sensors and motors.

Second, the artistic aspects of LEGO are maintained by using the EV3 Intelligent Brick as the host computer. LEGO constructions have an aesthetic appeal enjoyed by artists and builders, so the EV3 Intelligent Brick is used as the basis in this book. This artistic appeal is in contrast to the alternate approach of building a device from a Raspberry Pi and trying to put a LEGO box around the device, potentially resulting in a clumsy mash-up. In this book, LEGO is the heart of the invention.

Third, the educational foundation of LEGO can be built upon to introduce kids and students to more sophisticated technologies. LEGO adapts to kids’ interests as they grow older, culminating with MINDSTORMS EV3. As mastery of MINDSTORMS is achieved, this knowledge can be built upon to learn and use more complex electronic and software capabilities.

The key to expanding LEGO MINDSTORMS is introducing the wide selection of sensors, actuators, devices, and even smartphones that can be interfaced through an Arduino controller. This book shows how to add this Arduino interface for many applications. No prior knowledge of Arduino is required.

The development of this book’s ideas begins in Chapter 1 with introducing the Arduino. Instructions are given on how to select among the many varieties of the Arduino, along with the accessories for attaching it to LEGO bricks and wire connections. Two options are suggested of either an Arduino Uno circuit board with shield accessories or the STEMTera. A design is given for mounting of the Arduino alongside the EV3 Intelligent Brick to create a LEGO workstation for building prototype inventions.

Chapter 2 discusses programming the EV3 Intelligent Brick, preparing to interface it to the Arduino. The MINDSTORMS EV3 programming environment will be used throughout this book, taking advantage of its likely familiarity with many readers. While prior experience working with the robots of the EV3 Home Edition software is helpful, it is not necessary to build the projects in this book with instructions given on how to get started and how to program the projects’ EV3 code. Advanced programming blocks are used in some of the projects in this book that readers may not be familiar with, so these blocks are introduced in this chapter.

Chapter 3 sets up the Arduino, specifically in how to program this device and how to interpret the architecture of an Arduino program sketch. Arduinos are programmed with a variant of the C language, which can get complicated. However, programs are largely simplified by using sketches already developed and tested for a particular sensor or actuator. So an approach is taken in this book of using these predeveloped sketches, with some minor modifications. These modifications are documented throughout this book. All of the sketches found in this book can be downloaded from www.github.com .

Chapter 4 takes a look at the sensors available for projects. While Arduino-based sensors are the primary interest of this book, many of this book’s projects combine Arduino sensors with LEGO-made sensors or motors, so an overview is given of MINDSTORMS-based devices. A motivation to consider Arduino sensors is the wide capability they offer, but a drawback of so much variety is trying to figure out which sensor will work. So Arduino sensors are classified in this chapter by how they interface with the Arduino, either by pulse-width modulation (PWM), inter-integrated circuit (I2C), or serial peripheral interface (SPI). Some project designs need electronic components to send signals between sensors, the Arduino, and the EV3 Intelligent Brick. Such connections can involve resistor and/or capacitor circuits, so a guide is presented on understanding and buying these components.

Chapter 5 describes the first project—a metal detector built from an electromagnetic inductive sensor. The EV3 Intelligent Brick sounds and flashes an alarm when a metal is nearby, with an indication also given of how far away the metal is from the sensor. This project is first built on the LEGO Arduino Workstation of Chapter 1 and then is built in an alternate form of a handheld metal detector. The sensor in this project communicates with the Arduino by I2C and then with an analog signal to the EV3 Intelligent Brick.

Chapter 6 reverses the direction of data flow of Chapter 5, by now having the EV3 Intelligent Brick generate an analog signal that is read by the Arduino. The Arduino then sends I2C commands to the external device of a linear array of color-programmable light-emitting diodes (LEDs). Various LED color patterns can be displayed, useful for adding lighting effects to LEGO models.

Chapter 7 delves more deeply into I2C communication, a powerful tool for sending and receiving data to or from the EV3 Intelligent Brick. The I2C passes data in 7-bit words, so a description is given on how decimal numbers are represented in this digital format. I2C communication, facilitated by a programming block developed by Dexter Industries, works within the EV3 programming environment to keep programs simple. The software interface for the Arduino end of I2C is also developed and explained in this chapter.

The I2C capability built in the previous chapter is exploited in Chapter 8 to combine a lidar with LEGO inventions. The lidar can measure target distance up to 40 m, reporting results to the EV3 Intelligent Brick for a variety of possible uses. Example applications are shown in a scanning lidar for profiling an outdoor area, as well as measuring the height and canopy thickness of a tree. Scanning is accomplished by mounting the lidar on a LEGO EV3 Large Motor. Further capability is added by combining a camera with the scanning lidar, with an example project of monitoring roadway traffic. The data communication link between the Arduino and the lidar is by PWM.

Chapter 9 explores the use of sensors that communicate by SPI, in this case a weather sensor of temperature, barometric pressure, and humidity. Another environmental measurement is added by use of a LEGO EV3 Color Sensor to record the ambient light level. The EV3 Intelligent Brick logs these four meteorological parameters over the course of many hours. An example project is shown of how weather parameters vary over the course of a few days.

Chapter 10 introduces working with Arduino shields, which offer more sophisticated functionality than the discrete sensors used in earlier chapters. The shield used in this chapter is a spectrum analyzer that separates audio or music signals into several frequency bands. This spectral data is read by the EV3 Intelligent Brick in an example project to visually and mechanically represent the frequency content of music. The seven spectral bands are displayed in a bar graph format on an LED array. Also, three of the spectral bands are used to drive three different LEGO mechanisms that dance in time with music.

Whereas the previous chapter has the EV3 Intelligent Brick receiving data from an Arduino shield, Chapter 11 has the EV3 Intelligent Brick sending data to an Arduino shield. The shield used in this chapter is a vibrant two-dimensional LED display with a color adjustable by the user to contemplate their favorite color. Color adjustment is made by LEGO EV3 motors adapted to serve as control knobs for setting the levels of red, green, and blue constituent colors that get mixed together.

Chapter 12 features an Arduino shield that interfaces with a smartphone for a wide range of applications. The communications, imaging, and sensing capabilities of a smartphone can be incorporated into LEGO inventions. Two example projects are described. First, a smartphone’s orientation sensor provides data to the EV3 Intelligent Brick, which in turn orients the tilt of a LEGO liftarm to match the smartphone’s angle. The second project is a security monitor that uses an EV3 Ultrasonic Sensor to trigger the smartphone to take a picture and send email notification that an intruder has been detected.

Each project in this book is described with step-by-step instructions for the building aspects involved: LEGO part assembly, electronics, wiring, EV3 code, and Arduino sketch. All the parts used in a chapter are summarized in an appendix, along with suggested sources for purchasing electronic components. LEGO parts are also identified in each chapter with a graphical parts diagram that also gives the part’s name and number so it can be found on LEGO part supply sources such as Bricklink (www.bricklink.com ).

Table of Contents
Index 231
About the Author
Grady Koch

emphasizes building things from LEGO that can be applied to practical use in science, engineering, or security. He is the author of High-Tech LEGO Projects, LEGO Wind Energy, and Secrets of Eli’s LEGO Collection. He also writes for and runs www.hightechlego.com , which features various LEGO technology projects. His day job since 1987 has been as a research engineer with NASA Langley Research Center. There, he works with technology for remote sensing atmospheric phenomena. He holds a PhD in Electrical Engineering. And he holds three patents in the field of wind measurements with lidar.

 
About the Technical Reviewer
Gene Harding

Associate Professor Gene Harding has a Master of Science in Electrical Engineering from Rose-Hulman Institute of Technology. His experience includes 28 years of combined active and reserve service in the United States Air Force and 3 years in the private industry with Agilent Technologies. He has taught electrical engineering technology at Purdue’s South Bend location since the fall of 2003.

 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.249.105