You are previewing Make an Arduino-Controlled Robot.

Make an Arduino-Controlled Robot

Cover of Make an Arduino-Controlled Robot by Michael Margolis Published by O'Reilly Media, Inc.
  1. Make an Arduino-Controlled Robot
  2. SPECIAL OFFER: Upgrade this ebook with O’Reilly
  3. A Note Regarding Supplemental Files
  4. Preface
    1. Who This Book Is For
    2. How This Book Is Organized
    3. What Was Left Out
    4. Code Style (About the Code)
    5. Arduino Hardware and Software
    6. Conventions Used in This Book
    7. Using Code Examples
    8. Safari® Books Online
    9. How to Contact Us
    10. Acknowledgments
  5. 1. Introduction to Robot Building
    1. Why Build a Robot?
    2. How Robots Move
    3. Tools
  6. 2. Building the Electronics
    1. Hardware Required
    2. Construction Techniques
      1. Soldering
      2. Building the Motor Controller
      3. Soldering the Reflectance Sensors
      4. Making a Line Sensor Mount
      5. Next Steps
  7. 3. Building the Two-Wheeled Mobile Platform
    1. Hardware Required
    2. Mechanical Assembly
      1. Lay Out the Chassis Parts
      2. Motor Assembly
      3. Assemble the Chassis Components
      4. Attaching the Control Electronics
    3. Mounting the IR sensors
      1. Mounting the IR Sensors for Edge Detection
      2. Mounting the IR Sensors for Line Following
    4. Next Steps
  8. 4. Building the Four-Wheeled Mobile Platform
    1. Hardware Required
    2. Mechanical Assembly
      1. Lay Out the Chassis Parts
      2. Motor Assembly
      3. Assemble the Chassis Components
      4. Solder the Power and Motor Connections
      5. Connecting the Battery Pack and Power Switch
      6. Building the Optional Trickle Charger
      7. Assemble the Chassis
      8. Mounting Arduino and Connecting Wires to the Shield
    3. Mounting the IR sensors
      1. Mounting the IR Sensors for Edge Detection
      2. Mounting the IR Sensors for Line Following
    4. Next Steps
  9. 5. Tutorial: Getting Started with Arduino
    1. Hardware Required
    2. Arduino Software
    3. Arduino Hardware
    4. Installing the Integrated Development Environment (IDE)
      1. Installing Arduino on Windows
      2. Installing Arduino on OS X
      3. Installing Arduino on Linux
      4. Driver Installation
    5. Connecting the Arduino Board
    6. Using the IDE
    7. Uploading and Running the Blink Sketch
    8. Using Tabs
    9. Installing Third-Party Libraries
  10. 6. Testing the Robot's Basic Functions
    1. Hardware Required
    2. Software Prerequisites
    3. Sketches Used in This Chapter
    4. Load and Run helloRobot.ino
    5. About the Sketch
    6. Troubleshooting
    7. Making the Sketch Easy to Enhance
  11. 7. Controlling Speed and Direction
    1. Hardware Required
    2. Sketches Used in This Chapter
    3. Types of Motors
    4. Motor Controllers
    5. Controlling Motor Speed
      1. How Motor Speed Is Controlled
      2. Code for Motor Control
      3. Calibrating Rotation and Tracking
    6. Software Architecture for Robot Mobility
    7. Functions to Encapsulate Robot Movements
      1. Core Movement Code
      2. Additional Core Functions
      3. Functions to Rotate the Robot
      4. Higher-Level Movement Functions
  12. 8. Tutorial: Introduction to Sensors
    1. Hardware Discussed
    2. Software
    3. Infrared Reflectance Sensors
    4. Sonar Distance Sensors
    5. Maxbotix EZ1 Sonar Distance Sensor
    6. Sharp IR Distance Sensor
    7. Proximity Sensor
    8. Sound Sensor
    9. Arduino Cookbook
  13. 9. Modifying the Robot to React to Edges and Lines
    1. Hardware Required
    2. Sketches Used in This Chapter
    3. The Look Code
    4. Edge Detection
    5. Line Following
    6. Seeing Sketch Data
  14. 10. Autonomous Movement
    1. Hardware Required
    2. Sketches Used in This Chapter
    3. Mounting a Ping Distance Sensor
      1. Making a Mount for the Ping Sensor
      2. Mounting the Ping Sensor in a Fixed Position
      3. Mounting the Ping Sensor on a Servo
    4. Letting the Robot Wander
    5. Adding Scanning
  15. 11. Remote Control
    1. Hardware Required
    2. Sketches Used in This Chapter
    3. Design of the Remote Control Code
    4. Controlling the Robot with a TV Type IR Remote
      1. Installing the IR Decoder Chip
      2. The IR Remote Software
  16. A. Enhancing Your Robot
    1. Planning
      1. Think Before You Code
      2. Avoid Feature Bloat
      3. Don't Reinvent the Wheel
      4. Structure to Reflect Functionality
      5. Use Clear Names for Functions and Variables
    2. Implementing a Complex Project
      1. Test Often
      2. Simplify
      3. If It Is Awkward, Start Over
      4. Don't Confuse Activity with Progress
      5. Experiment
      6. Be Tenacious
      7. Have Fun
  17. B. Using Other Hardware with Your Robot
    1. Alternative Motor Controllers
      1. Ardumoto
      2. Continuous Rotation Servos
  18. C. Debugging Your Robot
    1. Identify the Symptoms and Localize the problem
      1. Seeing What the Robot Is Doing
  19. D. Power Sources
    1. Monitoring Battery Voltage
    2. Trickle Charging
  20. E. Programming Constructs
    1. Digital I/O
    2. Analog I/O
    3. Math functions
    4. Other Functions and Constructs
  21. F. Arduino Pin and Timer Usage
    1. Handling Resource Conflicts
      1. Modifying a Library to Change Timer Allocation
      2. Writing Code That Avoids the Use of a Timer
    2. Pin and Timer Tables
  22. About the Author
  23. SPECIAL OFFER: Upgrade this ebook with O’Reilly
  24. Copyright
