Android Peripherals - Professional · 6 Arduino + Android Projects for the Evil Genius correct...

8
Android Peripherals PART ONE

Transcript of Android Peripherals - Professional · 6 Arduino + Android Projects for the Evil Genius correct...

Page 1: Android Peripherals - Professional · 6 Arduino + Android Projects for the Evil Genius correct length. You will need to break off two lengths of six pins and two lengths of eight

Android Peripherals

P A R T O N E

01_Ch01_Monk 596-X 10/25/11 9:18 AM Page 1

Page 2: Android Peripherals - Professional · 6 Arduino + Android Projects for the Evil Genius correct length. You will need to break off two lengths of six pins and two lengths of eight

Bluetooth Robot

C H A P T E R 1

THE EVIL GENIUS and his Android phone areinseparable. You will find him using it for groceryshopping, redirecting military satellites, andmessaging his minions. The Evil Genius also lovesto direct small robots by remote control usingBluetooth.

This project employs a simple Android app(Figure 1-1) and an Arduino-controlled robot usinga low-cost Bluetooth module (Figure 1-2).

Arduino boards are very popularmicrocontroller boards that have a number ofadvantages, not the least of which are:

� They are easy to program, and can beprogrammed from a Mac, Windows, or Linuxcomputer.

� Many “shields” just plug into the top of theArduino board.

� They are not expensive.

Construction

Figure 1-3 shows the schematic diagram for theproject.

The robot’s drive motors are controlled by amotor shield kit, and the Bluetooth module isattached to the prototyping area of the shield,making this a simple project to construct, with aminimal amount of soldering required.

A remote-control appFigure 1-1

A Bluetooth robotFigure 1-2

3

01_Ch01_Monk 596-X 10/25/11 9:18 AM Page 3

Page 3: Android Peripherals - Professional · 6 Arduino + Android Projects for the Evil Genius correct length. You will need to break off two lengths of six pins and two lengths of eight

All the software for the project can bedownloaded from www.duinodroid.com.

What You Will Need

In addition to a Bluetooth-equipped Android phone(Android 2.1 or later), you will need thecomponents found in the following Parts Bin tomake the project.

This design uses the Arduino Uno. The officialArduino web site (www.arduino.cc) lists suppliersof the Uno. However, if you are on a budget, youcan use a clone of the Arduino Uno. The Arduinois “open-source hardware,” which means all thedesign files are available under a Creative

Commons license that permits third parties tomake their own Arduinos. Many do, and anInternet search will find you cheap alternatives tothe official “Uno.”

There are many different types of Bluetoothmodules on the market. The module that the authorused is a simple “stick of gum”–shaped Bluetoothmodule with just four pins coming out of it thatsupply power and provide, receive, and transmitconnections. These types of modules work at 5Vand are ideally suited for use with an Arduino.They are usually made up of a base board withfour pins on which an even smaller board ismounted that is the actual Bluetooth module.These can be bought on eBay for around USD 15.

4 Arduino + Android Projects for the Evil Genius

Arduino Uno

Android Phone

Motor Shield

Motor Motor

6V Battery

+ 6V

GND

Bluetooth Module

Bluetooth

Vcc

Rx

Tx

GND

Rx

Tx

5V

+ +

1 2 3 4

Left Right

The schematic diagramFigure 1-3

01_Ch01_Monk 596-X 10/25/11 9:18 AM Page 4

Page 4: Android Peripherals - Professional · 6 Arduino + Android Projects for the Evil Genius correct length. You will need to break off two lengths of six pins and two lengths of eight

It is best to buy one with the miniboard alreadysoldered to the main board, because theconnections are very tiny and quite hard to solder.Higher-quality and more expensive versions areavailable in the Bluesmirf range from suppliers likeSparkfun. The main difference between the low-cost and more expensive modules is range.

The gear motors from Pololu are ideal for thiskind of application. They have about the right gearratio and are not expensive. Alternatives areavailable, but try not to buy gear motors that drawmore than about 1 amp, otherwise the motor shieldwill struggle to provide the necessary current.

The motor shield greatly simplifies the wholeprocess of driving motors, and what’s more, it hasa handy little prototyping area at one end whereyou can attach your own extra components. In thiscase, that is where our Bluetooth module will sit.In the parts list, I specified the basic shield kit,which comes without header strips and screwterminals. This shield is also available as a “retail”

kit that includes the pin header and screwterminals. See Sparkfun’s web site for details.

In addition to these components, you will alsoneed the following tools.

Step 1. Attach Pin Headers to the Shield

The first step is to attach the pin headers to themotor shield. Figure 1-4 shows the bottom of theshield with the pin headers attached. Your headerstrips will probably come in a single long lengththat is designed to be snapped into sections of the

Chapter 1 � Bluetooth Robot 5

Part Quantity Description Source

Arduino Uno 1 Arduino Uno board www.arduino.cc

Ardumoto 1 Ardumoto Motor Shield Sparkfun: DEV-09815

BT Module 1 TTL Bluetooth module: eBay, SparkfunBluesmirf or the equivalent

Pin headers 1 Pin header strip, broken into two sections Farnell: 1097954of six pins, and two sections of eight pins

Screw terminals 3 2-way screw terminal, 3.5mm pitch Farnell: 1217302

Gear motors 2 120:1 mini plastic gear motor Pololu: 1125

Switch 1 SPST miniature toggle switch Farnell: 1661841

Battery holder 1 AAA battery holder, solder tags (4x) Farnell: 1650687

Case 1 Plastic case, 145 � 80 � 30mm

Wheels 2 Approximately 2-inch- (50mm-) diameter Model/toy shopmodel car wheels

Caster 1 Small caster Hardware store

P A R T S B I N

� An electric drill and assorted drill bits

� A hacksaw or Dremel rotary tool

� A hot glue gun or epoxy glue

� A computer to program the Arduino

� A USB-type A-to-B lead

T O O L B O X

01_Ch01_Monk 596-X 10/25/11 9:18 AM Page 5

Page 5: Android Peripherals - Professional · 6 Arduino + Android Projects for the Evil Genius correct length. You will need to break off two lengths of six pins and two lengths of eight

6 Arduino + Android Projects for the Evil Genius

correct length. You will need to break off twolengths of six pins and two lengths of eight pins.

The easiest way to keep the pins straight is toplug the long ends of the headers into your Arduinoboard while you solder them to the shield. However,this will heat up the plastic of the socket underneathand may distort it. So either solder quickly, or justsolder the pins at each end of a section so the headeris held in the right place, and then remove the shieldand solder the rest of the pins.

When all the pins are in place, the top of theshield should look like Figure 1-5.

Step 2. Attach Screw Terminals to the Shield

The screw terminals fit next to the A and Bchannels for the motors. We will also attach ascrew terminal to the power socket, as it is easierto connect to than the main 2.1mm power socketon the Arduino.

Solder the four screw terminals into place, withthe opening facing toward the outside of the shield.Figure 1-6 shows the shield with the screwterminals attached and the shield plugged into anArduino.

Step 3. Install the Bluetooth Module

Figure 1-7 shows the Bluetooth module solderedinto place and the wiring attached.

Before attaching the Bluetooth module, carefullybend the pins with pliers so the board lies flatagainst the shield. Solder the module itself intoplace first, and then attach the four wires as listed next:

� +5V on the Bluetooth module to +5V on theshield

� GND on the Bluetooth module to GND on theshield

The motor shield with pin headersattached

Figure 1-4 The top side of the motor shieldFigure 1-5

The shield with screw terminalsattached

Figure 1-6

01_Ch01_Monk 596-X 10/25/11 9:18 AM Page 6

Page 6: Android Peripherals - Professional · 6 Arduino + Android Projects for the Evil Genius correct length. You will need to break off two lengths of six pins and two lengths of eight

� TXD on the Bluetooth module to RX on theshield

� RXD on the Bluetooth module to TX on theshield

Note the cross-over between transmit andreceive between the Arduino and the Bluetoothmodule.

That’s it for the electronics. We now turn toconstructing the hardware for the robot.

Step 4. Fix the Motors and Battery Box to the Case

Figure 1-8 shows the position of the motors. Theplastic housing of the gear motors is glued to theinside of the box.

Chapter 1 � Bluetooth Robot 7

The motors and battery box glued to the inside of the boxFigure 1-8

The completed shieldFigure 1-7

01_Ch01_Monk 596-X 10/25/11 9:18 AM Page 7

Page 7: Android Peripherals - Professional · 6 Arduino + Android Projects for the Evil Genius correct length. You will need to break off two lengths of six pins and two lengths of eight

The motors and battery box are fixed to thebottom of the case, at either end, leaving room forthe Arduino and shield in the middle.

Step 5. Cut the Case Bottom and Fix the Castor

Figure 1-9 shows how the case bottom is cut toallow the top of the gear motors and their driveshafts to protrude from the bottom of the case.

It is also a good idea to make a hole close to theBluetooth module so you can see if the LED on themodule is flashing or solid. The box used by theauthor was reused from a previous project and hadvarious holes in it. This is not a bad thing as itallows ventilation.

The castor is merely the smallest castor theauthor could find at the local hardware store. This is just glued to the bottom part of the case.

Step 6. Final Wiring

The wiring is made easy by the screw terminals.Figure 1-10 shows the wiring diagram, whileFigure 1-11 displays a photo of the inside of the robot.

The wiring steps are:

1. Solder leads from each of the tabs on the gearmotors. The leads should be long enough tocomfortably reach the screw terminals on themotor shield.

2. Solder a lead directly from the negative powerterminal on the shield to the negative of thebattery holder.

3. Solder a longer lead to the center connectionon the switch to the positive battery terminal.

4. Solder a shorter lead to one side of the switch(it does not matter which) and fit the otherend into the positive screw terminal.

8 Arduino + Android Projects for the Evil Genius

The case bottomFigure 1-9

01_Ch01_Monk 596-X 10/25/11 9:18 AM Page 8

Page 8: Android Peripherals - Professional · 6 Arduino + Android Projects for the Evil Genius correct length. You will need to break off two lengths of six pins and two lengths of eight

Chapter 1 � Bluetooth Robot 9

The wiring diagramFigure 1-10

Inside the robotFigure 1-11

01_Ch01_Monk 596-X 10/25/11 9:18 AM Page 9