www.allitebooks.com Robotics: A Project-Based Approach Lakshmi Prayaga, Chandra Prayaga, Alex Whiteside, and Ramakrishna Suri Cengage Learning PTR Australia • Brazil • Japan • Korea • Mexico • Singapore • Spain • United Kingdom • United States www.allitebooks.com Robotics: A Project-Based Approach Lakshmi Prayaga, Chandra Prayaga, Alex Whiteside, and Ramakrishna Suri Publisher and General Manager, Cengage Learning PTR: Stacy L Hiquet Associate Director of Marketing: Sarah Panella Manager of Editorial Services: Heather Talbot Senior Product Manager: Emi Smith Project Editor: Dan Foster © 2015 Cengage Learning PTR WCN: 01-100 CENGAGE and CENGAGE LEARNING are registered trademarks of Cengage Learning, Inc., within the United States and certain other jurisdictions ALL RIGHTS RESERVED No part of this work covered by the copyright herein may be reproduced, transmitted, stored, or used in any form or by any means graphic, electronic, or mechanical, including but not limited to photocopying, recording, scanning, digitizing, taping, Web distribution, information networks, or information storage and retrieval systems, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the publisher Technical Reviewer: Jeremy Branchcomb For product information and technology assistance, contact us at Cengage Learning Customer & Sales Support, 1-800-354-9706 Interior Layout Tech: MPS Limited Cover Designer: Mike Tanamachi For permission to use material from this text or product, submit all requests online at cengage.com/permissions Indexer: Valerie Haynes Perry Further permissions questions can be emailed to permissionrequest@cengage.com Proofreader: Sam Garvey Oracle and Java are registered trademarks of Oracle and/or its affiliates All other trademarks are the property of their respective owners All images © Cengage Learning unless otherwise noted Library of Congress Control Number: 2014945698 ISBN-13: 978-1-305-27102-9 ISBN-10: 1-305-27102-5 eISBN-10: 1-305-27103-3 Cengage Learning PTR 20 Channel Center Street Boston, MA 02210 USA Cengage Learning is a leading provider of customized learning solutions with office locations around the globe, including Singapore, the United Kingdom, Australia, Mexico, Brazil, and Japan Locate your local office at: international.cengage.com/region Cengage Learning products are represented in Canada by Nelson Education, Ltd For your lifelong learning solutions, visit cengageptr.com Visit our corporate website at cengage.com Printed in the United States of America 16 15 14 www.allitebooks.com About the Authors Dr Lakshmi Prayaga is an Associate Professor at the University of West Florida, Pensacola, Florida Her research interests include the use of advanced technologies in education, including serious games, robotics, and mobile app development She has authored and coauthored several articles in international conferences and journals She has also received several grants to build and implement educational environments using advanced technologies Dr Chandra Prayaga is a professor and chair of the physics department at the University of West Florida His research interests include study of the properties of liquid crystals, laser spectroscopy, and physics education, particularly in the use of technology such as robotics for teaching physics He has received grants to train schoolteachers in physics, physical science, and mathematics Mr Alex Whiteside is a software engineer and entrepreneur Previously employed at American Express Technologies and the U.S Air Force Research Lab, he now works as a researcher for the University of West Florida and serves as Chief Technology Officer of RILE Inc He specializes in the development of low-level server applications and user experience design (UX) for web, desktop, and mobile applications Dr Ramakrishna Suri retired as a professor in the aerospace department of the Indian Institute of Science, Bangalore, India His research specializations include electronic instrumentation payloads for rockets He has trained several PhDs in instrumentation iii www.allitebooks.com This page intentionally left blank www.allitebooks.com Contents Introduction xi Chapter Introduction to Robotics History of Robotics What Is a Robot? Robots in Commercial Applications Basic Robot Navigation Robots in the Military Wi-Fi Networking Robots in Medicine Weather Monitor User Interfaces Security Entertainment 10 Mobile Connections 10 Conclusion 10 Chapter Build Your Own Robot Sweeper 11 Chapter Objectives 11 Introduction 11 Materials Required 12 Part 1: Assembling the Robot 12 Assembling the Chassis 12 Mounting the Arduino Board 13 v www.allitebooks.com vi Contents Mounting the Ardumoto Motor Driver Shield 15 Mounting the Ultrasonic Sensor 16 Part 2: The Software 19 Using the Arduino IDE 19 Controlling the Speed and Direction of a Motor 20 Running Both Motors Using Function Calls 22 Code for the Ultrasonic Sensor 24 Part 3: Putting It All Together 26 Complete Code for the Sweeper Robot 27 Conclusion 32 Chapter Traveling Robot 33 Chapter Objectives 33 Introduction 33 Materials Required 34 Part 1: Line Sensor 34 How Does a Line Sensor Work? 34 Assembling the Robot with the Sensors 36 lineSensorChk Sketch 37 Using the lineSensorChk Sketch .38 How the lineSensorChk Code Works 39 Part 2: Line Tracking 39 LineTracker Sketch 40 How the Code Works 42 Part 3: Learning to Use the Color Sensor 43 Connections between the Color Sensor Pins and Arduino Board Pins .47 lineClrSensor Sketch for Testing the Line Sensors and the Color Sensor 48 Testing the lineClrSensor Sketch 49 How the Code Works 51 Part 4: Making the Robot Follow a Track and Stop at a Specific Point for a Prescribed Time 51 lineandColorSensorTest Sketch 51 How the Code Works 55 Conclusion 56 Chapter Intruder Alarm 57 Chapter Objectives 57 Introduction 57 Materials Required 58 www.allitebooks.com Contents vii Activity 1: Intruder Alarm with a Diode Laser and Photoresistor 58 Sketch to Control the Laser 61 How the Code Works 61 Sketch to Control the Photoresistor 61 How the Code Works 63 Sketch Combining the Laser and the Photoresistor 64 How the Code Works 64 Activity 2: Proximity Alarm with an Ultrasonic Range Sensor 65 Sketch for the Proximity Alarm 66 How the Code Works 67 Activity 3: Touch Sensor and Alarm 67 Sketch for the Touch Sensor 68 How the Code Works 69 Activity 4: Keyboard and LEDs 69 Sketch to Light Up LEDs with Touch 70 How the Code Works 72 Conclusion 72 Chapter Robot Networking and Communications with Wi-Fi 73 Chapter Objectives 73 Introduction 73 Materials Required 75 Part 1: Installing the Wi-Fi Sensor and Connecting to Your Network 75 Connecting to an Open Network 79 Connecting to a Closed Network 80 Part 2: Creating a Telnet Server 81 For Microsoft Windows Users 83 For Mac/Linux Users 84 The Complete Sketch 85 Conclusion 88 Chapter Robot Medical Assistant 89 Chapter Objectives Introduction Materials Required Program Components and Connections Pill Reminder Sketch How the Code Works Conclusion www.allitebooks.com 89 89 90 90 94 96 99 viii Contents Chapter Data Logger 101 Chapter Objectives 101 Introduction 101 Materials Required 102 Part 1: Measuring and Displaying Ambient Temperature 102 Hardware Connections 103 Writing the Sketch 106 How the Code Works 107 Part 2: Data Logging Activities 108 Activity 1: Initializing the SD Card Reader 109 Activity 2: Writing Data to an SD Card 111 Activity 3: Reading Data from a File 115 Activity 4: Logging Temperature Data 117 Conclusion 120 Chapter Remote-Controlled User Interfaces 121 Chapter Objectives 121 Introduction 121 Development Software 122 A Graphical Control for Arduino 124 Materials Required 125 Introduction to Java 125 Downloading and Installing NetBeans 126 Networking in Java 127 Creating the User Interface 131 Optional Activities 138 Conclusion 139 Chapter Security Robot 141 Chapter Objectives 141 Introduction 141 Materials Required 142 Setting Up the Hardware 142 The Complete Relevant Code Blocks 146 Variable Setup 146 Capture Photo Function 146 Conclusion 148 www.allitebooks.com Contents Chapter 10 ix Light and Sound 149 Chapter Objectives 149 Introduction 149 Materials Required 149 Part 1: Connect the NeoPixel Ring to the Arduino and Program Pixel Colors 150 pixelColor0 Sketch 154 How the Code Works 156 pixelColor1 Sketch 157 How the Code Works 158 pixelColor2 Sketch 159 How the Code Works 161 Part 2: Attaching the Microphone 162 soundSensor1 164 How the Code Works 164 Part 3: Putting It All Together 165 soundLight4 166 How the Code Works 167 Conclusion 168 Chapter 11 Android App Controller 169 Chapter Objectives 169 Introduction 170 Materials Required 170 Part 1: Getting Ready for Android 170 Android Programming Architecture and Language 171 Installing the Android Developer Kit 172 Installing the Genymotion Android Emulator 175 Creating a Sample Application 180 Part 2: Creating an Arduino Controller App 185 Conclusion 198 Chapter 12 Additional Robotics Applications 199 Robots in Medicine 199 Robots in Education 200 Robots in the Military and Law Enforcement 201 Robots in Industrial Applications 202 Trends in Robot Types 202 Soft Robotics 202 Swarm Robots 203 Conclusion 204 www.allitebooks.com Glossary AJAX Asynchronous JavaScript and XML algorithm An algorithm is written to perform calculations in an ordered fashion to achieve an objective ambient temperature refers to the temperature outside Arduino an open-source electronics platform Ardumoto a motor shield that can control two DC motors Artificial Intelligence (AI) Machines with intelligence built in with software show artificial intelligence Baud rate speed at which data is transferred Bluetooth This technology uses short wavelength radio waves for establishing wireless connections over short distances CCD Charge-Coupled Device CMOS Complementary Metal-Oxide-Semiconductor color sensor Color sensors give varying outputs depending on the colors to which they are exposed CSS Cascading Style Sheets drones unmanned aerial vehicles with extensive military applications DSLR Digital Single-Lens Reflex (camera) FXML JavaFX Extensible Markup Language 209 210 Glossary GUI Graphical User Interface HTML HyperText Markup Language is the standard markup language used to create web pages humanoid A humanoid robot is a robot with its body shape built to resemble that of the human body IDE Integrated Development Environment; a tool for software development IEEE 802.11 802.11 is the generic name of a family of standards for wireless networking related to Wi-Fi IP address Internet Protocol address is the label assigned to each device in a computer network IR emitter detector an infrared sensor that sends out an infrared signal and receives the reflected energy from an object Java Java is a programming environment that allows you to play online games, chat with people around the world, calculate your mortgage interest, and view images in 3D, just to name a few examples JavaFX variant of Java, extensively used in RIA (Rich Internet Applications) JavaScript JavaScript is the programming language of the Web JDK Java Development Kit LAN Local Area Network is a computer network that interconnects computers within a limited area like a home or school LCD Liquid Crystal Display LED Light-Emitting Diode MAC address The Media Access Control address is a unique value associated with a network adapter composed of 12-digit hexadecimal numbers Magician Chassis A kit manufactured by SparkFun for use with Arduino boards The chassis comes with a set of two wheels and a platform for mounting the Arduino board and associated shields MATLAB MATLAB is a high-level technical computing language and interactive environment for algorithm development modem a modulator/demodulator used to encrypt analog data for transmitting over a wireless network NetBeans IDE NetBeans is an Integrated Development Environment (IDE) for development primarily with Java It is also used with other languages such as PHP and C/C++ Glossary 211 Ni-MH batteries nickel-metal hydride rechargeable batteries pairing establishing a connection between two Bluetooth devices pheromones Pheromones are chemicals released by an organism into its environment, enabling it to communicate with other members of its own species photoresistor a sensor whose resistance changes with changes in the amount of light falling on it PHP PHP is an acronym for “PHP Hypertext Preprocessor”; PHP is a widely used, opensource scripting language piezo-buzzer a device that sends a beep/makes noise proximity alarm a device which produces an alarm when someone is in the vicinity Python a programming language Qt Qt is a cross-platform application and UI framework for developers using C++ or QML, a CSS & JavaScript-like language quadcopter a helicopter that is lifted and propelled by four rotors router A networking device that forwards data packets between computer networks SD card Secure Digital non-volatile memory card shield commonly used to denote an add-on board in Arduino hardware SparkFun a company that manufactures many products used in projects with the Arduino boards Swing Swing is the primary Java GUI widget toolkit syntax In programming, syntax refers to the rules that specify the correct combined sequence of symbols that can be used to form a correctly structured program using a given programming language Programmers communicate with computers through the correctly structured syntax, semantics, and grammar of a programming language telemedicine the practice of medicine using wireless techniques telerobotics the area of robotics concerned with the control of semi-autonomous robots from a distance, chiefly using wireless networks Telnet a network protocol that provides a bidirectional interactive text-oriented communication facility TO-92 package a 3-pin plastic header-style package used mainly for transistors torque Torque is a measure of how much a force acting on an object causes that object to rotate 212 Glossary touch sensor a sensor that gives out a signal when someone touches it UART Universal Asynchronous Receiver/Transmitter ultrasonic sensor A sensor that emits an ultrasonic signal and detects the reflected signal The time between the signal being sent and being received gives a measure of the distance of the object untethered connection In untethered communications, there are no physical connections using wires and, as such, there are no constraints USB Universal Serial Bus Velcro fabric fasteners Wi-Fi local area wireless technology that enables an electronic device to connect to the Internet INDEX Symbols ; (semicolon), using with code lines, 23 // (slashes), using with comments, 20–22 A AI (Artificial Intelligence), explained, 209 AJAX acronym, 209 alarm described, 57 with diode laser, 58–65 keyboard and LEDs, 58 laser and photoresistor, 64–65 materials required, 58, 206 with photoresistor, 58–65 proximity alarm, 58 touch sensor and alarm, 58 algorithm, defined, 209 ambient temperature displaying, 102–108 explained, 209 measuring, 102–108 analogWrite() command, 20, 31 Android app controller application state, 171 architecture and language, 171–172 assigning listener, 195 buttons for movement, 187–189 connect method, 190 creating, 189 default run configuration, 181 developer settings, 184 device for debugging, 185 device selection, 182 Eclipse IDE, 180 editing Hello World text box, 186 error handling, 191–194 functionality for buttons, 195–197 Genymotion emulator, 175–179 Hello World! application, 183 libraries in Eclipse, 189 materials required, 170, 207 MVC diagram, 171 onCreate() method, 196–197 op-codes for Arduino server, 196 overview, 170 sample application, 180–185 updating welcome screen, 187 XML editor, 186 Android Developer Kit, installing, 172–175 Android framework, 172 app controller (Android) application state, 171 architecture and language, 171–172 assigning listener, 195 buttons for movement, 187–189 connect method, 190 creating, 189 default run configuration, 181 developer settings, 184 213 214 Index app controller (Android) (Continued ) device for debugging, 185 device selection, 182 Eclipse IDE, 180 editing Hello World text box, 186 error handling, 191–194 functionality for buttons, 195–197 Genymotion emulator, 175–179 Hello World! application, 183 libraries in Eclipse, 189 materials required, 170, 207 MVC diagram, 171 onCreate() method, 196–197 op-codes for Arduino server, 196 overview, 170 sample application, 180–185 updating welcome screen, 187 XML editor, 186 Arduino connecting user interface to, 136–138 explained, 209 graphical control, 124–125 interfacing with Java, 124 Arduino board batteries, 14 battery clip with plug, 14–15 connecting to, 14–15 mounting for chassis, 13–15 pin connections, 16 power source, 14 solderless breadboard, 14 Arduino IDE, using, 19–20 ArduinoCommunicator class creating functions, 135–136 naming, 131 Ardumoto board analog pins, 17 digital pins, 17 DIRA pin, 17 DIRB pin, 17 GND pin, 17 motors, 18 photo, 18 PWMA pin, 17 PWMB pin, 17 RST pin, 17 setting up, 30 terminals, 18 VIN pin, 17 Ardumoto Motor Driver Shield, 15 Aristotle’s Politics, artificial being, introduction of, 1–2 B baud rate, explained, 209 Bluetooth, explained, 209 breadboards, using, 17 C camera sensors, camera shield, testing, 143–144 capacitive effect, 68 CCD (Charge-Coupled Device), 142, 209 chassis Arduino board, 13–15 Ardumoto Motor Driver Shield, 15 assembling for Roomba, 12–13 ultrasonic sensor, 16–19 See also Magician Chassis CMOS acronym, 209 color sensor explained, 209 header pins, 45 I2C serial connection, 46 mounted on robot, 45 pins, 46–47 SCL and SDA wires, 47–48 using with traveling robot, 43–47 commercial applications, 2–3 CSS acronym, 209 CW direction, using with motors, 23 D data logger hardware connections, 103–106 including SD.h library, 116 LCDTemp sketch, 106–108 Index logging temperature data, 117–120 materials required, 102, 206 overview, 101–102 reading data from file, 115–117 SD card reader, 109–111 SD card shield, 108–109 TMP36 temperature sensor, 102–103 writing data to SD card, 111–115 delay() function, using with motors, 24 detective robot, digital cameras CCD (Charge-Coupled Device), 142 lens, 141 processor, 141–142 sensor, 141–142 digitalWrite command, using with sweeper robot, 31 diode laser code explanation, 61 photo of module, 60 and photoresistor, 64–65 pin connections, 60 sketch for control, 61 using with intruder alarm, 59 DIR command, using with motors, 22 distances, checking, 26 driveArdumoto() function, 31 drones, explained, 209 DSLR acronym, 209 dust cloth, attaching to robot, 27 E Eclipse IDE, using with Android app controller, 180 education muscle tissue for, 201 robotlabs, 200 robots in, 200–201 F function, using with motors, 23, 30–31 FXML acronym, 209 forward() 215 G Genymotion Android Emulator Add device interface, 178 installing, 175–179 interface, 177 virtual machine, 179 VirtualBox interface, 176 GUI (graphical user interface), explained, 121, 210 See also remote-controlled GUIs; UI (user interface) H HTML acronym, 210 humanoid, explained, 210 I IDE (Integrated Development Environment), 19–20, 210 IEEE 802.11, explained, 210 if condition, using with sweeper robot, 31 industrial applications, robots in, 201 intruder alarm described, 57 with diode laser, 58–65 keyboard and LEDs, 58 laser and photoresistor, 64–65 materials required, 58, 206 with photoresistor, 58–65 proximity alarm, 58 touch sensor and alarm, 58 IP address, explained, 210 IR emitter detector, explained, 210 J Java interfacing with Arduino, 124 JFrame Editor, 131–132 nested functions, 130 networking in, 127–131 programming environment, 210 Socket, 128–129 using with remote-controlled GUIs, 122, 125–126 216 Index JavaFX, explained, 210 JavaScript/Web user interfaces, using with remote-controlled GUIs, 123 JDK acronym, 210 JFrame Editor, using to create buttons, 132 K K-12 education, use of robots in, 200 keyboard and LEDs code explanation, 72 explanation, 69–70 sketch, 70–72 L LAN (Local Area Network), explained, 210 law enforcement, robots in, 201 LCD acronym, 210 LCDTemp sketch code explanation, 107 writing, 106–107 LED acronym, 210 light and sound system attaching microphone, 162–165 materials required, 149–150, 207 overview, 149 soundLight4, 166–168 See also NeoPixel ring line sensor assembling traveling robot with, 36–37 jumper wire connections, 37 mounted, 35 QRE1113, 35 using with traveling robot, 34–35 LineandColorSensorTest code explanation, 54–55 typing code, 51–54 lineClrSensor sketch code explanation, 51 testing, 49–50 typing code, 48–49 using with traveling robot, 48–51 lineSensorChk sketch code explanation, 39 typing code, 37–38 using, 38–39 LineTracker sketch, 40–47 loop() function, 21–22 M MAC address, explained, 210 Magician Chassis battery compartment, 13 bottom, 13 explained, 210 motors, 13 top, 13 wheels, 13 See also chassis MATLAB acronym, 210 medical assistant components and connections, 90–93 explained, 89–90 LCD panel connections, 90–92 materials required, 90, 206 pill reminder sketch, 94–99 pins, 91 potentiometer, 93 potentiometer connections, 91 push button, 92–93 push button connections, 92 setup, 93 speaker connections, 92 Timer() function, 92 medicine, robots in, 6, 199–200 microphone sensor attaching, 162–165 code explanation, 164–165 connections, 163 package, 162–163 powering, 163 soundSensor1, 164 military, robots in, 4, 201 milliseconds, converting to distance, 26 modem, explained, 210 motor control, code for, 30 motor direction, controlling, 20–22 motor speed, controlling, 20–22 motors commenting code, 20–22 CW direction, 23 Index function, 24 function, 23 running using function calls, 22–24 turns, 24 delay() forward() N navigation, 3–4 NeoPixel ring battery pack, 152, 154 capacitor, 152–153 connecting to Arduino board, 165–168 description, 150 front and back, 151 obtaining, 150 pixelColor0 sketch, 154–157 pixelColor1 sketch, 157–159 pixelColor2 sketch, 159–162 resistor, 152–153 soldering, 152 terminals, 152 See also light and sound system NetBeans IDE downloading, 126–127 explained, 210 installing, 126–127 NewPing statement, using with sweeper robot, 30 Ni-MH batteries, explained, 211 O Objective C, using with remote-controlled GUIs, 124 pill reminder sketch, 94–99 pixelColor0 sketch code, 155 code explanation, 156–157 pixelColor1 sketch code, 157–158 code explanation, 158–159 pixelColor2 sketch code, 159–161 code explanation, 161–162 Politics, prescription medication reminder components and connections, 90–93 explained, 89–90 LCD panel connections, 90–92 materials required, 90, 206 pill reminder sketch, 94–99 pins, 91 potentiometer, 93 potentiometer connections, 91 push button, 92–93 push button connections, 92 setup, 93 speaker connections, 92 Timer() function, 92 proximity alarm circuit, 65 code explanation, 67 explained, 211 sketch, 66 with ultrasonic range sensor, 65–67 PWM command, using with motors, 22 Python, explained, 211 Python, using with remote-controlled GUIs, 123 P pairing, explained, 211 pheromones, explained, 211 photoresistor code explanation, 63 and diode laser, 64–65 explained, 211 pin connections, 62 sketch to control, 61–63 PHP (PHP Hypertext Preprocessor), 211 piezo-buzzer, explained, 211 217 Q QRE1113 Analog line sensor, 35 Qt, explained, 211 quadcopter, explained, 211 R remote-controlled GUIs adding sensors, 138 ArduinoCommunicator class, 131 218 Index remote-controlled GUIs (Continued ) completing, 136–138 connecting to Arduino, 136–138 controlling motors, 133 creating, 131–138 development software, 122–124 improving design, 138 Java, 122, 125–126 JavaScript/Web user interfaces, 123 materials required, 125, 207 NetBeans IDE, 126–127 networking in Java, 127–131 Objective C, 124 op-codes for actions, 134 overview, 121–122 printing interface state, 138 providing motion, 133–134 Python, 123 setting pins, 133 system diagram, 124 See also GUI (graphical user interface); UI (user interface) robot medical assistant components and connections, 90–93 explained, 89–90 LCD panel connections, 90–92 materials required, 90, 206 pill reminder sketch, 94–99 pins, 91 potentiometer, 93 potentiometer connections, 91 push button, 92–93 push button connections, 92 setup, 93 speaker connections, 92 Timer() function, 92 robot sweeper analogWrite() command, 31 Arduino board, 17, 19 Arduino IDE, 19–20 battery clip, 19 chassis assembly, 12–13 code, 27–29 completing, 19 constants, 30 describing intended actions, 26–27 digitalWrite command, 31 direction of motor, 20–22 explained, 2–3 if condition, 31 materials required, 12, 205 motor control, 30 NewPing statement, 30 setupArdumoto() function, 31 speed of motor, 20–22 testing, 32 ultrasonic sensor, 17, 24–26 variables, 30 voidloop() function, 30 voidturnRight() function, 31 wires to motor, 19 robot types soft robotics, 202–203 swarm robots, 203 trends in, 202–203 robotics applications, 196–197 history, 1–2 robotlabs, 200 robots attaching dust cloth to, 27 in commercial applications, 2–3 versus computers, definition, as detectives, versus machines, in medicine, in military, mobility, navigation, 3–4 UI (user interface), Roomba vacuum cleaner analogWrite() command, 31 Arduino board, 17, 19 Arduino IDE, 19–20 battery clip, 19 chassis assembly, 12–13 code, 27–29 completing, 19 constants, 30 describing intended actions, 26–27 digitalWrite command, 31 Index direction of motor, 20–22 explained, 2–3 if condition, 31 materials required, 12, 205 motor control, 30 NewPing statement, 30 setupArdumoto() function, 31 speed of motor, 20–22 testing, 32 ultrasonic sensor, 17, 24–26 variables, 30 voidloop() function, 30 voidturnRight() function, 31 wires to motor, 19 router, explained, 211 S SD card code explanation, 114–115 connecting pins, 112 explained, 211 setting up digital data, 111–112 software, 112–114 writing data to, 111–115 SD card reader code explanation, 111 hardware, 109–110 software, 110–111 security robot capture photo function, 146–148 code blocks, 146–148 digital cameras, 141 hardware setup, 142–146 materials required, 142, 207 overview, 141 saving multiple images, 144–145 shield connections, 143 testing, 145–146 testing camera shield, 143–144 variable setup, 146 semicolon (;), using with code lines, 23 setup function, using with ultrasonic sensor, 26 setupArdumoto() function, 23, 31 shield, explained, 211 singleMotorControl file, saving, 21 slashes (//), using with comments, 20–22 soft robotics, 202–203 sound system See light and sound system soundLight4 code, 166–167 code explanation, 167–168 loop() function, 168 onPixels() function, 168 setup() function, 168 SparkFun explained, 211 website, 15 swarm robots, 203 sweeper robot analogWrite() command, 31 Arduino board, 17, 19 Arduino IDE, 19–20 battery clip, 19 chassis assembly, 12–13 code, 27–29 completing, 19 constants, 30 describing intended actions, 26–27 digitalWrite command, 31 direction of motor, 20–22 explained, 2–3 if condition, 31 materials required, 12, 205 motor control, 30 NewPing statement, 30 setupArdumoto() function, 31 speed of motor, 20–22 testing, 32 ultrasonic sensor, 17, 24–26 variables, 30 voidloop() function, 30 voidturnRight() function, 31 wires to motor, 19 Swing, explained, 211 syntax, explained, 211 T telemedicine, explained, 211 telerobotics, explained, 199, 211 Telnet, explained, 211 219 220 Index Telnet server connecting to incoming client, 82 creating, 81–85 interacting with client, 82–83 Mac/Linux users, 84–85 Microsoft Windows users, 83–84 setup function, 82 temperature displaying, 102–108 measuring, 102–108 temperature data code explanation, 119–120 hardware connection, 117 logging, 117–120 sketch, 117–119 TMP36 temperature sensor hardware connections, 103–106 LCD panel pin connections, 104–106 pin connections, 104 TO-92 package, explained, 211 torque, explained, 211 touch sensor code explanation, 69 explained, 212 sketch, 68–69 touch sensor and alarm capacitive effect, 68 connections, 68 traveling robot assembling with sensors, 36–37 code explanation, 42–43 color sensor, 43–51 following track, 51–56 jumper wire connections, 37 line sensor, 34–39 line tracking, 39–43 LineandColorSensorTest, 51–56 lineClrSensor sketch, 48–51 lineSensorChk sketch, 37–39 LineTracker sketch, 40–42 materials required, 34, 205 pin connections, 47–48 stopping at specific point, 51–56 Turing, Alan, turns, coding, 24 U UI (user interface), See also GUI (graphical user interface); remote-controlled GUIs ultrasonic sensor code, 24–26 ECHO_PIN variable, 25 explained, 212 functionality, 16 loop, 26 MAX_DISTANCE variable, 25 photo, 16 pin connections, 16–17 setup function, 26 sonar object, 26 TRIGGER_PIN variable, 25 untethered connection, explained, 212 USB acronym, 212 V vacuum cleaner robot analogWrite() command, 31 Arduino board, 17, 19 Arduino IDE, 19–20 battery clip, 19 chassis assembly, 12–13 code, 27–29 completing, 19 constants, 30 describing intended actions, 26–27 digitalWrite command, 31 direction of motor, 20–22 explained, 2–3 if condition, 31 materials required, 12, 205 motor control, 30 NewPing statement, 30 setupArdumoto() function, 31 speed of motor, 20–22 testing, 32 ultrasonic sensor, 17, 24–26 variables, 30 voidloop() function, 30 voidturnRight() function, 31 wires to motor, 19 Index Velcro, explained, 212 void, using before forward() function, 23 voidloop() function, 30 voidturnRight() function, 31 W weather monitoring, Wi-Fi explained, 212 materials required, 75 overview, 73–74 Wi-Fi networking, 5–6 Wi-Fi sensor calling printNetworks() function, 77 commands, 76 complete sketch, 85–87 connectClosedNetwork() function, 80 connecting to closed network, 80–82 connecting to open network, 79–80 installing, 75–79 materials required, 206 security IDs, 79 serial monitor, 78 setup() function for open network, 79–80 setup loop, 76 testing, 76 221 This page intentionally left blank Look for complete video tutorials for each project in this book on www.cengageptr.com ...Robotics: A Project-Based Approach Lakshmi Prayaga, Chandra Prayaga, Alex Whiteside, and Ramakrishna Suri Cengage Learning PTR Australia • Brazil • Japan • Korea • Mexico • Singapore • Spain • United... States www.allitebooks.com Robotics: A Project-Based Approach Lakshmi Prayaga, Chandra Prayaga, Alex Whiteside, and Ramakrishna Suri Publisher and General Manager, Cengage Learning PTR: Stacy... ultrasonic sensor Put it all together Materials Required n Arduino Uno R3 board (Amazon, SparkFun, Adafruit) n Magician chassis kit (Amazon, SparkFun) n Ardumoto board (Amazon, SparkFun) n Ultrasonic