Sie sind auf Seite 1von 49

DESIGN AND IMPLEMENTATION OF

ROBOT VEHICLE CONTROL WITH WIRELESS


JOYSTICK
B.Tech Project Report

T.Jashua danie
A.Mahender yadav
B.Raghuvardhan Reddy
G.Ravikiran

DEPARTMENT OF ELECTRONICS AND


COMMUNICATION ENGINEERING

GOKARAJU RANGARAJU INSTITUTE OF


ENGINEERING AND TECHNOLOGY
(Affiliated to Jawaharlal Nehru Technological University)

HYDERABAD 500 090


2013

DESIGN AND IMPLEMENTATION OF


ROBOT VEHICLE CONTROL WITH WIRELESS
JOYSTICK
Project Report Submitted in Partial Fulfillment of
the Requirements for the Degree of

Bachelor of Technology
in
Electronics and Communication Engineering
by

T.Jashua danie (Roll no.09241A0476)


A.Mahender yadav (Roll no.09241A0480)
B.Raghuvardhan Reddy (Roll no.09241A0491)
G.Ravikiran (Roll no. 09241A0496)

DEPARTMENT OF ELECTRONICS AND


COMMUNICATION ENGINEERING
GOKARAJU RANGARAJU INSTITUTE OF
ENGINEERING AND TECHNOLOGY
(Affiliated to Jawaharlal Nehru Technological University)

HYDERABAD 500 090


2013

Department of Electronics and Communication Engineering


Gokaraju Rangaraju Institute of Engineering and Technology
(Affiliated to Jawaharlal Nehru Technological University)

Hyderabad 500 090


2013

Certificate
This is to certify that this project report entitled Design and implementation of Robot
Vehicle control with Wireless Joystick by T.Jashua danie (Roll No. 09241A0476), A.Mahender
yadav (Roll No. 09241A0480) , B.Raghuvardhan Reddy(Roll No. 09241A0491)and G.Ravikiran
(Roll No.09241A0496), submitted in partial fulfillment of the requirements for the degree of
Bachelor of Technology in Electronics and Communication Engineering of the Jawaharlal Nehru
Technological University, Hyderabad, during the academic year 2012-2013, is a bonafide record
of work carried out under our guidance and supervision.
The results embodied in this report have not been submitted to any other University or
Institution for the award of any degree or diploma.

(Guide)
K. Jamal
Assistant Professor

(External Examiner)

(i)

(Head of Department)
Ravi Billa

ACKNOWLEDGMENT

[To Project Guides(s)] It is a pleasure to express thanks to Mr. K.Jamal for the
encouragement and guidance throughout the course of this project.

[To all others (if any), such as individuals and organizations who were instrumental in
the completion of our project]

T.Jashua danie

___________________________

A.Mahender yadav

___________________________

B.Raghuvardhan Reddy

____________________________

G.Ravikiran

_____________________________

(ii)

Abstract
This paper presents the design and implementation of Robot Vehicle Control
with Wireless Joystick . Wireless communications play an important role in
mobile robotics and are able to address real world applications. Radio signals
sent from distant computer or smartphone or joystick can be used to control the
movements of robot. The main idea of this project is to control the robot vehicle wirelessly with joystick .A microcontroller attached with the robot gets the
incoming message from the transmitter and controls the movement of the robot
accordingly.
The paper provides information on the two main components of the project
One component is a transmitter which sends signals from the joystick to the
receiver using zigbee interface. The second component is the receiver which
takes incoming messages from transmitter and sends to the microcontroller
using zigbee interface. Pieces of software had to be written for both receiver and
transmitter.

Keywords : Wireless, Robot, Joystick

CONTENTS
Abstract

List of Figures

ii

List of Tables

iii

1 Introduction
1.1 Background
1.2 Aim of this Project
1.3 Methodology
1.4 Significance of this work
1.5 Outline

1
1
1
2
2

2 Block diagram and Hardware


2.1 Block diagram
2.2 Hardware
2.3 Joystick shield
2.4 Motor Driver Shield
3 Arduino Uno and its Programming
3.1 Arduino Uno
3.2 Pin configuration 12
4. AtMega328
4.1 Features
4.2 Pin diagram
5 XBEE
5.1 Performance
5.2 Features
5.3 Networking and security
5.4 Power requirements
5.5 Serial Communications

4
5
5
8

10

15
17
20
20
21
21
21

5.6 Transparent Operation

22

6 Flow Chart
6.1 Transmitter flowchart
6.2 Receiver flowchart

23
24

7. Tools
7.1 X-CTU (configuring the XBees)
7.2 Arduino IDE

25
32

8. Arduino code
8.1 Arduino code for transmitter
8.2 Arduino code for receiver

37
41

Chapter 1
INTRODUCTION

1.1 Background
Technological advancement in the field of science has paved the way to the invention
of sophisticated machines, which could assist us and simplify our work. One such valuable
invention of humankind is robots. By flipping through the pages of history, it is studied that
people in the ancient Greece and Egypt started using the raw form of robots, for
accomplishing various kinds of works. With the passing time, robotics saw further
developments. The design of robots became more and more sophisticated, with the increase
in the capacity of the machines to do work. In The present time, Robots emerged as machines
that could follow along with a human by holding hands. Today, with the advancement of
science and technology, the researchers are coming up with innovative ideas to create robots
that could simplify the sophisticated tasks, which are otherwise done with intense hard work,
with work force. Robotics is a developing science.

1.2 Aim of this Project


The aim of the project is to control the robot vehicle wirelessly with joystick. In this
Project data is taken from the joystick and sends to receiver through wireless communication
and robot vehicle moves according to the data taken from joystick

1.3 Methodology
There are two sections in this project 1.Transmitter 2.Receiver
1.TRANSMITTER
In this section ,the transmitter consists of joystick ,microcontroller and xbee
module .The data is taken from Joystick ,The joystick gives the analog data and this data is
given to microcontroller and microcontroller process the data according to the software
written in it and sends the commands to the xbee module .Where xbee module transmits the
commands to the receiver
2. RECEIVER
In this section ,the receiver consists of xbee module ,microcontroller, and motor
driver .The xbee module takes the commands from the transmitter and sends to
microcontroller and microcontroller will process the commands according to the software
written in it and gives the signals to motor driver to drive the motors.

1.4 significance of this work

Used in military applications


Immune to interference from other radio sources
Multiple access
1

Secure

1.5 Outline of this Report

Chapter 1 deals with Introduction to the Project


Chapter 2 deals with Block diagram and hardware components
Chapter 3 deals with Arduino uno and its programming
Chapter 4 deals with AtMega 328 Features and Pin diagram
Chapter 5 deals with xbee module
Chapter 6 contains flowcharts
Chapter 7 deals with usage of X-ctu and Arduino IDE
Chapter 8 deals with Arduino code

1.6 Conclusion
The aim of the project and methodology used ,significance of the project ,Outline of the
Project can be known from this chapter

Chapter 2
BLOCK DIAGRAM AND HARDWARE
2.1 Block diagram

Transmitter

A(0)

JOYSTICK

A(1)

A
R
D
U
I
N
O
U
N
O

xbee
TX

Receiver

MOTOR
1

MOTOR
DRIVER

MOTOR
2

A
R
D
U
I
N
O
U
N
O

RX

xbee

2.2 Hardware
The main components used in this Project are

Joystick shield
Arduino uno
Motor Driver shield
Xbee module

2.3 Joystick Shield


The Joystick Shield is an Arduino add-on that has a 2 axis joystick and 5
buttons (one in the joystick). We can use it to control a lot of things that needs analog and
digital commands .Here is the Circuit

Working of Joystick:
The basic idea of a joystick is to translate the movement of a plastic
stick into electronic information a computer can process. In order to communicate a full
range of motion to the computer, a joystick needs to measure the stick's position on two
axes -- the X-axis (left to right) and the Y-axis (up and down). Just as in basic geometry, the
X-Y coordinates pinpoint the stick's position exactly

In the standard joystick design, the handle moves a narrow rod that sits in two
rotatable, slotted shafts. Tilting the stick forward and backward pivots the Y-axis shaft
from side to side. Tilting it left to right pivots the X-axis shaft. When you move the
stick diagonally, it pivots both shafts. Several springs center the stick when you let go
of it

To determine the location of the stick, the joystick control system simply monitors the position of
each shaft. The conventional analog joystick design does this with two potentiometers, or variable
resistors. The diagram below shows a typical arrangement

.
Each potentiometer consists of a resistor, in the form of a curved track, and a movable contact arm.
The computer power supply conducts electricity to the input terminal, through the curved resistor,
through the contact arm and back to the joystick port on the computer.
By moving the contact arm along the track, you can increase or decrease the resistance acting on the
current flowing through this circuit. If the contact arm is on the opposite end of the path from the
input connection terminal, electricity will have to flow through a long length of resistor, so it will face
maximum resistance. If the contact arm is near the input terminal, the potentiometer will have
minimal resistance.
Each potentiometer is connected to one of the joystick shafts so that pivoting the shaft rotates the
contact arm. In other words, if you push the stick all the way forward, it will turn the potentiometer
contact arm to one end of the track, and if you pull it back toward you, it will turn the contact arm
the other way.
Varying the resistance of the potentiometer alters the electrical current in the connected circuit. In
this way, the potentiometer translates the stick's physical position into an electrical signal, which it
passes on to the joystick port on the computer.
This electrical signal is totally analog -- it's a varying wave of information, like a radio signal. In order
to make the information usable, the computer needs to translate it into a digital signal -- a strict
numerical value.

2.4 Motor driver shield


The Motor driver shield used in this Project is Moto Mama. The Moto Mama
is a motor driver based on the L298N H-bridge driver chip

Features:

Light Weight, small dimension


Super driver capacity
FED protection
Heavy load heat sink
2 DC motor/4 coil dual phrase stepper motor output
Motor direction indication LED
Pulse protection
XBee/nRF24L01+ socket break out
UART/IIC/Ads socket break out
4 standard mounting holes

Specifications:
Power supply
Indicators
Communication Protocol

7-15v
PWR, Motor direction
Xbee,UART

MotoMama can drive two DC motors at the same time.


OUT1/OUT2 is completely symmetrical as OUT3/OUT4 on the board. These pins is connect
to the DC motors. The output voltage depends on VIN.
DC motor control input port A has three pins, In1, In2 and EnA. In1 and In2 are digital ports
which be used to control the direction of the motor, EnA is connecting with PWM port of
control board to control the speed of motor.

EnA
0

In1
X

In2
X

1
1
1

1
0

0
1
In2

EnB
0

In3
X

In4
X

1
1
1

1
0

0
1
In2

In1

In1

Description
Free running motor
stop
Forward
Reverse
Fast Motor Stop

Description
Free running motor
stop
Forward
Reverse
Fast Motor Stop

Port A is used to control the motor that connect with OUT1 and OUT2, Port B is used to
control the motor that connect with OUT3 and OUT4.
The EnA, EnB, ln1, ln2, ln3, ln4 can be used to drive the 4-wire stepping motor which
connects with OUT1, OUT2, OUT3 and OUT4.

Chapter 3
ARDUINO UNO AND ITS PROGRAMMING

Arduino is a tool for making computers that can sense and control more of the physical world
than your desktop computer. It's an open-source physical computing platform based on a
simple microcontroller board, and a development environment for writing software for the
board.
Arduino can be used to develop interactive objects, taking inputs from a variety of switches
or sensors, and controlling a variety of lights, motors, and other physical outputs. Arduino
projects can be stand-alone, or they can be communicate with software running on your
computer (e.g. Flash, Processing, MaxMSP.) The boards can be assembled by hand or
purchased preassembled; the open-source IDE can be downloaded for free.
The Arduino programming language is an implementation of Wiring, a similar physical
computing platform, which is based on the Processing multimedia programming environment

3.1 Arduino uno :

10

Overview
The Arduino Uno is a microcontroller board based on the ATmega328 . It has 14 digital
input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a
16 MHz ceramic resonator, a USB connection, a power jack, an ICSP header, and a reset
button. It contains everything needed to support the microcontroller; simply connect it to a
computer with a USB cable or power it with a AC-to-DC adapter or battery to get started.
The Uno differs from all preceding boards in that it does not use the FTDI USB-to-serial
driver chip. Instead, it features the Atmega16U2 (Atmega8U2 up to version R2) programmed
as a USB-to-serial converter.

Summary
Microcontroller

ATmega328

Operating Voltage

5V

Input Voltage (recommended) 7-12V


Input Voltage (limits)

6-20V

Digital I/O Pins

14 (of which 6 provide PWM output)

Analog Input Pins

DC Current per I/O Pin

40 mA

DC Current for 3.3V Pin

50 mA

Flash Memory

32 KB (ATmega328) of which 0.5 KB used by bootloader

SRAM

2 KB (ATmega328)

EEPROM

1 KB (ATmega328)

Clock Speed

16 MHz

11

3.2 Pin Configuration


Power
The Arduino Uno can be powered via the USB connection or with an external power supply.
The power source is selected automatically.
External (non-USB) power can come either from an AC-to-DC adapter (wall-wart) or battery.
The adapter can be connected by plugging a 2.1mm center-positive plug into the board's
power jack. Leads from a battery can be inserted in the Gnd and Vin pin headers of the
POWER connector.
The board can operate on an external supply of 6 to 20 volts. If supplied with less than 7V,
however, the 5V pin may supply less than five volts and the board may be unstable. If using
more than 12V, the voltage regulator may overheat and damage the board. The recommended
range is 7 to 12 volts.
The power pins are as follows:

VIN. The input voltage to the Arduino board when it's using an external power
source (as opposed to 5 volts from the USB connection or other regulated power
source). You can supply voltage through this pin, or, if supplying voltage via the
power jack, access it through this pin.

5V.This pin outputs a regulated 5V from the regulator on the board. The board can be
supplied with power either from the DC power jack (7 - 12V), the USB connector
(5V), or the VIN pin of the board (7-12V). Supplying voltage via the 5V or 3.3V pins
bypasses the regulator, and can damage your board.

3V3. A 3.3 volt supply generated by the on-board regulator. Maximum current draw
is 50 mA.

GND. Ground pins.

IOREF. This pin on the Arduino board provides the voltage reference with which
the microcontroller operates. A properly configured shield can read the IOREF pin
voltage and select the appropriate power source or enable voltage translators on the
outputs for working with the 5V or 3.3V.

Memory
The ATmega328 has 32 KB (with 0.5 KB used for the bootloader). It also has 2 KB of
SRAM and 1 KB of EEPROM .

12

Input and Output


Each of the 14 digital pins on the Uno can be used as an input or output,
using pinMode(), digitalWrite(), and digitalRead( ) functions. They operate at 5 volts. Each
pin can provide or receive a maximum of 40 mA and has an internal pull-up resistor
(disconnected by default) of 20-50 kOhms. In addition, some pins have specialized functions:

Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial
data. These pins are connected to the corresponding pins of the ATmega8U2 USB-toTTL Serial chip .

External Interrupts: 2 and 3. These pins can be configured to trigger an


interrupt on a low value, a rising or falling edge, or a change in value. See
the attachInterrupt() function for details.

PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with


the analogWrite() function.

SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI


communication using the SPI library.

LED: 13. There is a built-in LED connected to digital pin 13. When the pin is
HIGH value, the LED is on, when the pin is LOW, it's off.

The Uno has 6 analog inputs, labeled A0 through A5, each of which provide 10 bits of
resolution (i.e. 1024 different values). By default they measure from ground to 5 volts,
though is it possible to change the upper end of their range using the AREF pin and
the analog Reference() function. Additionally, some pins have specialized functionality:

TWI: A4 or SDA pin and A5 or SCL pin. Support TWI communication


using the Wire library.

There are a couple of other pins on the board:

AREF. Reference voltage for the analog inputs. Used with analogReference().

Reset. Bring this line LOW to reset the microcontroller. Typically used to add a
reset button to shields which block the one on the board.

13

Communication
The Arduino Uno has a number of facilities for communicating with a computer, another
Arduino, or other microcontrollers. The ATmega328 provides UART TTL (5V) serial
communication, which is available on digital pins 0 (RX) and 1 (TX). An ATmega16U2 on
the board channels this serial communication over USB and appears as a virtual com port to
software on the computer. The '16U2 firmware uses the standard USB COM drivers, and no
external driver is needed. However, on Windows, a .inf file is required. The Arduino software
includes a serial monitor which allows simple textual data to be sent to and from the Arduino
board. The RX and TX LEDs on the board will flash when data is being transmitted via the
USB-to-serial chip and USB connection to the computer (but not for serial communication on
pins 0 and 1).
A SoftwareSerial library allows for serial communication on any of the Uno's digital pins.
The ATmega328 also supports I2C (TWI) and SPI communication. The Arduino software
includes a Wire library to simplify use of the I2C bus; see the documentation for details. For
SPI communication, use the SPI library.

Programming
The Arduino Uno can be programmed with the Arduino software . Select
"Arduino Uno from the Tools > Board menu (according to the microcontroller
on your board)..
The ATmega328 on the Arduino Uno comes preburned with a bootloader that
allows you to upload new code to it without the use of an external hardware
programmer. It communicates using the original STK500 protocol ( C header
files)

14

Chapter 4
AT MEGA 328
4.1

Features

High Performance, Low Power AVR 8-Bit Microcontroller


Advanced RISC Architecture
131 Powerful Instructions Most Single Clock Cycle Execution
32 x 8 General Purpose Working Registers
Fully Static Operation
Up to 20 MIPS Throughput at 20 MHz
On-chip 2-cycle Multiplier
High Endurance Non-volatile Memory Segments
4/8/16/32K Bytes of In-System Self-Programmable Flash progam memory
256/512/512/1K Bytes EEPROM (ATmega48P/88P/168P/328P)
512/1K/1K/2K Bytes Internal SRAM (ATmega48P/88P/168P/328P)
Write/Erase Cycles: 10,000 Flash/100,000 EEPROM
Data retention: 20 years at 85C/100 years at 25C(1)
Optional Boot Code Section with Independent Lock Bits
Programming Lock for Software Security
Peripheral Features
Two 8-bit Timer/Counters with Separate Prescaler and Compare Mode
One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and
Real Time Counter with Separate Oscillator
Six PWM Channels
8-channel 10-bit ADC in TQFP and QFN/MLF package
6-channel 10-bit ADC in PDIP Package
Programmable Serial USART
Master/Slave SPI Serial Interface
Byte-oriented 2-wire Serial Interface (Philips I2C compatible)
Programmable Watchdog Timer with Separate On-chip Oscillator
On-chip Analog Comparator
Interrupt and Wake-up on Pin Change

15

CaptureMode

Special Microcontroller Features:


Power-on Reset and Programmable Brown-out Detection
Internal Calibrated Oscillator
External and Internal Interrupt Sources
Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, Standby, and
Extended Standby
I/O and Packages:
23 Programmable I/O Lines
28-pin PDIP, 32-lead TQFP, 28-pad QFN/MLF and 32-pad QFN/MLF
Operating Voltage:
1.8 - 5.5V for ATmega48P/88P/168PV
2.7 - 5.5V for ATmega48P/88P/168P
1.8 - 5.5V for ATmega328P
Temperature Range:
-40C to 85C
Speed Grade:
ATmega48P/88P/168PV: 0 - 4 MHz @ 1.8 - 5.5V, 0 - 10 MHz @ 2.7 - 5.5V
ATmega48P/88P/168P: 0 - 10 MHz @ 2.7 - 5.5V, 0 - 20 MHz @ 4.5 - 5.5V
ATmega328P: 0 - 4 MHz @ 1.8 - 5.5V, 0 - 10 MHz @ 2.7 - 5.5V, 0 - 20 MHz @ 4.5 5.5V
Low Power Consumption at 1 MHz, 1.8V, 25C for ATmega48P/88P/168P:
Active Mode: 0.3 mA
Power-down Mode: 0.1 A
Power-save Mode: 0.8 A (Including 32 kHz RTC)

16

4.2

Pin diagram:

4.3

Pin Descriptions

VCC
Digital supply voltage.
GND
Ground.
Port B (PB7:0) XTAL1/XTAL2/TOSC1/TOSC2
Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for
each bit). The Port B output buffers have symmetrical drive characteristics with both high
sink and source capability. As inputs, Port B pins that are externally pulled low will source
current if the pull-up resistors are activated. The Port B pins are tri-stated when a reset
condition becomes active, even if the clock is not running.Depending on the clock selection
17

