Contents - inexglobal
Contents
Part list___________________________________________________2
Preparartion __________________________________4
iZEBOT
Activity #1 : Building iZEBOT__________________________________9
Activity #2 : iZEBOT motor driveing_________________________11
Activity #3 : iZEBOT Moving_________________________________13
iZEBOT Collision detection via Switch
Activity #4 : Installing the iZEBOT switch_____________________16
Activity #5 : Writing a program to read the Switch__________18
Activity #6 : iZEBOT versus the wall__________________________19
iZEBOT Serial Communication
Activity #7 : Serial Data Transmission________________________22
iZEBOT Remote Control
Activity #8 : Installing the Infrared Receiver module Sensor____ 27
Activity #9 : Using the ER-4 remote control___________________29
Activity #10 : Controlling movement through remote control___31
iZEBOT Distance Measurement using Infrared
Activity #11 : Installing GP2D120 onto the iZEBOT ____________33
Activity #12 : Reading the Analog signal____________________35
Activity #13 : Communicating with GP2D120________________37
Activity #14 : Detecting obstacles with no Contact___________42
iZEBOT Precision Movement with Encoder
Activity #15 : Installing IR Reflector to detect the wheel code__44
Activity #16 : : Testing Reflection and Non-reflection________46
Activity #17 : iZEBOT with Movement along defined distance_47
1
iZEBOT Partlist
+
Stamp-BOX : i-Stamp microcontroller
Robotic Controller board
This consists of the i-Stamp Basic Stamp microcontroller board 2SX; RBX-Stamp24 board;
and a CX-4 cable to download programs. It
has a 16KB memory (divided into 8 parts,
each of 2 KB), 8 analog input channels, 7
digital input/output channels, and it drives
two DC motors and three RC servo motors.
Box holder
Used to support the Stamp-Box when
attaching it to the robot.
iZEBOT body plate
This is a circle plastic plate with a diameter
of 15 cm. and thickness of 3 mm. A size 1
inch plastic ball is connected to the front
and back as supporting wheels.
Motor Gearbox
Uses a 6-9 V and 180 mA DC motor with a
ratio of 48:1; torque 4kgF/cm; come with
two mountings.
Wheel & tire set
This consists of two circle wheels with
diameter of 6.5 cm. Each wheel has 8 ovalshaped holes to use as wheel codes. It also
comes with two rubber bands to cover the
wheels. This helps with surface retraction
while the robot moves.
2
Angled Joiner
20 pieces of varied color joiners made from PVC plastic.
They can be connected together or by using screws
and 3 mm nuts in installation.
Obtuse Joiner
20 pieces of varied color 135 degree obtuse joiners
made from PVC plastic. They can be connected
together or by using screws and 3 mm nuts in installation.
Strength Joiner
20 pieces of varied color joiners made from PVC plastic.
They can be connected together or by using screws
and 3 mm nuts in installation.
Nut, Screws & Spacer
2mm. Screws
There are two of 2 mm screws, four of 3 x 6 mm. machine
3mm. Nut
3mm.
screws, thirty of 3x10 mm. machine screws, four of 3 x
Machine
25 mm. machine screws, two of 3 x 12 flat-head screws,
screw
Metal & Plastic spacers
thirty of 3 mm. nuts, four of 25 mm. metal spacers, and
four of 3 mm., 10 mm., 15 mm., and 25 mm. size plastic
spacers each.
Switch input
IR Refelctor
GP2D120 IR Ranger
The switch input is used to
detect collision at logic “0”.
Two sets along with the
connecting
cable
are
provided.
Used to detect the perimeter,
lines, and the wheel code. The
results are in voltage. Three sets
along with the connecting
cable are provided.
Measures distance
ranging from 4 to 30 cm
using infrared light. The
results are in voltage.
4-ch. IR Remote control
38kHz Infrared receiver module
Uses Infrared light to transmit the serial data of
the 4 switches.
This module is used to detect infrared
signals carried by the 38kHz carrier
frequency.
3
Preparation
Tools and Nescessary parts
1. Computer using Windows 98SE or above as the
operating system. It must also have at least 1
available serial port.
2. USB port to serial port converter (used if computer
doesn’t have serial port) UCON-232 is recommended.
UCON-232
Screwdriver
3. Philips Screwdriver
4. Four 1.2V and 1700mA batteries or four Alkaline AA
1.5V batteries
5. Battery recharger for four AA batteries (Case using
Rechargeable batteries)
6. Pliers
Basic Stamp Editor 2.0 Software
The Robo-Stamp2.0 set uses Basic Stamp 2SX (i-Stamp
Board) to control how it works. Basic Stamp 2SX uses
the program language PBasic through the Basic
Stamp Editor. This program is used to communicate
between the computer and Basic Stamp though the
serial port. It is also used as a program editor to write
and edit the Basic programming. The software
suggested is the Basic Stamp Editor V2.0 (the version
may change) which supports PBasic up to Version
2.5, an already high capability version.
The installation and how to use
the Basic Stamp Editor V2
software, as well as the Basic
Stamp 2SX commands can be read
from BASIC Stamp Editor manual;
free download from www.
parallax.com.
4
Batteries
Plier
Battery Charger
Stamp-BOX Anatomy
Battery Terminal
RS-232 Serial port
Modular Jack
Piezo Speaker
Motor indicator
Direct motor A output
POWER switch
Invert motor A output
Direct motor B output
Analog input
(ANALOG0 to
ANALOG7)
connect with any
analog sensor boards.
Accept 0+5V input
pass through 10-bit
Analog to Digital
Converter circuit to
convert digital data 0
to 1024
Invert motor B output
7 of Digital
input/output
ports : P0 to
P6
i-Stamp
BASIC Stamp2SX microcontroller
board
3 of RC Servo motor
output P7, P8 and P9
RESET
switch
GND
SIGNAL
+V
GND
+5V
SIGNAL
GND
SERVO
+5V
Features
l
Use I-Stamp as the main controller
l
Two DC motor drivers including status indicators to show motor direction
l
l
16 kB memory
8-ch. Analog connector with a 10-bit A/D converter that can accept up to +5V.
l
7-ch. Digital input/output port connector
l
RS-232 Serial port
l
Size of 6.5 x 6.75 x 6.0 cm
l
Uses PBasic 2.5 programming
l
Capability to write-erase 100,000 times
l
Piezo Speaker
l
3 of RC servo motor connectors
l
Uses 4 AA batteries
5
Testing the Stamp-BOX
1. Place the 4 batteries into the Stamp-BOX. Connect the Stamp-BOX to
the serial port (or COM port) of the computer with the CX-4 cable. Turn
on the power switch.
CX-4 cable
Computer has not Serial port
USB port
RS-232 serial port
(COM port)
CX-4 cable
UCON-232
2. Open the Basic Stamp Editor program. Test its connection to the
Stamp-BOX by going to the menu RUN. Choose Identity or press Ctrl+I.
The program should open the Identities display window and show which
serial port that Stamp-BOX is connected to.
Report founding BASIC Stamp2SX at COM1. It means StampBOX ready and connect at COM1 port
3. Test writing a simple program with the following steps.
3.1 Choose Directive or type of BASIC Stamp that you need. Go
to the Directive menu and choose Stamp à BS2SX as in the picture. The
description ‘{$STAMP BS2SX} will appear on the first line. Press Enter.
6
3.2 Choose the version of the PBasic language. In Directive menu,
choose PBASICà Version2.5. The description ‘{SPBASIC 2.5} will appear
on the second line. Press Enter.r
3.3 Choose the serial port to be used to communicate with the
Stamp-BOX. In the Directive menu, choose Port à Com1 (or the port
that it is connected to). The description ‘{$PORT COM1} will appear on
the third line. Press Enter.
3.4 Type debug “welcome”. This command tells the Stamp-BOX
to send the message welcome to the Debug Terminal of the Basic Stamp
Editor Program. Press Enter.
7
3.5 Click on RUN. A window checking the connection status of
the BASIC Stamp 2SX will appear, followed by the download window.
Then the Debug Terminal window displaying the message welcome
will appear.
3.6 Press the RESET switch on the Stamp-BOX. A rerun of the
messages will appear on the Debug Terminal since the RESET switch is
used to command the Stamp-BOX to restart the operation again.
3.7 If the message “No BASIC Stamps found” appears as below
it means that the connection between the computer and the StampBOX failed. This may result from bad cable connection to the computer
or low battery. Depending on the problem, check the cable or change
the battery.
4. After you complete writing the test program and want to save it as a
file, always use the .bsx format. This is because the BASIC Stamp 2SX
Interpreter will interpret .bsx files only.
How to use the Basic Stamp Editor V2 program, as well as the
Basic Stamp 2SX commands can be read from the BASIC Stamp Editor
manual; free download from www.parallax.com. However in RoboStamp’s CD-ROM bundled this manual ready.
8
iZEBOT
Robo-Stamp 2.0 Smart Robot kit
This small automatic robot has a round
body and is driven with a DC motor and
gear set. It has a large round wheel that
supports not only fast, but also efficient
movement.
Activity #1: Building iZEBOT
A1.1 Wrap the rubber band around the wheel. Do
this for both sets.
A1.2 Attach the covered wheels to the motor
gearbox. Use the 2mm. screws and screw the wheels
onto the motor gearbox tightly. Repeat for the other
set of wheels and motor gearbox.
A1.3 Take the completed wheel sets and attach it to
the body plate of the robot. Then use size 3 x 6 mm
machine screws to screw them together tightly. Place
the motors opposite of each other as shown in the
picture.
Motor position attached
Motor position attached
9
A1.4 Screw the flat-end screws into the box holder from
the inside, using 3.x 12mm. flat-head screws. Place the
3mm. plastic spacer onto the screw, then screw in
the alloy spacer tightly. Repeat for the other hole in
the box, according to position shown in the picture.
Hole postion of screws
Box holder
A1.5 Place the box holder from step A1.4 onto the
iZEBOT robot body plate. Use the 3 x 10mm machine
screws to screw the box holder and body plate
together so that they are aligned together as shown
in the picture below.
Turn back iZEBOT chasis
A1.6 Place the Stamp-BOX into the box holder. Then
connect the cable from the motor into the DIRECT
output of motor A and DIRECT output of motor B. The
iZEBOT is now ready for you to write the control
program.
10
Activity #2 : iZEBOT motor driveing
The motor used in the Robo-Stamp iZEBOT is a DC motor. The
motor functions when it receives a direct current. Figure A2-1
shows how the direction of the motor is controlled when electric
current is supplied into the DC motor.
ẵàµÍÃÕè
BATTERY
ẵàµÍÃÕè
BATTERY
Figure A2-1 Shows electric current being supplied to the motor.
(a) The motor rotates clockwise when positive current is sent to the red end and
negative current to the black end.
(b) The motor rotates counter-clockwise when positive current is sent to the black
end and negative current to the red end.
The motor module in the Stamp-BOX
Stamp-BOX can drive two DC motors. The first one or Motor A is
controlled from P12 and P13 of i-Stamp. The second motor or
Motor B is controlled by P14 and P15. Figure A2-2 shows the flow
of the electric current into the motor as well as the BASIC
commands used to control the motor module for motor A. For
motor B, change the commands for P14 and P15 instead.
HIGH 12
P12
LOW 12
P12
HIGH 13
P13
Motor driver
LOW 13
P13
Motor driver
Figure A2-2 Using BASIC commands to control how the motor.
11
You can order the motor to stop running by setting P12
and P13 to either both LOW or HIGH. However, setting both to
LOW will also stop the flow of electric current to the motor and
would therefore help save power, unlike setting both to HIGH.
Position of the Motor Polarity
Stamp-Box has 4 connection points for the 2 motors as
shown in figure A2-3. As you can see, the connection point for
DIRECT and INVERT are the same except for the difference in
polarity. If the motor is connected to INVERT, the motor will spin
in the opposite direction as when connected to DIRECT.
DIRECT
INVERT
Motor driver
DIRECT
INVERT
Figure A2-3 Motor output postion on Stamp-BOX
Testing the Polarity Connection of the Motor
A2.1 Open the BASIC Stamp Editor and type in the following
program. Download it to the iZEBOT robot and turn off the
POWER switch on the Stamp-BOX
'{$STAMP BS2sx}
Listing A2-1
'{$PBASIC 2.5}
' ++++++++++++++++++++ PROGRAM A2.1 ++++++++++++++++++++++++
' +++++++++ FORWARD & BACKWARD EVERY 2 SECOND ++++++++++++++
DO
LOW 12 : HIGH 13 : LOW 14 : HIGH 15 ' Motor Forward
PAUSE 2000
' Delay 2 Sec
HIGH 12 : LOW 13 : HIGH 14 : LOW 15 ' Motor Backward
PAUSE 2000
' Delay 2 Sec
HIGH 12 : LOW 13 : LOW 14 : HIGH 15 ' Motor A Backward , Motor B Forward
PAUSE 2000
LOW 12 : HIGH 13 : HIGH 14 : LOW 15 ' Motor A Forward , Motor B Backward
PAUSE 2000
LOOP
12
A2.2 Remove the download cable (CX-4) and lift the robot off
the floor. Turn on the power switch and observe the motor.
The motor will turn clockwise for 2 seconds and then turn
counter-clockwise for another 2 seconds. Motor A and Motor B
will then spin in the opposite direction for another 2 seconds. It
will repeat these steps continuously.
A2.3 Place the iZEBOT robot back on the floor and observe its
movement.
(1) If both the status lights of the motor module are green,
the robot will move forward.
(2) If both the status lights of the motor module are red,
the robot will move backwards.
(3) If the status light of Motor A is green while the status
light of Motor B is red, the robot will turn left.
(4) If the status light of Motor A is red while the status light
of Motor B is green, the robot will turn right.
If the movement of the robot is not according to the
above, try changing the polarity connection of the motor until
the iZEBOT robot moves correctly as in (1) to (4).
Activity #3: Moving the iZEBOT robot
To keep the control program for iZEBOT robot short and easy to
read, the programs for different movements of the robot should
be written in the form of subroutines.
Robo-Stamp Note (1)
In writing the subroutine of PBASIC 2.5, you need to start with the label name followed by
: and end with RETURN in order to go back to the main program.
Label name
Forward:
End of subroutine
HIGH 13
LOW 12
HIGH 15
LOW 14
RETURN
In the case that the program is short, you can use : between commands to keep it in one line.
Forward:
RETURN
HIGH
13 : LOW 12 : HIGH 15 : LOW 14 :
13
The iZEBOT robot has 6 different movement as following:
Movement
Table A3-1 Shows
each movement of
the iZEBOT robot.
Motor B
P15
P14
Forward
High
Backward
Motor A
Direction
P13
P12
Low
High
Low
Low
High
Low
High
Turn Left
Low
Low
High
Low
Turn Right
High
Low
Low
Low
Rotate Left
Low
High
High
Low
Rotate Right
High
Low
Low
High
Stop
Low
Low
Low
Low
Direction
These movements can be written as a subroutine as
shown in Listing A3-1. However this subroutine can not function
by itself and needs the main program to run it.
Forward: HIGH 13
Backward: HIGH 12
T_Left:
HIGH 13
T_Right: LOW 13
S_Left:
HIGH 13
S_Right: HIGH 12
Motor_OFF: LOW 13
:
:
:
:
:
:
:
LOW
LOW
LOW
LOW
LOW
LOW
LOW
12
13
12
12
12
13
12
:
:
:
:
:
:
:
HIGH
HIGH
LOW
HIGH
HIGH
HIGH
LOW
15
14
15
15
14
15
15
:
:
:
:
:
:
:
LOW
LOW
LOW
LOW
LOW
LOW
LOW
14
15
14
14
15
14
14
:
:
:
:
:
:
:
RETURN
RETURN
RETURN
RETURN
RETURN
RETURN
RETURN
Listing A3-1
Program A3-1 can be combined with the main program
as following the Listing A3-2.
'{$STAMP BS2sx}
'{$PBASIC 2.5}
PAUSE 1000
Main:
GOSUB Forward : PAUSE 1000
GOSUB T_Left
: PAUSE 500
GOSUB Forward : PAUSE 1000
GOSUB T_Right : PAUSE 500
GOSUB Forward : PAUSE 1000
GOSUB S_Left
: PAUSE 500
GOSUB Backward : PAUSE 1000
GOSUB S_Right : PAUSE 500
GOSUB Forward : PAUSE 1000
GOSUB Motor_OFF : PAUSE 3000
GOTO Main
Forward: HIGH 13 : LOW 12 : HIGH 15 :
Backward: HIGH 12 : LOW 13 : HIGH 14 :
T_Left:
HIGH 13 : LOW 12 : LOW 15 :
T_Right: LOW 13 : LOW 12 : HIGH 15 :
S_Left:
HIGH 13 : LOW 12 : HIGH 14 :
S_Right: HIGH 12 : LOW 13 : HIGH 15 :
Motor_OFF: LOW 13 : LOW 12 : LOW 15 :
14
Listing A3-2
LOW
LOW
LOW
LOW
LOW
LOW
LOW
14
15
14
14
15
14
14
:
:
:
:
:
:
:
RETURN
RETURN
RETURN
RETURN
RETURN
RETURN
RETURN
The Listing A3-2 tells the robot to move as following:
(1) Order the robot to move straight 1 second
(2) Order the robot to turn left 0.5 seconds.
(3) Order the robot to move straight 1 second.
(4) Order the robot to turn right 0.5 seconds.
(5) Order the robot to move straight 1 second.
(6) Order the robot to rotate left 0.5 seconds
(7) Order the robot to move backward 1 second.
(8) Order the robot to rotate right 0.5 seconds.
(9) Order the robot to move straight 1 second.
(10) Order the robot to stop for 3 seconds.
The robot will then go back to (1)
A3.1 Type program A3-2 and download it to the iZEBOT robot.
Turn off the power switch on the Stamp-BOX
A3.2 Remove the download cable. Place the iZEBOT robot on
the floor and observe its movements.
The iZEBOT should move as defined in the program.
Robo-Stamp Note (2) Limitations of robots that are driven with direct current.
Specifying the point to turn for robots driven with DC motors can only be made by
specifying the operation time. For example, if you want the robot to make a 90 degree left
turn, you would not be able to program it to turn 90 degrees. You would have to specify the
amount of time it takes to turn left as shown in the Listing A3-2.
GOSUB T_Left : PAUSE 500
From the program, the robot would turn left for 0.5 seconds. The user would have to
test if 0.5 seconds would result in a 90 degree turn or not. If not, the number of seconds
would have to be adjusted so that the turn would be 90 degrees.
15
iZEBOT
Collision Detection via
Switch
Robo-Stamp 2.0 Smart Robot kit
Add the basic senses to the iZEBOT robot
so that it can detect and avoid obstacles.
The switch can also be used to control
how it operates.
Activity #4 Installing the switch on
iZEBOT
A4.1 Put the switch input and angled joiner together. Place a 3
x 10mm. machine screw and 3mm. nut together with the switch
and use a screwdriver to screw them together tightly. Do the
same for both sets.
A4.2 Connect the strength joiner to the front of the iZEBOT robot
on the right-hand side. This will be used to attach the switch input.
Choose a hole in the front area of the robot and screw in a 3 x
10mm. machine screw and 3mm. nut. Push the strength joiner
in.
16
A4.3 Connect the obtuse joiner to the other end of the strength
joiner as in the picture. Do the same for the other set and
connect it to the left-hand side of the robot.
A4.4 Take the switch input that is attached to the angled joiner
and connect it to both arms of the robot, with the cable input
side turned upward.
A4.5 Connect the signal cable between the switch input and
Stamp-BOX as following:
Connect the right switch with P6 of the Stamp-BOX
Connect the left switch with P1 of the Stamp-BOX
iZEBOT robot is now ready to detect any obstacles.
17
Activity #5: Writing a program to
read the switch value.
Reading the input value from the switch with PBASIC can
be done through the IF....THEN function by checking the
conditions of each port connected to the switch. The INx
command will be used to read the value from each port (x is
the port number. If it the switch is connected to P1 then IN1 will
be used)
A5.1 Open the Basic Stamp Editor program and type in Listing
A5-1. Download it into the iZEBOT robot.
Switch/Touch sensor
Signal connector
Indicator Switch
LED1
'{$STAMP BS2sx}
'{$PBASIC 2.5}
Main:
Listing A5-1
R1
510
IF (IN1 = 0 ) THEN
HIGH 12 : LOW 13
ENDIF
GOTO Main
Motor A will start to run when the switch is pressed.
A5.3 In addition to using the IF...THEN function to make the
program operate when the conditions are true, it can also
operate in a different way when the program conditions are
false. Type Listing A5-2 and download it into the iZEBOT robot.
Listing A5-2
Main: IF (IN1 = 0 ) THEN
HIGH 12 : LOW 13
ELSE
LOW 12 : LOW 13
ENDIF
GOTO Main
A5.4 Remove the download cable. Lift the robot up. Press down
on the left switch for a few seconds and let go. Observe how
the robot operates.
The motor will run when the switch is pressed. Once
the switch is released the motor will stop working.
18
+V
R2
10k
R3
220
DATA
Signal output
S1
GND
Switch
A5.2 Remove the download cable. Lift the robot up. Press the
left switch (connected to P1 of the Stamp Box) and observe
how the robot operates.
'{$STAMP BS2sx}
'{$PBASIC 2.5}
Indicator
The switch sensor has
the above circuit diagram.
If the switch is not
pressed, DATA will
have a logic value of
“1” due to the resistor
R2 that is connected to
+V.
Once the switch is
pressed, DATA will be
connected to ground,
and will result in a
logic value “0”. The
flow of current will
then light LED1.
Activity #6: iZEBOT versus The Wall
In this activity, the switch input will be used to determine
the movements of the iZEBOT robot.
A6.1 Open the Basic Stamp Editor program. Type in Listing A6-1
and download it to the iZEBOT robot. Turn off the POWER switch.
'{$STAMP BS2sx}
'{$PBASIC 2.5}
PAUSE 1000
Main: GOSUB Forward
IF (IN1 = 0) OR (IN6 = 0) THEN
GOSUB Backward : PAUSE 1000
GOSUB S_Right : PAUSE 500
ENDIF
GOTO Main
Listing A6-1
' Test switch from P1 or from P6
' IF switch pressed, backward
' and spin right
' Test again
'+++++ Movement Procedure +++++++++++++++++++++++++++++
Forward: HIGH 13 : LOW 12 : HIGH 15 : LOW 14 : RETURN
Backward: HIGH 12 : LOW 13 : HIGH 14 : LOW 15 : RETURN
T_Left:
HIGH 13 : LOW 12 : LOW 15 : LOW 14 : RETURN
T_Right: LOW 13 : LOW 12 : HIGH 15 : LOW 14 : RETURN
S_Left:
HIGH 13 : LOW 12 : HIGH 14 : LOW 15 : RETURN
S_Right: HIGH 12 : LOW 13 : HIGH 15 : LOW 14 : RETURN
Motor_OFF: LOW 13 : LOW 12 : LOW 15 : LOW 14 : RETURN
'++++++++++++++++++++++++++++++++++++++++++++++++++++++
A6.2 Remove the download cable. Hold the robot in your hand
and turn on the Power switch.
The status light of the motor circuit is both green.
This means that the motor is supposed to move forward.
A6.3 Test by pressing any switch.
The status light of the motor circuit will both be red.
This means that the motor is supposed to move backward.
Then the status light for Motor A will be green while the
light for Motor B will be red. This means that the left wheel
will move forward while the right wheel will continue to
move backward. This will cause the robot to turn. Then
both status lights will be green again, indicating that the
robot is now moving forward.
19
A6.4 After testing how it works, turn off the switch. Prepare the
test area by placing obstacles wherever you want. Then put
the robot on the floor and turn on the power switch. Observe its
movements and areas that need to be adjusted such as if the
robot reverses too much or if it turns too little.
The iZEBOT robot will move forward and detect any
pressure on the switch. If any of the switches are pressed
the iZEBOT robot will move backwards and turn. Then it will
resume its normal function and move forward again.
1
2
3
4
A6.5 Test editing the program source code and download the
program for the robot to try again.
Modifying the Program
From Listing A6-1, the test was designed to have the same
results. That is, when either switch is pressed, the iZEBOT robot
will move backward and turn right. In reality, if the robot hits the
right switch it means there is an obstacle on the right side of the
robot and the robot should turn left in order to avoid the
obstacle. Therefore, the program should be modified to Listing
A6-2.
Moreover, Listing A6-2 also includes the command to start
operating only when the switch is pressed to start. Therefore,
when the program is finished downloading, the robot will not
work immediately. The robot will start only when the left switch
connected to P1 is pressed.
A6.6 Open the Basic Stamp Editor program. Type in Listing A6-2
and download it into the iZEBOT robot. Turn off the POWER switch.
20
5
'{$STAMP BS2sx}
'{$PBASIC 2.5}
Init:
Main:
IF IN1 = 0 THEN
PAUSE 500
GOTO Main
ENDIF
GOTO Init
GOSUB Forward
IF (IN1 = 0)THEN
GOSUB Backward : PAUSE 1000
GOSUB S_Right : PAUSE 500
ENDIF
IF (IN6 = 0)THEN
GOSUB Backward : PAUSE 1000
GOSUB S_Left : PAUSE 300
ENDIF
GOTO Main
Listing A6-2
'Check switch before run program
' Loop test again
' Test switch at P1
' If switch at P1 pressed, backward
' and spin Right
' Test switch at P6
' If switch at P6 pressed, backward
' and spin left
' Test again
'+++++ Movement Procedure +++++++++++++++++++++++++++++
Forward: HIGH 13 : LOW 12 : HIGH 15 : LOW 14 : RETURN
Backward: HIGH 12 : LOW 13 : HIGH 14 : LOW 15 : RETURN
T_Left:
HIGH 13 : LOW 12 : LOW 15 : LOW 14 : RETURN
T_Right: LOW 13 : LOW 12 : HIGH 15 : LOW 14 : RETURN
S_Left:
HIGH 13 : LOW 12 : HIGH 14 : LOW 15 : RETURN
S_Right: HIGH 12 : LOW 13 : HIGH 15 : LOW 14 : RETURN
Motor_OFF: LOW 13 : LOW 12 : LOW 15 : LOW 14 : RETURN
'++++++++++++++++++++++++++++++++++++++++++++++++++++++
A6.7 Remove the download cable. Then place the iZEBOT robot
on the floor and turn on the POWER switch. Press the left switch
one time and observe the robot.
The iZEBOT robot will move forward and check if
there is any contact at the switches or not. If there is
contact on the left switch, the iZEBOT robot will move
backward and turn right. Vice versa, if the right switch is
hit, the iZEBOT robot will move backward and turn left.
21
iZEBOT
Serial Communication
Robo-Stamp 2.0 Smart Robot kit
Not only should an automatic robot be
able to receive commands and program
data from the computer, but it should also
send data back to the computer. The
iZEBOT robot also has this capability, in
which communication between the
iZEBOT robot and computer is done
through serial communication.
Activity #7: Serial Data Transmission
Downloading the program written from the Basic Stamp
Editor to the iZEBOT robot can be considered as a form of
communication in which the computer acts as the sender and
the iZEBOT robot is the receiver. Two-way communication can
be done through the Debug Terminal window as shown in Figure
A7-1 When the iZEBOT (through the Stamp-BOX) sends data to
the computer, the data will appear on the blue display screen
(color can change). Data can be sent to the Stamp-BOX by
typing it into the input box above the blue display screen
Set the serial data format
Type in data to send out
Received data screen
Figure A7-1 Component of Debug Terminal that use in serail data communication
22
Using the DEBUG command to send
data from Stamp-BOX to the computer
A7.1 Connect the CX-4 (download cable) between the iZEBOT
robot and the serial port (If the computer doesn’t have an serial
port use the USB port converter to convert it into a RS-232 port or
COM port).
A7.2 Open the Basic Stamp Editor program and type in the
following program. Download the program to the iZEBOT robot.
'{$STAMP BS2sx}
'{$PBASIC 2.5}
Main:
IF (IN1 = 0) THEN
DEBUG "iZEBOT"
PAUSE 1000
ENDIF
GOTO Main
Listing A7-1
' Test Switch
' Show ASCII
' Delay 1 Sec
' Again
A7.3 The Debug Terminal window will appear with no data on
the display screen yet. With the download cable still connected,
press the switch connected to P1 of the Stamp-BOX. Observe
the changes that occur on the Debug Terminal window.
This test program shows how data sent from the
iZEBOT robot will be displayed on the Debug Terminal
window. When the switch connected to P1 is pressed, the
robot will send the text “iZEBOT” to be displayed on the
Debug Terminal window as shown in Figure A7-2.
Figure A7-2 Show receiveing data from iZEBOT via Debug Terminal
23
Receiving Data using the SERIN Command
P16 is used to receive and send serial data from the serial
port of the i-Stamp, which is the micro-controller board on the StampBOX of the iZEBOT robot. Therefore, the position of the terminal
must be defined as 16 in order to read the output values from this
port
Data communication between the computer and StampBOX uses the serial RS-232 standard, which includes the baud rate,
data bit, stop bit, and parity bit. The baud rates that are usually
used are1200, 2400, 4800, and 9600 bits per second (bps). There
are 8 data bits, 1 stop bit, and no parity bits, abbreviated as 8N1.
Table A7-1 shows the value assigned for each baud rate
that the SERIN command must use.
Baudrate and Data format
baud value of SERIN
command
1200 bps : 8N1
2063
2400 bps : 8N1
1021
4800 bps : 8N1
500
9600 bps : 8N1
240
Table A7-1 Displays the baud value used in the SERIN command
to specify the baud rate and data format.
A7.4 Connect the CX-4 cable between the iZEBOT robot and
serial port (or through the USB to RS-232 port converter if the
computer does not have an serial port)
A7.5 Open the Basic Stamp Editor program. Type the following
program and download it into the iZEBOT robot.
24
'{$STAMP BS2sx}
'{$PBASIC 2.5}
KEY
VAR
Byte
Main:
SERIN 16,240,[KEY]
IF (KEY = "A") THEN
DEBUG CLS,"FORWARD"
GOSUB Forward
ENDIF
IF (KEY = "B") THEN
DEBUG CLS,"MOTOR STOP"
GOSUB Motor_OFF
ENDIF
GOTO Main
Listing A7-2
'
'
'
'
Baudrate 9600 8N1
Test key = A ?
Show status on Debug Terminal
Robot forward
' Test key = B ?
' Show status on Debug Terminal
' Stop motor
' Loop again
'+++++ Movement Procedure +++++++++++++++++++++++++++++
Forward: HIGH 13 : LOW 12 : HIGH 15 : LOW 14 : RETURN
Backward: HIGH 12 : LOW 13 : HIGH 14 : LOW 15 : RETURN
T_Left:
HIGH 13 : LOW 12 : LOW 15 : LOW 14 : RETURN
T_Right: LOW 13 : LOW 12 : HIGH 15 : LOW 14 : RETURN
S_Left:
HIGH 13 : LOW 12 : HIGH 14 : LOW 15 : RETURN
S_Right: HIGH 12 : LOW 13 : HIGH 15 : LOW 14 : RETURN
Motor_OFF: LOW 13 : LOW 12 : LOW 15 : LOW 14 : RETURN
'++++++++++++++++++++++++++++++++++++++++++++++++++++++
A7.6 The Debug Terminal window will appear with no data on
the display screen yet. With the download cable still connected,
click the mouse at the input box on the Debug Terminal window.
A7.7 Test the program by typing in the character A or B. Observe
the iZEBOT robot and the results displayed on the Debug Terminal
window.
If A is typed, the robot will move forwards
If B is typed, the robot will stop moving
The robot’s action will also be sent to the computer
and displayed as seen in Figure A7-3.
Figure A7-3 Debug Terminal displaying the input key and the resulting action.
25
Creating Music note through Data
transmission
A7.8 Connect the CX-4 cable between iZEBOT and the serial
port (or through the USB port converter to RS-232)
A7-9 Open the BASIC Stamp Editor Program. Type in the following
program and then download it into the iZEBOT robot.
'{$STAMP BS2sx}
'{$PBASIC 2.5}
C
D
E
G
KEY
CON
CON
CON
CON
VAR
837
939
1054
1254
Byte
Listing A7-3
'
'
'
'
DO
SERIN 16,240,[KEY]
SELECT KEY
CASE "C"
FREQOUT 11,200,C
CASE "D"
FREQOUT 11,200,D
CASE "E"
FREQOUT 11,200,E
CASE "G"
FREQOUT 11,200,G
ENDSELECT
LOOP
C
D
E
G
note
note
note
note
'
'
'
'
'
'
'
'
'
'
'
Loop
Save Data From Debug
CHeck Key = Note
Press Key "C"
Generate Sound
KEY = "D"
Generate Sound
KEY = "E"
Generate Sound
KEY = "G"
Generate Sound
' Loop
A7.10 The Debug Terminal window will appear with no data on
the display screen yet. With the download cable still connected,
click the mouse at the input box of the Debug Terminal window.
A7.11 Test the program by typing the characters C, D, E or G
and observe the robot.
If C is pressed, the robot will play the note Do
If D is pressed, the robot will play the note Re
If E is pressed, the robot will play the note Me
If G is pressed, the robot will play the note Sol
A7.12 The user can define the baud rate at the Debug Terminal
window. Test by changing the baud rate according to Table
A7-1. Observe the results. Also test by entering the wrong value
to see if the robot is still functioning according to the original
conditions or not.
26
iZEBOT Remote Control
Robo-Stamp 2.0 Smart Robot kit
Another feature of automatic robots is
that it can receive commands from a far
distance by using infrared light. This is
similar to a remote-controlled robot
except that the commands received are
through serial communication.
Activity #8: Installing the Infrared Receiver Module
A8.1 Use a 3 x 10mm. machine screw and place it into the
Infrared Receiver Module board, followed by the 3mm. plastic
spacer. Then place the obtuse joiner at the back of the module
and used a 3mm. nut to screw it all in together tightly.
A8.2 At the front of the robot, use a 3 x 6 mm. machine screw to
screw in the metal spacer to the body plate of the robot (The
switches from Activity #7 can be removed for ease in
installation).
27
A8.3 Attach an angled joiner to the other end of the metal
spacer with a 3 x 6mm. machine screw.
A8.4 Attach the end of the angled joiner to the other end of the
obtuse joiner from A8.1 that is connected to the Infrared
Receiver Module board. The receiver of the Infrared Receiver
module should be facing the front so that it can better receive
infrared light.
A8.5 Connect the signal cable of theInfrared Receiver Module
board to connection point P3 on the Stamp-BOX of the iZEBOT
robot. The robot is now ready to operate with the infrared remote
control ER-4
38kHz Infrared Receiver module sensor
Signal output
3
1
0.1uF
50V
Infrared Module
Vcc
1 DATA
DATA
GND
2
2
1
Infrared Receiver module
28
GND
3 Vcc
2
3
If the sensor does not detect
the 38kHz frequency with
the infrared light, the output
will be logic “1”. Otherwise,
if it detects the 38kHz
frequency, the output logic
is “0”.
Activity #9: Using the ER-4 Remote
Control
The Easy remote4 (ER-4) is a multi-purpose infrared remote control
which sends out serial data mixed into the 38kHz carrier
frequency.
ER-4 Easy Remote4
4-channels
Infrared Remote
Control
Data format of ER-4 Remote control
To make it easier for the receiver to read the switch value from
the remote control, the ER-4 transmits serial data according to
the RS-232 standard, with a baud rate of 1,200 bps and 8N1
format. Characters are transmitted according to what switch is
pressed on the remote. The switch positions are displayed in
Figure A9-1.
l
Press switch A, the large cap A , followed by small cap A is sent.
l
Press switch B, the large cap B, followed by small cap B is sent
Uses a microcontroller to control the
data created and sent
l
Press switch C, the large cap C, followed by small cap C is sent
l Operational distance
l
Press switch D, the large cap D, followed by small cap D is sent.
is 8-10 meters in open
space.
The reason that we have to alternate large cap and small cap
letters is so that the receiver can differentiate if a user presses
continuously or if the user represses.
The 4-channel switch
operates in an on/off
mode
If a user represses, the large cap character will be sent the first
time. If the user represses the same button again, the small cap
character will be sent the second time
l
If the user presses continually, the last character will be sent
repeatedly.
A9.1 Place 2 AA batteries into the battery compartment of the
remote control Easy Remote4
Easy remote4
K A
IR-LED
2-5V
,
Figure A9-1 Switch position on ER-4 Remote
control
+
l
l
Uses low power;
Automatically resumes
power-save mode once
data is sent
Uses only 2.4-3.0 V
from two AA batteries both regular and
rechargeable.
l
Transmits serial data
using the RS-232
standard with 1200
bps. baud rate and 8N1
data format (8 data bit,
no parity, 1 stop bit)
l
*
)
29
A9.2 Type Listing A9-1 and download it to the iZEBOT robot. Keep
the download cable connected.
'{$STAMP BS2sx}
'{$PBASIC 2.5}
KEY VAR Byte
DO
SERIN 3,2063,[KEY]
DEBUG KEY,TAB
LOOP
Listing A9-1
' Receive 1200 8N1 on P3
' Show on Debug Terminal
Additional program description
At SERIN command will be define the baud parameter as 2063. It means baudrate 1,200 bit
per second, none parity, 8-bit data and 1 stop bit. See more information in BASIC Stamp
Manual ; Free download at www.parallax.com.
A9.3 The Debug Terminal window will appear with no data on
the display screen yet. Press the switch on the remote control.
The Easy Remote4 remote control must be pointed towards the
robot’s IR receiver module. Observe the changes on the Debug
Terminal window.
If the switch is pressed and released alternately, the
data received by the iZEBOT robot will alternate between
a large cap character and a small cap character. If the
switch is pressed continuously, the data received will be
the last character (either large cap or small cap) displayed
repeatedly.
30
Activity #10: Controlling movement
through the remote control
In Activity #7, the user was able to control the movements of
the iZEBOT robot through the Debug Terminal. However, the
cable still had to be connected between the computer and
iZEBOT robot which made it inconvenient. Therefore, using the
Infrared remote control, which is a wireless communication, will
help solve the problem.
A10.1 Type in Listing A10-1 and download it into the iZEBOT robot.
Remove the download cable. Observe the results.
A10.2 Place the iZEBOT robot on the floor and turn on the power
switch. Press the switch on ER-4 to control the movements of the
robot. Observe the limitations that might occur with the robot.
'{$STAMP BS2sx}
Listing
'{$PBASIC 2.5}
KEY VAR
Byte
DO
SERIN 3,2063,[KEY] ' Read Serial DATA From P3 at 1200 8N1
IF KEY = "D" OR KEY = "d" THEN GOSUB Forward
IF KEY = "A" OR KEY = "a" THEN GOSUB Backward
IF KEY = "C" OR KEY = "c" THEN GOSUB S_left
IF KEY = "B" OR KEY = "b" THEN GOSUB S_right
LOOP
A10-1
'+++++ Movement Procedure +++++++++++++++++++++++++++++
Forward: HIGH 13 : LOW 12 : HIGH 15 : LOW 14 : RETURN
Backward: HIGH 12 : LOW 13 : HIGH 14 : LOW 15 : RETURN
T_Left:
HIGH 13 : LOW 12 : LOW 15 : LOW 14 : RETURN
T_Right: LOW 13 : LOW 12 : HIGH 15 : LOW 14 : RETURN
S_Left:
HIGH 13 : LOW 12 : HIGH 14 : LOW 15 : RETURN
S_Right: HIGH 12 : LOW 13 : HIGH 15 : LOW 14 : RETURN
Motor_OFF: LOW 13 : LOW 12 : LOW 15 : LOW 14 : RETURN
'++++++++++++++++++++++++++++++++++++++++++++++++++++++
How the Program Works:
This program will read the serial values sent from the ER-4 remote control according to
the RS-232 standard. The SERIN command is used to assign the baud rate to 1,200 bps. The
value will be stored in the variable KEY which will later be used to verify in the IF....THEN
function.
If switch D or d is pressed, the robot will move forward
If switch A or a is pressed, the robot will move backwards
If switch C or c is pressed, the robot will spin left
If switch B or b is pressed, the robot will spin right
After the switch value is verified, the program will await new data. It will then loop
back and repeat the steps.
31
Modifications:
From Program A10-1, the iZEBOT robot was able to move
according to that defined. However, the robot was unable to
stop operating once the switch on the remote control no longer
sent it commands.
This problem can be solved by modifying the software
to specify the time for data received from the remote control.
If the Easy Remote4 remote control does not send data within
a specific time, the motor module of the iZEBOT robot will stop
automatically
A10.3 Type Listing A10-2 and download it onto the iZEBOT robot.
Then turn off the switch and remove the download cable.
'{$STAMP BS2sx}
Time value and Subroutine addition
'{$PBASIC 2.5}
Listing A10-2
KEY VAR
Byte
Main:
DO
SERIN 3,2063,250,Timeout,[KEY]' Read DATA From P3 at 1200 8N1
IF KEY = "D" OR KEY = "d" THEN GOSUB Forward
IF KEY = "A" OR KEY = "a" THEN GOSUB Backward
IF KEY = "C" OR KEY = "c" THEN GOSUB S_left
IF KEY = "B" OR KEY = "b" THEN GOSUB S_right
LOOP
Timeout:GOSUB Motor_OFF
Command addition
GOTO Main
'+++++ Movement Procedure +++++++++++++++++++++++++++++
Forward: HIGH 13 : LOW 12 : HIGH 15 : LOW 14 : RETURN
Backward: HIGH 12 : LOW 13 : HIGH 14 : LOW 15 : RETURN
T_Left:
HIGH 13 : LOW 12 : LOW 15 : LOW 14 : RETURN
T_Right: LOW 13 : LOW 12 : HIGH 15 : LOW 14 : RETURN
S_Left:
HIGH 13 : LOW 12 : HIGH 14 : LOW 15 : RETURN
S_Right: HIGH 12 : LOW 13 : HIGH 15 : LOW 14 : RETURN
Motor_OFF: LOW 13 : LOW 12 : LOW 15 : LOW 14 : RETURN
Subroutine addition
'++++++++++++++++++++++++++++++++++++++++++++++++++++++
How the Program Works:
The additional routine of this program is part of the SERIN command that is used to
transmit serial data. When the time value for the switch on the remote control to be pressed
exceeds the defined value, that is 250 or 0.1 second, the program will go to the Timeout
subroutine. Therefore, if the switch is not pressed for more than 0.1 seconds, the program
will order the robot to stop moving and will call upon the subroutine Motor-OFF to operate.
A10.4 Place the robot on the floor and turn on the Power switch.
Use the ER-4 remote control to control the movements of the
robot. Compare its operation to the previous program.
A10.5 Modify the program so that the remote control is
programmed to control the different movement of the iZEBOT
robot.
32
iZEBOT
Distance Measurement
with Infrared
Robo-Stamp 2.0 Smart Robot kit
Add another sense to the robot by enabling it to
measure distance and detect obstacles using
infrared light. Use the GP2D120 module so that
the iZEBOT robot can avoid obstacles without
having to make contact.
Activity #11: Installing the GP2D120 to the iZEBOT
robot
A11.1 Screw in 2 of 3 x 10mm. machine screws
into the installation slot on the GD2D120 module
loosely followed by 3mm. nuts. Do not tighten.
A11.2 Place the strength joiner between the screw and nut, and
tighten the screw. (Leave it loose enough to change the angle)
A11.3 Attach an obtuse joiner to the other end of the strength
joiner. Repeat for both sides as shown in the picture.
33
A11.4 Attach a strength joiner to the other end of the obtuse
joiner. Then place an angled joiner to the other end of the
strength joiner.
A11.5 Use a 3 x 10mm. machine screw to screw it in loosely with
a 3mm. nut at the front (or back : no other sensor is attached
on the other side) of the robot, and on the right and left sides.
A11.6 Use a 3 x 10mm. amchine screw and 3mm. nut to attach
Module GP2D120, along with the attached joiners, to the body
plate of the robot. Connect the cable from Module GP2D120
connection point ANALOG1
The iZEBOT robot is now ready to measure
the distance and detect faraway obstacles without
any contact, but by using infrared light instead.
Warning for the signal cable of the GP2D120
The GP2D120 module has a different pin arrangement
then that of the Stamp-BOX, even though it looks similar.
Therefore, a special signal cable has already been
connected to the GP2D120 module. The user just needs
to connect the other end of the cable to the connection
points of the Stamp-BOX. Do NOT remove the cable from
the module, and do not replace it with signal cables
from other sensor modules.
34
Activity #12 Reading the Analog
Signal
Since the i-stamp or Basic Stamp 2SX, which is the main
micro-controller in the iZEBOT Stamp-BOX, does not have an
analog to digital converter module (A/D converter), an external
converter must be connected in order to communicate with
components that send out voltage signals, such as Module
GP2D120. Therefore, IC QP410 will be used to convert and send
digital signals to the main micro-controller. Figure A12-1 displays
the circuit schematic when connected with the Stamp-BOX.
+5V
+5V
K9
ANALOG6
+5V
K8
ANALOG5
+5V
K7
ANALOG4
5 AN2
6
+5V
AN3
GP3
GP5
4
2
+5V
R14
10k
P10
R15
150
AN1
7 AN0
IC4
QP410
8
A/D Converter IC
l 4 analog channels.
l Input voltage of 0 -
+5V
l 10-bit A/D converter
l can be connected to
increase the input to 8
channels.
a serial
interface connection
will use only one port
of microcontroller
1
3
Serial interface
l Using
C5
0.1/63V
K10
ANALOG7
QP410
l Baud rate 9,600 bps
l Uses 2.5 - 5V power
supply
l No external compo-
nents needed.
+5V
1
3
K5
ANALOG3
+5V
K4
ANALOG2
+5V
5 AN2
6
K3
ANALOG1
+5V
K2
ANALOG0
+5V
IC5
QP410
AN3
AN1
GP5 2
GP3
4
R16
150
7 AN0
8
Figure A12-1 The analog receiver circuit of the Stamp-BOX
has 2 IC QP410 connected to connection point P10 of the iStamp, resulting in an analog input of 8 channels.
35
Communicating with IC QP410
Communicating with the IC QP410 A/D converter can be done
through a program, as shown in Listing A12-1. The program reads
the data value from ANALOG1 of the Stamp-BOX (while
connected to Module GP2D120), then displays it onto the
Debug Terminal window. The program works according to the
following steps.
'{$STAMP BS2sx}
'{$PBASIC 2.5}
'*********************************
' Read Data From Analog Input (CH1)
'*********************************
ADC VAR
Word
PAUSE 1000
Init:
HIGH 10
DO
LOW 10:PAUSE 1:HIGH 10
SEROUT 10,240,[1]
SERIN 10,240,[ADC.BYTE0,ADC.BYTE1]
DEBUG DEC STREAM,CR
PAUSE 1000
LOOP
Listing A12-1
' Idle chip ADC
'
'
'
'
Send acknowledge
Select channel 1
Read ADC
Show data on Debug Teminal
(1) Pauses or delays for 1 second so that the IC QP410 is
ready to operate.
(2) Sends a pulse signal so that the IC QP410 can
acknowledge and get ready to communicate with the StampBOX
(3) The i-Stamp sends the value of the channel to be read
to the IC QP410. From Listing A12-1, the value is 1 which means
that it will be communicate with ANALOG1
(4) The i-Stamp reads the value from channel ANALOG1
of the IC QP410 and stores it in the variable ADC. The variable is
defined as type word, which can store up to 16 bits of data,
therefore easily storing the 10 bit data from the IC QP410.
(5) i-stamp sends the value that it reads to be displayed
on the Debug Terminal.
A12.1 Download Program A12-1 to the Stamp-BOX on the iZEBOT
robot and do not remove the download cable yet. The Debug
Terminal window will appear automatically.
A12.2 Observe the values displayed on the Debug Terminal .
36
A12.3 Use your hand or a piece of paper to block in front of the
GP2D120 module. Observe the number that appears on the
Debug Terminal
The numbers that appear on the Debug Terminal
window will increase.
A12.4 Move your hand or the paper back and forth to change
the distance between the GP2D120 module. Observe the
changes that occur.
The numbers that appear on the Debug Terminal
window will change according to the distance. But the
data that the QP410 IC reads from the GP2D120 module is
raw data, and not the final distance value.
A12.5 To make it more convenient to write programs that can
call upon the A/D converter QP410 when needed, asubroutine
called RD_ADC is created as shown in Listing A12-2.
RD_ADC: LOW 10:PAUSE 1:HIGH 10
' Send acknowledge
SEROUT 10,240,[1]
SERIN 10,240,[STREAM.BYTE0,STREAM.BYTE1]
RETURN
Listing A12-2
' Select channel 1
' Read ADC
Activity #13: Communicating with GP2D120
The output from Module GP2D12 or GP2D120 is voltage. When
connected to the iZEBOT robot, it must be connected to ports
ANALOG0 to ANALOG7 so that the values can be read through
IC QP410. In the previous activity, the GP2D120 module was
connected to ANALOG1, so we can proceed on with this
activity.
The value received from GP2D12 or GP2D120 must be displayed
in the form of range. This can be done by converting the voltage
value using a comparison graph between voltage and range.
For convenience, a line equation with the following formula has
been created.
'"
4=
− for GP2D120
8 +#
4=
$%&%
−"
8 −!
for GP2D12
Thus, R Range measured in centimeters
V Data Received from the A/D converter
37
GP2D120/GP2D12 Infrared Ranger module
LED ÍÔ¹¿ÃÒàôµÑÇʋ§
µÑÇÃѺáʧÍÔ¹¿ÃÒàô
l Uses Infrared light reflection to measure range
l Can measure a range from 10 to 80 cm for
GP2D12 and 4 to 30 cm for GP2D120
/2 ,
/2 , l 4.5-5 V power supply and 33mA electric current
Vout
l The output voltage range is 0.4 to 2.4V when
GND
Vcc
supplied by +5V
GP2D12/GP2D120 Infrared Ranger module has 3 terminals: Power input (Vcc), Ground
(GND) and voltage output (Vout). To read the voltage values from the GP2D12, you must
wait till after the acknowledgement period which is around 32 to 52.9 ms.
The output voltage of GP2D120 at a range of 30 cm and +5V power supply is between
0.25 to 0.55V, with the mean being 0.4V. At the range of 4-30 cm, the output voltage will
change at 2.25V± 0.3V.
The output voltage of GP2D12 module at a range of 80 cm and +5V power supply is
between 0.25 to 0.55V, with the mean being 0.4V*. At the range of 10-80 cm, the output
voltage will change at 2V± 0.25V.
GP2D120 characteristic curve
Output voltage
(V)
GP2D12 characteristic curve
Output Voltage
(V)
2.8
2.8
2.4
2.4
2.0
2.0
1.6
1.6
1.2
1.2
0.8
0.8
0.4
0.4
0
0
4
8
12
16
20
24
Distance (cm)
28
32
0
0
10
20
30
40
50
60
70
80
Distance (cm)
* Use Kodak R-27 gray-white paper. The white side has a 90% reflection rate, made from a
material that reflects light for range measurement.
38
How the IR Ranger Module works
object
Measuring range can be done in many
ways. The easiest to understand is through
ultra sonic where sound waves are sent to
the object and the time it takes to reflect
back is measured. This is because sounds
waves do not travel fast, and can be
measured by present day equipment.
However, in the case of infrared light, the
time it takes to hit an obstacle and reflect
back can not be measured because infrared
light travels fast. No measurement
equipment is available yet. Therefore, the
following theory must be used.
The infrared light is sent out from a
transmitter to the object in front, by passing
through a condense lens so that the light
intensity is focused on a certain point.
Refraction occurs once the light hits the
surface of the object. Part of the refracted
light will be sent back to the receiver end,
in which another lens will combine these
lights and. determine the point of impact.
The light will then be passed on to an array
of photo-transistors. The position in which
the light falls can be used to calculate the
distance (L) from the transmitter to the
obstacle using the following formula:
Signal
processing
Regulator
Oscillator
LED Driver
Driver
output
L F
=
A X
Therefore, L equals
L=
F×A
X
Thus, the distance value from the
phototransistors will be sent to the Signal
Evaluation Module before it is changed to
voltage, resulting in a change of voltage
according to the measured distance.
39
A13.1 Type in Listing A13-1 and download it to the iZEBOT robot.
After finished, turn off the switch. Do not remove the download
cable yet.
'{$STAMP BS2sx}
'{$PBASIC 2.5}
ADC VAR
Word
R
VAR
Word
Listing A13-1
PAUSE 1000
HIGH 10
DO
GOSUB RD_ADC
R = (2914 /(ADC+5))-1
' Convert Voltage to Range (CM)
' Show Range On Debug Terminal
DEBUG "ADC = ",DEC ADC,TAB, "Range = ",DEC R ," CM" ,CR
PAUSE 200
LOOP
' Read Again
RD_ADC: LOW 10: PAUSE 1: HIGH 10
SEROUT 10,240,[1]
SERIN 10,240,[ADC.BYTE0,ADC.BYTE1]
RETURN
' Send Acknowledge
' Send Select Chip
' Read ADC
How the Program works:
(1) Pause 1 second for the A/D converter to get ready
(2) Call subroutine RD_ADC to read the value from the A/D Converter
(3) Take the value and use it in the equation R=(2914/(V+5) - 1 to find the range value.
The resulting number is a whole number, unit in centimeters, and is stored in the variable
R.
(4) Display the measured range value on the Debug Terminal window, both the raw
value that was measured and the value in centimeters after the conversion.
A13.2 Turn on the power switch of the robot. Hold the robot
near the wall, with the side that has the GP2D120 module
installed facing the wall. Observe the range value that appears
on the Debug Terminal window.
A13.3 Use a ruler to measure the distance from the robot to the
wall and compare it to the value shown on the Debug Terminal
window.
A13.4 Test at different ranges to see if the actual distance and
the range on the Debug Terminal window is the same. Notice
the range from Module GP2D120 starts being inaccurate.
40
Modifications:
From Listing A13-1, it is seen that the
value read often changes or shifts
from the actual value. Therefore,
modifications to the Listing A13-1 are
made to find the average after
reading the value several times, as
seen in Listing A13-2. Repeat the test
again from steps A13-1 to A13-4.
Compare the results.
Figure A13-1: The Debug Terminal window
displays the value read from Module GP2D120
from Program A13-2
'{$STAMP BS2sx}
'{$PBASIC 2.5}
ADC VAR
Word
R
VAR
Word
I
VAR
Byte
X
VAR
Word
PAUSE 1000
HIGH 10
DO
X = 0
FOR I = 1 TO 5
GOSUB RD_ADC
X = (ADC+X)
NEXT
X = X/5
R = (2914 /(X+5))-1
Listing A13-2
' Initial ADC
' Mean Off ADC 5 Time
' Convert voltage to distance(CM)
' Show Range On Debug Terminal
DEBUG "ADC = ",DEC X,TAB, "Range = ",DEC R ,"
PAUSE 200
LOOP
CM" ,CR
' Read Again
RD_ADC: LOW 10: PAUSE 1: HIGH 10
' Send Acknowledge
SEROUT 10,240,[1]
' Select channel
SERIN 10,240,250,Error,[ADC.BYTE0,ADC.BYTE1] ' Read ADC
RETURN
Error:
DEBUG "Error Reading",CR
RETURN
How the program works:
This program uses the FOR...NEXT command to loop back 5 times to read the data
value from the GP2D120. Then the values will be divided by 5 to find a more stable value.
In addition, this program also adds a check line in the subroutine RD_ADC by adding a
parameter in the SERIN command to check the time data is received. If no data is sent by
the QP410 IC within 0.1 seconds, the program will go back to the main program. This is to
prevent the program from remaining at the SERIN command awaiting data.
41
Activity #14 Detecting Obstacles with no contact
In the previous activity, an obstacle would be detected when
the switch made contact with the obstacle. The robot would
then change its route. However, with the GP2D120 module, the
iZEBOT robot no longer has to touch the obstacle. It only has to
measure the range to see if the distance of the obstacle is closer
than the specified range or not. Then the robot will move
backward and change directions immediately.
A14.1 Type in Listing A14-1 and download it into the iZEBOT robot.
Turn off the switch and remove the download cable.
'{$STAMP BS2sx}
'{$PBASIC 2.5}
ADC VAR
Word
R
VAR
Word
I
VAR
Byte
X
VAR
Word
PAUSE 1000
HIGH 10
DO
GOSUB Forward
GOSUB RD_ADC
IF (ADC > 300) THEN
GOSUB Backward : PAUSE 1000
GOSUB S_Left : PAUSE 400
ENDIF
LOOP
Listing A14-1
' Initial ADC
' Distance less than 8 CM ?
' Yes, backward and spin left
' Read again
'+++++ Analog to Digital Converter Procedure ++++++++++
RD_ADC: LOW 10: PAUSE 2: HIGH 10
' Send acknowledge
SEROUT 10,240,[1]
' Select channel
SERIN 10,240,250,Error,[ADC.BYTE0,ADC.BYTE1] ' Read ADC
RETURN
Error: DEBUG "Error Reading",CR
RETURN
'+++++ Movement Procedure +++++++++++++++++++++++++++++
Forward: HIGH 13 : LOW 12 : HIGH 15 : LOW 14 : RETURN
Backward: HIGH 12 : LOW 13 : HIGH 14 : LOW 15 : RETURN
T_Left:
HIGH 13 : LOW 12 : LOW 15 : LOW 14 : RETURN
T_Right: LOW 13 : LOW 12 : HIGH 15 : LOW 14 : RETURN
S_Left:
HIGH 13 : LOW 12 : HIGH 14 : LOW 15 : RETURN
S_Right: HIGH 12 : LOW 13 : HIGH 15 : LOW 14 : RETURN
Motor_OFF: LOW 13 : LOW 12 : LOW 15 : LOW 14 : RETURN
'++++++++++++++++++++++++++++++++++++++++++++++++++++++
42
How the Program Works:
Listing A14-1 will read the value from Module GP2D120 to see if it is more than 300 or
not. The value 300 in this place is the value received from the A/D converter when this
value is converted to voltage using the following equation:
Voltage = (Raw data x Maximum voltage) / Full scale data
Voltage = (300 x 5)/1023 = 1.47 V
Take the voltage and compare it to the module GP2D120 graph. You will get a range of
8.5 centimeters. Therefore, when the robot is closer than 8.5 centimeters to the wall, the
IF...THEN conditions in the program will be true and the program will command the robot
to change directions to avoid the obstacle.
A14.2 Prepare the test area by placing obstacles in specific
places of your choice. Place the iZEBOT robot on the floor and
turn on the power switch. Observe the robot.
The robot will operate as shown in the picture.
< 8.5 «Á.
1
2
3
4
43
iZEBOT
Precision Movement
with Encoder
Robo-Stamp 2.0 Smart Robot kit
Increase the accuracy in movement to the
iZEBOT robot by detecting the wheel code in
order to accurately specify the range of
movement without depending on the power
supplied to the robot’s motor.
Activity #15 Installing the IR Reflector Sensor to
detect the Wheel encoding code
A15.1 Place a 3 x 10mm. machine screw into the ZX-03Q IR
Reflector followed by the 3mm. plastic spacer. Then place an
angled joiner at the back and screw it in altogether with a 3mm.
nut as shown in picture.
A15.2 Take the ZX-03Q from A15-1 and attach it to the body
plate of the iZEBOT robot next to the left and right wheel Use a
3 x 10mm. machine screw and 3mm. nut to screw it in tightly.
44
A15.3 In installing the ZX-03Q, the distance between the ZX-03Q
and the wheel code must be approximately 2 mm. for accurate
measurement.
2mm.
ZX-03Q
Wheel
A15.4 Connect the signal cable of the ZX-03Q near the left wheel
to connection point ANALOG3 and the right wheel to ANALOG5
of the Stamp-BOX. Hardware preparations for counting the range
of movement for the iZEBOT robot are finished.
ZX-03Q IR Reflector sensor
QRD1114 Infrared
reflector detector
How sensor work :
An infrared LED in the sensor will continually receive voltage
from a +V power supply. A 510 Ω resistor is connected to limit
electric current.
The infrared receiver uses a phototransistor in a parallel line
with a 10 kΩ resistor.
Signal output
+V
OUT
GND
34,"
10k
510
If the phototransistor does not receive any infrared light, it
will not induce any current. Therefore the OUT terminal will have
approximately 0V voltage. The value read from input channel
ANALOG on the Stamp-BOX will also be approximately 0.
The amount of electric current that flows through the circuit
once the phototransistor receives infrared light depends on the
intensity of the light, which varies according to the reflection
distance. The QRD1114 IR Reflector sensor can be used for a
distance of 0.1 to 1.5 centimeters. The terminal OUT will have a
voltage ranging from 0.5 to 5V. The value read from the StampBOX via the input ANALOG will be from 100 to 1,023.
45
Activity #16 Reflection and Non-Reflection Test
The wheel of the iZEBOT robot has 8 oval-shaped holes. Therefore,
when the ZX-03Q is installed next to it, two types of status can
occur when the wheels turn.
Status 1: occurs when the ZX-03Q finds the dark position
of the wheel. The sensor would be able to detect the infrared
light and the data value that the Stamp-BOX reads will be high.
Status 2: occurs when the ZX-03Q finds the oval-shaped
hole and therefore cannot detect the infrared light. The data
value that the Stamp-BOX reads will be low.
Test both statuses by using Program A16-1 to display the results
of the reflection on the Debug Terminal window
A16.1 Type in Listing A16-1 and download it to the iZEBOT robot.
Do not remove the download cable yet.
'{$STAMP BS2sx}
'{$PBASIC 2.5}
ADC VAR
Word
CH
VAR
Byte
DO
CH = 3
GOSUB RD_ADC
DEBUG CLS,"LEFT SENSOR = ", DEC ADC , TAB
CH = 5
GOSUB RD_ADC
DEBUG "RIGHT SENSOR = ", DEC ADC , TAB
PAUSE 300
LOOP
Listing A16-1
'
'
'
'
'
'
'
Select ANALOG3
Read data from ADC
Show data on Debug Terminal
Select ANALOG5
Read data from ADC
Show data on Debug Terminal
Delay 0.3 second
'+++++ Analog to Digital Converter Procedure ++++++++++
RD_ADC: LOW 10: PAUSE 2: HIGH 10
' Send acknowledge
SEROUT 10,240,[CH]
' Select channel
SERIN 10,240,250,Error,[ADC.BYTE0,ADC.BYTE1] ' Read ADC
RETURN
Error: DEBUG "Error Reading",CR
RETURN
A16.2 After the download is complete, the Debug Terminal
window will appear. Test by spinning the wheel and observe
the value that appears on the Debug Terminal window. Record
the value read when a dark area is sensed and when the ovalshaped hole is sensed.
A16.3 Compare the values received from the left wheel and
the right wheel if they are similar.
46
l For dark areas, the value read should be between
200 to 300
l For oval-shaped holes, the value read should be
between 10 to 50
Figure A16-1 Debug Terminal shows ZX-03Q reading from the encoder wheel
Activity #17 Movement along Defined distance
In the previous activity, the movement range of the iZEBOT robot
was determined by the time value of power supplied to the
motor. If the battery is full, the motor will run at full speed, and
the robot will move a certain distance. However, if the battery
is half full, the motor will run slower and thus the robot will move
a shorter distance in the same time period. Therefore, the
distance traveled by the robot will not be the same if time value
is used to determine the robot’s range of movement.
When the ZX-03Q IR Reflector Sensor is attached to the wheel of
the robot, we can count the number of changes that occur
from the oval-shaped holes on the wheel. This value can be used
to find the movement range of the iZEBOT robot, making it easier
to determine the iZEBOT’s exact distance more accurately.
A17.1 Type in Listing A17-1 and download it into the iZEBOT robot.
Turn off the switch. Do not remove the download cable yet.
A17.2 Hold the robot and turn on the power switch. Observe
how the wheel turns and the value that appears on the Debug
Terminal window.
Once the wheel turns 1 round and the value that
appears on the Debug Terminal screen reaches 20, the
wheel of the robot will stop spinning.
47
'{$STAMP BS2sx}
'{$PBASIC 2.5}
ADC VAR
Word
CH
VAR
Byte
CNT VAR
Byte
CNT = 0
PAUSE 1000
GOSUB Forward
DO
CH = 3 : GOSUB RD_ADC
IF (ADC < 100) THEN
DO
CH = 3 : GOSUB RD_ADC
LOOP UNTIL (ADC > 100)
CNT = CNT + 1
DEBUG DEC CNT
ENDIF
LOOP UNTIL (CNT > 19)
GOSUB Motor_OFF
STOP
Listing A17-1
' Clear counter
' Robot move forward
' Read position first time
' Check hold or reflect
' If Hold,
' Wait until reflect
' Increment counter
' Show counter on Debug terminal
' Check counter more than 19 ?
' If yes, stop robot
' Stop program
'+++++ Analog to Digital Converter Procedure ++++++++++
RD_ADC: LOW 10: PAUSE 2: HIGH 10
' Send acknowledge
SEROUT 10,240,[CH]
' Select channel
SERIN 10,240,250,Error,[ADC.BYTE0,ADC.BYTE1] ' Read ADC
RETURN
Error: DEBUG "Error Reading",CR
RETURN
'+++++ Movement Procedure +++++++++++++++++++++++++++++
Forward: HIGH 13 : LOW 12 : HIGH 15 : LOW 14 : RETURN
Backward: HIGH 12 : LOW 13 : HIGH 14 : LOW 15 : RETURN
T_Left:
HIGH 13 : LOW 12 : LOW 15 : LOW 14 : RETURN
T_Right: LOW 13 : LOW 12 : HIGH 15 : LOW 14 : RETURN
S_Left:
HIGH 13 : LOW 12 : HIGH 14 : LOW 15 : RETURN
S_Right: HIGH 12 : LOW 13 : HIGH 15 : LOW 14 : RETURN
Motor_OFF: LOW 13 : LOW 12 : LOW 15 : LOW 14 : RETURN
'++++++++++++++++++++++++++++++++++++++++++++++++++++++
How the Program Works
The program can be separated into the following steps:
(1) Create a variable called CNT to count the movements. The start value is defined at 0 and
ready to start counting.
(2) Command the robot to move forward. The wheel of the iZEBOT robot turns and is ready to
start counting.
(3) Read the value from the ZX-03Q sensor whether it is less than 100 or not. This is to find the
position of the oval-shaped holes on the robot wheel.
(4) When found, the program is ordered to wait until the value read is more than 100. This
means that the wheel is now turned to the dark area.
(5) Add 1 to the variable CNT. This means that 1 oval-shaped hole of the wheel has been
counted. The wheel has 8 oval-shaped holes. Therefore, when CNT counts to 8, it means that the
wheel has turned 1 round.
(6) Display the value from the count on the Debug Terminal window and order the motor to
stop running when the value is more than 19.
48
Accurate Movement by Calculation
From the circumference formula
Thus
circumference = πD
π is approximately 3.14
D is the diameter of a circle. Here, the diameter of the
wheel is 7 cm.
Therefore, the distance when the robot turns 1 round is
3.14 x 7 = 21.98 or 22 cm.
There are 8 oval-shaped holes on the wheel, with each space
being 2.75 cm apart.
From Program A17-1, the program will stop when the counter
exceeds 19, in which it counted 20 oval-shaped holes. Therefore,
the robot moved a distance of 2.75 x 20 = 55 cm
A17.3 Edit Program A17-1 to delete the command line
DEBUG DEC CNT ‘ show counter on debug terminal
Download the program onto the iZEBOT robot again. Turn
off the switch and remove the download cable.
A17.4 Place the iZEBOT robot on the floor. Then turn on the power
switch for the robot to start.
A17.5 Use a ruler to measure the distance from the starting point
to where the iZEBOT robot stopped to see if the distance is the
same as what was calculated.
The robot exceeds the calculated 55 cm by 4-5 cm
due to low friction which causes the robot to move forward
a certain distance even though the motor already stopped
running.
Modifications for more accuracy
From the problem that occurred in A17.5, the program must be
edited to order the robot to stop moving instantaneously. The
easiest way is to command the motor to spin in the reverse
direction for a short period. This can be done with the following
program:
GOSUB Backward : PAUSE 100 ' Brake motor
49
Insert this line in the program, before the command to stop the
motor, as following:
GOSUB Motor_OFF
' Yes, Stop robot
GOSUB Backward : PAUSE 100 ' Brake motor
STOP
' Stop program
A17.6 Download the program to the iZEBOT robot again. Turn
off the switch and remove the download cable. Place the robot
on the floor and turn on the power switch. Observe the robot
and measure the distance to see if it is more accurate
Turning 90 Degrees
From the equation used to calculate the circumference, it can
also be used to find the circumference of making a turn as
following
Since the turn of the iZEBOT robot is a 90 degree turn, only one
wheel will turn. The rotating point is the wheel that stands still.
Thus, the radius of the turn is the distance between the two
wheels.
Measuring the distance between the two wheels will give a
distance of 9 cm. Using it in the circumference equation, the
distance of a 90 degree turn is:
R = (2πr) / 4
R is the radius that equals 9 cm
Substitute the values,
Distance = (2 x 3.14 x 9) / 4 =14.13 cm
Rotating point
50
However, counting the range of movement of the iZEBOT robot
is done by counting the number of oval-shaped holes on the
wheel. The distance of each oval-shaped hole was calculated
as 2.75 cm per space. Therefore, a 90 degree turn would be
approximately 14.13/2.75 = 5.14 or 5 oval-shaped holes.
Robo-Stamp Note (3)
Test by using the values from this calculation. Edit the Listing
A17.1 in line
Through calculation it
was found that the
distance between the
oval-shaped holes on
the wheels of the
iZEBOT robot is 2.75
cm.
LOOP UNTIL (CNT > 19) ' Check counter more than 19 ?
to
LOOP UNTIL (CNT > 6)
' Check Counter More Than 6 ?
A17.7 Download the program and test again. Check to see
whether the robot can make a 90 degree turn or not.
Limitations
in
Accurate Distance
Counting
Therefore, in each
count, there is a
chance that the robot
will have a ±1.375
error. If the number of
holes is increased, the
possibility of errors will
decrease.
51
.
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertisement