9781788830584 Flipbook PDF


35 downloads 102 Views 846KB Size

Recommend Stories


Porque. PDF Created with deskpdf PDF Writer - Trial ::
Porque tu hogar empieza desde adentro. www.avilainteriores.com PDF Created with deskPDF PDF Writer - Trial :: http://www.docudesk.com Avila Interi

EMPRESAS HEADHUNTERS CHILE PDF
Get Instant Access to eBook Empresas Headhunters Chile PDF at Our Huge Library EMPRESAS HEADHUNTERS CHILE PDF ==> Download: EMPRESAS HEADHUNTERS CHIL

Story Transcript

EXPERT INSIGHT

Jon Hoffman

Mastering Arduino

A project-based approach to electronics, circuits, and programming

FOR SALE IN INDIA ONLY

Mastering Arduino

A project-based approach to electronics, circuits, and programming

Jon Hoffman

BIRMINGHAM - MUMBAI

Mastering Arduino Copyright © 2018 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Acquisition Editor: Ben Renow-Clarke, Suresh Jain Project Editor: Radhika Atitkar Content Development Editor: Alex Sorentinho Technical Editor: Gaurav Gavas Proofreader: Safis Editing Indexer: Tejal Daruwale Soni Graphics: Tom Scaria Production Coordinator: Sandip Tadge

First published: September 2018 Production reference: 1270918

Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78883-058-4

www.packt.com

I would like to thank my wife, Kim; without her support none of my books would have been possible. I would also like to thank my two daughters who have both been my inspiration and driving force since the days they were born. -Jon Hoffman

Packt Upsell

mapt.io

Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.

Why subscribe? Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals Improve your learning with Skill Plans built especially for you Get a free eBook or video every month Mapt is fully searchable Copy and paste, print, and bookmark content

packt.com Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.

Contributors About the author Jon Hoffman has over 25 years of experience in the field of Information Technology. Over those years, Jon worked in the areas of System Administration, Network Administration, Network Security, Application Development, and Architecture. Currently, Jon works as an Enterprise Software Manager for Syntech Systems. Jon has developed extensively for the iOS platform since 2008. This includes several apps that he has published in App Store, apps that he wrote for third parties and numerous enterprise applications. What really drives Jon is the challenges in the Information Technology field, and there is nothing more exciting to him than overcoming a challenge. Some of Jon’s other interests are baseball and basketball. Jon also really enjoys TaeKwonDo, where he and his oldest daughter earned their Black Belts together early in 2014. Kim (his wife) earned her Black Belt at the end of 2014.

About the reviewers Dr. Pratik Desai is a computer scientist and an engineering leader. His fields of expertise include the Internet of Things, Artificial Intelligence, and Connected Cars. He is a pioneer researcher in IoT and the published author of Python Programming for Arduino. In his spare time, Pratik likes tinkering with sensors and working on Python projects. Ejike is a developer with a serious love of sharing his skills and knowledge with his fellow developers and beginners in the industry. He has spent his few years as a lead instructor in computer programming and has enjoyed the most part of his life doing live trainings with over hundreds of students. Ejike derives joy in building the next generation of software and hardware developers who do amazing things in the industry today. He led the team of developers who participated in Forbes' Under 30 Change the World Challenge, judged by a panel of professionals at the Wharton school of the university of Pennsylvania in 2015. His love for computer programming in his early stage in life got Ejike into Java, C, C#, C++, Python, MikroC, Arduino, and lots of other programming languages and embedded system designs. He began to think that he is crazy until I started developing advance projects for clients and getting amazing job offers from reputable companies across America, Asia, and Africa. The worst part of Ejike’s life as a software developer is seeing himself coding always in his dreams. The best part of his life as a developer is NOT building advanced and complicated projects with different programming languages combine together, but, building the next generation of developers and seeing them excel in the industry like him and other senior developers around him. He is always happy each time his students get across to him to tell him how they successfully got employed by one reputable firm or the other, and how they pick up fast in their respective companies to become senior developers with mouth-watering salaries! Ejike’s courses are one of the most comprehensive ones in the market today!

Packt is searching for authors like you If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.

Table of Contents Preface Chapter 1: The Arduino History of the Arduino What is the Arduino?

Touring the Arduino UNO R3 Powering the Arduino

Using the VIN/GND pins to power the Arduino Using the DC supply input to power the Arduino Using the USB connector to power the Arduino

Arduino shields Arduino pin

Digital pins Analog input pins PWM pins Power pins Serial pins SPI pins

Different Arduino boards Arduino Micro Arduino Mega 2560 Lilypad Arduino Nano Generic boards

Summary Chapter 2: Basic Electronics Electronic building block Power supply Input Output Control circuit

Multimeter Electronic components Resistor Potentiometer Switches Transistor LED Capacitor

1 7 8 10 11 12 13 13 14 15 17 18 18 18 19 20 20 20 21 21 22 23 23 26 27 28 29 29 29 30 30 34 35 35 36 37 38 38

Table of Contents

Integrated circuit

39 40 41 42 43 44 46 46 47

What is electricity? Current Voltage Resistance Ohm's law What is power? Resistor color codes Summary Chapter 3: Circuit Diagrams What is a circuit? Fritzing Fritzing diagrams Schematic diagrams Parallel and series circuits Series circuits

49 49 54 54 56 58 58 59 59 59 60 60 61 61 62 62 64

Resistance Voltage Current

Parallel circuits Resistance Voltage Current

Voltage drop Light up LED Summary Chapter 4: Basic Prototyping Setting up a work area Using a solderless breadboard Dupont (jumper) cables Prototyping

Four building blocks of an electronic project Creating a diagram Building the prototype

First prototype Summary Chapter 5: Arduino IDE Arduino Sketch Arduino IDE

Exploring the IDE Configuring the Arduino within the IDE

Arduino web editor

[ ii ]

65 66 67 72 73 74 75 76 76 79 81 81 82 83 84 86

Table of Contents

Exploring Configuring the Arduino within the IDE

Examples Arduino libraries Serial monitor Hello World Echo Summary Chapter 6: Programming the Arduino - The Basics Curly brackets Semicolons Comments Variables Data types Boolean Byte Integer Long Double and float Character

Arrays Character arrays Constants Arithmetic functions Comparison operators Logical operators Casting Decision making Looping Functions Summary Chapter 7: Programming the Arduino - Beyond the Basics Setting digital pin mode Digital write Digital read Analog write Analog read Structures Unions Adding tabs Working with tabs Object-oriented programming [ iii ]

88 89 89 93 97 100 101 103 105 106 106 106 107 108 108 108 108 109 109 110 110 112 113 114 115 115 116 116 119 121 123 125 126 127 128 129 131 132 134 135 139 141

Table of Contents

String library Summary Chapter 8: Motion Sensor Introduction Components needed Circuit diagrams Code Running the project Challenge Summary Chapter 9: Environment Sensors Introduction Components needed Circuit diagrams Code Running the project Challenge Summary Chapter 10: Obstacle Avoidance and Collision Detection Introduction Crash sensor Obstacle avoidance sensor Ultrasonic range finder

Components needed Circuit diagrams Code Running the project Challenge Summary Chapter 11: Fun with Lights Introduction Components needed Circuit diagrams Code

144 146 147 147 150 151 153 154 155 155 157 157 160 160 161 169 170 170 171 171 171 173 174 175 176 177 179 180 181 183 183 186 186 187 187 189 192 192 193

RGB LED NeoPixel shield

Running the project Challenge Summary Chapter 12: Fun with Sound

195

[ iv ]

Table of Contents

Introduction Components needed Circuit diagrams Code

Using the tone function Playing a ringtone in the RTTTL format

Challenge Summary Chapter 13: Using LCD Displays Introduction Components needed Circuit diagrams Code Drawing a line Displaying text Rotating text Basic shapes Filled shape Rectangle Filled rectangle Rounded rectangle Filled rounded rectangle

Challenge Summary Chapter 14: Speech Recognition and Voice Synthesizing Introduction Components needed Circuit diagrams Code Running the project Challenge Summary Chapter 15: DC Motors and Motor Controllers Introduction Components needed Circuit diagrams Code Running the project Challenge Summary Chapter 16: Servo Motors [v]

195 197 198 198 199 202 206 206 207 207 209 210 211 212 213 215 215 216 217 217 218 219 220 220 221 221 223 224 224 227 227 228 229 229 233 234 236 237 237 238 239

Table of Contents

Introduction Components needed Circuit diagrams Code Challenge Summary Chapter 17: Using a Relay Introduction Components needed Circuit diagrams Code Challenge Summary Chapter 18: Remotely Controlling the Arduino Introduction Components needed Circuit diagrams Code Challenge Summary Chapter 19: Creating a Robot Introduction Chassis and movement Motors and power Autonomous robot–obstacle avoidance and collision detection Remotely controlling a robot User feedback Making things rotate Non-robotic projects Weather station Smart thermostat

Proximity sensor Challenge Summary Chapter 20: Bluetooth LE Introduction Bluetooth LE radio

239 241 242 243 245 245 247 247 251 251 253 254 254 255 255 258 259 261 265 266 267 267 268 272 274 278 278 279 280 280 280 281 281 281 283 283 285 287 287 288 289

Network topology

Bluetooth LE broadcasting Bluetooth LE connections

Bluetooth LE profiles

[ vi ]

Table of Contents

Generic access profile (GAP) Generic attribute (GATT) profile

HM-10 Bluetooth module

Components needed Circuit diagrams Project 1 – serial communication

Test command Query software version Restore factory default Restart module Query MAC (Media Access Control) address Set name Query name Set the advertising interval Query the advertising interval Set advertising type Query advertising type Set baud rate Query baud rate Set characteristic id Set service id Query service id Set role Query role Clear last connected device Try to connect to last connected device Try to connect to an address Set pin code Query pin code Set module power Query module power Set bond mode Query bond mode Set notify information Query notify information

Project 2 – controlling LED Project 3 – environmental sensor What is new with Bluetooth 4.1, 4.2 and 5.0? Bluetooth 4.1 Bluetooth 4.2 Bluetooth 5.0 Bluetooth mesh

Challenge Summary Chapter 21: Bluetooth Classic

289 291 295 296 297 298 301 301 302 302 302 302 302 303 303 304 304 304 305 305 305 305 305 306 306 306 307 307 307 307 308 308 308 308 308 315 317 321 321 321 321 322 322 322

323

[ vii ]

Mastering Arduino Mastering Arduino is an all-in-one guide to getting the most out of your Arduino. This practical, no-nonsense guide teaches you all of the electronics and programming skills that you need to create advanced Arduino projects. This book is packed full of real-world projects for you to practice on, bringing all of the knowledge in the book together and giving you the skills to build your own robot from the examples in this book. The final two chapters discuss wireless technologies and how they can be used in your projects. The book begins with the basics of electronics, making sure that you understand components, circuits, and prototyping before moving on. It then performs the same function for code, getting you into the Arduino IDE and showing you how to connect the Arduino to a computer and run simple projects on your Arduino. Once the basics are out of the way, the next 10 chapters of the book focus on small projects centered around particular components, such as LCD displays, stepper motors, or voice synthesizers. Each of these chapters will get you familiar with the technology involved, how to build with it, how to program it, and how it can be used in your own projects.

www.packtpub.com

Things you will learn:

• Explains the basics of electronics and circuits along with the Arduino IDE and basic C operations

• Use sensors to build a mini weather station

• Control LEDs using code • Power a robot arm using stepper motors

• Remotely control your Arduino using RF, Bluetooth LE, and Bluetooth Classic

• Make a sound tone generator with buttons

FOR SALE IN INDIA ONLY

Get in touch

Social

© Copyright 2013 - 2024 MYDOKUMENT.COM - All rights reserved.