fuse settings, PB6 can be used as input to the inverting Oscillator amplifier and input
to the internal clock operating circuit.Depending on the clock selection fuse settings, PB7 can
be used as output from the invertingOscillator amplifier.
If the Internal Calibrated RC Oscillator is used as chip clock source, PB7..6 is used as
TOSC2..1 input for the Asynchronous Timer/Counter2 if the AS2 bit in ASSR is set. The
various special features of Port B are elaborated in Alternate
Port C (PC5:0)
Port C is a 7-bit bi-directional I/O port with internal pull-up resistors (selected for each bit).
The PC5..0 output buffers have symmetrical drive characteristics with both high sink and
source capability. As inputs, Port C pins that are externally pulled low will source current if
the pull-up resistors are activated. The Port C pins are tri-stated when a reset condition
becomes active, even if the clock is not running.
PC6/RESET
If the RSTDISBL Fuse is programmed, PC6 is used as an I/O pin. Note that the
electrical characteristics of PC6 differ from those of the other pins of Port C.
If the RSTDISBL Fuse is unprogrammed, PC6 is used as a Reset input. A low level
on this pin for longer than the minimum pulse length will generate a Reset, even if the clock
is not running.
Shorter pulses are not guaranteed to generate a Reset. The various special features of Port C
are elaborated in Alternate Functions of
Port D (PD7:0)
Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for
each bit). The Port D output buffers have symmetrical drive characteristics with both high
sink and source capability. As inputs, Port D pins that are externally pulled low will source
current if the pull-up
resistors are activated. The Port D pins are tri-stated when a reset condition becomes active,
even if the clock is not running.
AVCC
AVCC is the supply voltage pin for the A/D Converter, PC3:0, and ADC7:6. It should
be externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be
connected to VCC through a low-pass filter. Note that PC6..4 use digital supply voltage,
VCC.

18

AREF
AREF is the analog reference pin for the A/D Converter.
ADC7:6 (TQFP and QFN/MLF Package Only)
In the TQFP and QFN/MLF package, ADC7:6 serve as analog inputs to the A/D
converter. These pins are powered from the analog supply and serve as 10-bit ADC channels.

4.4

Internal block diagram

19

Chapter 5
XBEE MODULE
For applications where robust mesh networking topologies are preferred, XBee
ZigBee/mesh OEM RF modules provide developers with both ZigBee mesh and the soon-tobe-released proprietary DigiMesh topologies. These networks allow devices to harness the
entire network of RF modules to effectively extend range beyond that of a single module, and
create a more stable and reliable network. Employing dynamic self-healing, self-discovery
functionality for reliable communications, XBee ZigBee/mesh OEM RF modules make mesh
networking simple and easy to deploy.

5.1 Performance

RF Data Rate
Indoor/Urban Range
Outdoor/RF Line-of-Sight Range

Transmit Power
Receiver Sensitivity

250kbps
133ft(40m)
400ft (120m)
1.25mW
-97dBm

5.2 Features

Serial Data Interface


Configuration Method
Frequency Band
Interference Immunity
Serial Data Rate
ADC Inputs
Digital I/O
Antenna

3.3v CMOS UART


API or AT Commands, local or over-the-air
2.4GHz
DSSS(Direct Sequence Spread Spectrum)
1200bps -1Mbps
4 10 bit ADC inputs
10
chip
20

5.3 Networking & Security


Encryption
Reliable Packet Delivery
IDs and Channels

128-bit AES
Retries/Acknowledgements
PAN ID,64-bit IEEE MAC,16 Channels

5.4 Power Requirements

Supply Voltage

2.1 -3.6VDC

Transmit Current

35mA/45mA

Receiver Current

38mA/40mA

Power- Down Current

<1 uA @ 25 C

5.5 Serial Communications


The XBee Modules interface to a host device through a logiclevel asynchronousserial port. T
hrough its serial port, the module can communicate with any logic and voltage compatible U
ART; or through a level translator to any serial device.

Serial data
Data enters the module UART through the DI pin (pin 3) as an asynchronous serial signal.
The signal should idle high when no data is being transmitted. Each data byte consists of a
start bit (low), 8 data bits (least significant bit first) and a stop bit(high).