O'Reilly logo

Chapter 1. Introduction to Robot Building

This book takes you through the steps needed to build a robot capable of autonomous movement and remote control. Build instructions are provided for 2WD (two wheel drive) and 4WD (four wheel drive) platforms. The platforms shown in Figure 1-1 and Figure 1-2 will make the construction a snap, but you can build your own robot chassis if you prefer. The connection and use of the control electronics and sensors are fully explained and the source code is included in the book and available for download online (see How to Contact Us for more information on downloading the sample code).

The assembled two wheeled robot chassis

Figure 1-1. The assembled two wheeled robot chassis

The assembled four wheeled robot chassis

Figure 1-2. The assembled four wheeled robot chassis

Here is a preview of the projects you can build:

  • Controlling speed and direction by adding high level movement capability.

  • Enabling the robot to see the ground—using IR sensors for line and edge detection (see Figure 1-3 and Figure 1-4).

  • Enabling the robot to look around—scanning using a servo so the robot can choose the best direction to move, as shown in Figure 1-5.

  • Adding remote control using a TV remote control or a wired or wireless serial connection.

Robot moves around but remains within the white area

Figure 1-3. Robot moves around but remains within the white area

Robot follows black line

Figure 1-4. Robot follows black line

Two wheeled and four wheeled robots with distance scanners

Figure 1-5. Two wheeled and four wheeled robots with distance scanners

Why Build a Robot?

Building a robot is different from any other project you can make with a microcontroller.  A robot can move and respond to its environment and exhibit behaviors that mimic living creatures. Even though these behaviors may be simple, they convey a sense that your creation has a will and intent of its own. Building a machine that appears to have some spark of life has fascinated people throughout the ages. The robots built over 60 years ago by neurophysiologist W. Grey Walter (see http://www.extremenxt.com/walter.htm) explored ways that the rich connections between a small number of brain cells give rise to complex behaviors.

There are many different kinds of robots, some can crawl, or walk, or slither. The robots described in this book are the easiest and most popular; they use two or four wheels driven by motors.

How Robots Move

Tools

These are the tools you need to assemble the robot chassis.

Phillips Screwdriver

A small Phillips screwdriver from your local hardware store.

Small long-nose or needle-nose pliers

For example, Radio Shack 4.5-inch mini long-nose pliers, part number 64-062 (see Figure 1-10) or Xcelite 4-inch mini long-nose pliers, model L4G.

Small wire cutters

For example, Radio Shack 5" cutters, part number 64-064 (Figure 1-11) or Jameco 161411

Soldering iron

For example, Radio Shack 640-2070 (Figure 1-12) or Jameco 2094143 are low cost irons suitable for beginners. But if you are serious about electronics, a good temperature controlled iron is worth the investment, such as Radio Shack 55027897 or Jameco 146595.

Solder 22 AWG (.6mm) or thinner

For example, Radio Shack 640-0013 or Jameco 73605.

Soldering Iron

Figure 1-12. Soldering Iron

The best content for your career. Discover unlimited learning on demand for around $1/day.