Serial communications depend on the two UARTs (the microcontroller's and the RF
module's) to be configured with compatible settings (baud rate, parity, start bits, stop bits,
data bits).

21

5.6 Transparent Operation


1Serial-to-RF Packetization

Data is buffered in the DI buffer until one of the following causes the data to be
packetized and transmitted:

No serial characters are received for the amount of time determined by the RO
(Packetization Timeout) parameter. If RO = 0, packetization begins when a character
is received.

2. The maximum number of characters that will fit in an RF packet (100) is received.

3. The Command Mode Sequence (GT + CC + GT) is received. Any character


buffered in the DI buffer before the sequence is transmitted.

22

Chapter 6
FLOWCHART
6.1 Transmitter
START

Initialize Pins
8,9,10,11,12,13 as
Output Pins

SERIAL.BEGIN

Is
Serial data
available?

Case
f

Assign Pins
8,10,11,12 (HIGH)
13,9 (LOW)

F
F

Assign Pins
9,10,11,13 (HIGH)
8,12 (LOW)

Case
b
F

Case
r

Assign pins
11,12(HIGH)
10,13(LOW)

F
T

Case
l

Assign Pins
8,10(HIGH)
9,11(LOW)

F
T
Assign Pins
10,11 (LOW)

Case
s

STOP

6.2 Receiver
START

SERIAL.BEGIN

Read data from


AnalogRead(0)
Analog Read(1) Pin

Is data
received
from analog
Read(0) pin

Data
from A(0)
pin > 517

Send f

Is data
received
from analog
Read(0) pin

Data
from A(0)
pin > 517

Send b

Send s

Data
from A(0)
pin > 517

Send r

F
STOP

Data
from A(0)
pin > 517

Send l

Send s

Chapter 7
TOOLS
The tools used in this project x-ctu software for configuring xbee and Arduino software for
writing code for arduino uno r3
Following steps are involved in configuring xbee
1.Open the X-CTU configuration tool and select the COM as shown below

25

2.You can test you can connect to your XBEE by pressing the TEST/Query button and it let
you know its current firmware as shown below

3. If X-CTU cannot find your XBee, you will see this pop-up as shown below

26

4. Now we are ready to program our XBee. The first XBee is going to be our Coordinator
module, basically the boss of the private area network (PAN) we are going to create. To
program an XBee we need to upload new firmware to it. To do this, navigate to the Modem
Configuration tab in X-CTU and choose the following configuration. Click Write and XCTU will attempt to program you XBee, this should take 30 seconds or so, you may be asked
to press the RESET button on your USB Dongle as shown in below figure

27

5. When your XBee has been successfully programmed, press the Read button to retrieve the
configuration of the device. All the details about the configuration will be downloaded and
shown as below:

28

6. We are going to use all this information as there are many ways of setting up complex
XBee configurations to suit specific applications. We are only going to set up a simple pointto-point network. This XBee will be the Coordinator node, and so all the 'end points' (Router
nodes) will need to know the address of this node to communicate. Very simply, this means
we want to get the Serial Number of this device to program into our Router.
Write down the SH - Source Address High and SL - Source Address Low for us to use in
the next step. The Coordinator node is now complete! Take this XBee (you may want to mark
this XBee so you know it is the Coordinator) out of your XBee USB Dongle (carefully, make
sure not to bend any of the pins on the module) and insert the next XBee we are going to
program.
Follow the same procedure as last time, make sure you can connect to the XBee and then go
to the Modem Configuration tab. This time instead of programming the node as a
Coordinator, we are going to program it as a Router. Select the same configuration as below
and press Write, this will take another 30 seconds.

29

7. Once this XBee is programmed, press Read to get the configuration. To tell this XBee
which Coordinator to connect to, we need to give it the address. We do that by setting the DH
- Destination Address High and DL - Destination Address Low with the serial number we
took from the Coordinator. Put this information in and then press Write to write this new
configuration to the XBee.

30

8. Testing the connection


To test the XBee network we have created , write a simple Arduino sketch that is going to
transmit some information from our router (end device) to our Coordinator .Swap the XBees
over so that our Coordinator is in the XBee USB Dongle, and the Router is in the XBee
Developer. Open up X-CTU on our computer and this time go to Terminal tab.This tab will
show you what your XBee Is currently listening too.

Sample arduino sketch


void setup()
{
Serial.begin(9600);
}
Void loop()
{
Serial.Println(Hello XBee Network!);
delay(200);
}
After uploading the above code open up the Serial Port in the Arduino IDE.Which is shown
below

31

7.2 Arduino IDE is used to write the program and dump into the Arduino board
Following are the steps involved :
1. Open Arduino IDE as shown below

32

2. Select the COM Port from tools

33

3.Select the required Arduino board from Tools as shown below

34

4.Write the sketch in Arduino IDE

35

5.compile and upload the Sketch to arduino board

36

Chapter 8
ARDUINO CODE

8.1 Arduino code for Transmitter

/* the analog Read pin reads value from 0 to 1023 we will take a threshold value and based
on that we will assume the joystick moved left or right The assumed threshold value are
for x axis low thershold value =505;
high threshold value =515;
for y axis low thershold value =500;
high threshold value =510;
*/

int x_position;
int y_position;
int x_direction;
int y_direction;
void setup()
{
Serial.begin(9600);
}
void loop()
{
x_direction =0;
y_direction =0;
37

x_position =analogRead(0); // analog 0 pin gives the x direction

y_position =analogRead(1); // analog 1 pin gives the y direction


if(x_position >515) // High threshold value
{
x_direction =1; // if the x_positioin is greater than threshold value then it moved along
positive x axis
}
else if (x_position <505) // low thershold value
{
x_direction =-1; //if the x_postion is less than low threshold valve then it moved along
negative x axis
}
if(y_position> 510) // similar to x axis
{
y_direction =1;
}
else if (y_position < 500)
{
y_direction =-1;
}
if(x_direction ==-1)
{
if(y_direction == 0)
{

Serial.write ("l");
}

38

}
if(x_direction ==1)
{
if(y_direction ==0)
{

Serial.write("r");
}
}
if(y_direction ==1)
{
if(x_direction ==0)
{

Serial.write("f");
}
}
if(y_direction == -1)
{
if(x_direction ==0)
{

Serial.write("b");
}
}
if(x_direction ==0)
{

39

if(y_direction==0)
{

Serial.write("s");
}
}
}

40

8.2 Arduino code for receiver

void setup()
{
Serial.begin(9600); // initialize serial communication:
pinMode(10,OUTPUT); // initialize for motor A
pinMode(11,OUTPUT); // initialize for motor B
pinMode(8,OUTPUT); // IN1
pinMode(9,OUTPUT); // IN2
pinMode(12,OUTPUT); // IN3
pinMode(13,OUTPUT); // IN4
}
void loop()
{
if(Serial.available()>0)
{
int data =Serial.read();
switch(data)
{
case 'f' :analogWrite(11,255); //enable for channel B
digitalWrite(12,HIGH); //in3
digitalWrite(13,LOW); //in 4 forward (12-13)
digitalWrite(8,HIGH); // in 1
digitalWrite(9,LOW); // in 2 forward (8,9)
analogWrite(10,255); // enable for channel A
break;
41

case 'b' :analogWrite(11,255); //enable for channel B


digitalWrite(12,LOW); //in3
digitalWrite(13,HIGH); //in 4 backward (12-13)
digitalWrite(8,LOW); // in 1
digitalWrite(9,HIGH); // in 2 backward (8,9)
analogWrite(10,255); // enable for channel A
break;
case 'l' :analogWrite(11,0); //disable for channel B
digitalWrite(8,HIGH); // in 1
digitalWrite(9,LOW); // in 2 forward (8,9)
analogWrite(10,255); // enable for channel A
break;
case 'r' :analogWrite(11,255); //enable for channel B
digitalWrite(12,HIGH); //in3
digitalWrite(13,LOW); //in 4 forward (12-13)
analogWrite(10,0); // disable for channel A
break;

case 's' : analogWrite(11,0); //diable channel B


analogWrite(10,0); // disable channel A
}
}
}

42

References
1. Arduino Cookbook, 2nd Edition by Michael Margolis.
2.Building Wireless sensor networks by Robert Faludi.

Das könnte Ihnen auch gefallen