Professional Documents
Culture Documents
KS0488-X Keyestudio 4DOF Robot Arm Arduino Learning Kit
KS0488-X Keyestudio 4DOF Robot Arm Arduino Learning Kit
com
Content
1. Introduction .............................................................................................. 3
2. Features ................................................................................................... 4
1
www.keyestudio.com
2
www.keyestudio.com
1. Introduction
On the Internet, we often see DIY robotic arms performing various actions.
Do you want to have one? I believe that you are bound to build your own robotic
This kit includes a Arduino single-chip microcomputer, two joystick modules and
four servos and so on. Next, we’ll teach you how to install and debug a robotic
arm.
First, we can make a wired home-made joystick controller (included in the kit);
secondly, the App control is adapted; thirdly, it makes sense to use a wireless PS2
Note: You must connect a DC 7-15V power to VIN port of shield when
3
www.keyestudio.com
2. Features
joystick control.
3. Specification
VIN current: 5A
Size: 73 * 53.34mm
2-channel 5V output: 5V / 3A
PS2 interface: compatible with Sony PS2 receiver, can be plugged directly into the
shield.
4
www.keyestudio.com
3.Component List
2 USB Cable 1
5
www.keyestudio.com
6 BT-24 Module 1
7 Robotic Arm 1
8 1 Set
MEARM 3pcs Acrylic Boards
Galvanized M2+M3
9 1
Double end Wrench
M3*10MM Round
11 3
Head Screws
M2*8MM Round
12 3
Head Screws
6
www.keyestudio.com
Male to Female
18 25
10CM/40P/2.54 24 Dupont Wire
Female to Female
19 5
50CM/40P/2.54 Dupont Wire
7
www.keyestudio.com
If this is your first experience tinkering with the platform, the Arduino board is the
8
www.keyestudio.com
9
www.keyestudio.com
Digital I/O
Keyestudio Arduino (Black) Main Control Board has 14 digital input/output
pins (of which 6 can be used as PWM outputs). These pins can be
configured as digital input pin to read the logic value (0 or 1). Or used as
digital output pin to drive different modules like LED, relay, etc. The pin
labeled “〜” can be used to generate PWM.
AREF
Reference voltage (0-5V) for analog inputs. Used with analogReference().
SDA
IIC communication pin
SCL
IIC communication pin
RESET Button
You can reset your Keyestudio Arduino (Black) Main Control Board, for
example, start the program from the initial status. You can use the RESET
button.
D13 LED
There is a built-in LED driven by digital pin 13. When the pin is HIGH value,
the LED is on, when the pin is LOW, it's off.
10
www.keyestudio.com
USB Connection
Keyestudio Arduino (Black) Main Control Board can be powered via USB
connector. All you needed to do is connecting the USB port to PC using a
USB cable.
ATMEGA 16U2-MU
USB to serial chip, can convert the USB signal into serial port signal.
TX LED
Onboard you can find the label: TX (transmit)
When Keyestudio Arduino (Black) Main Control Board communicates via
serial port, send the message, TX led flashes.
RX LED
Onboard you can find the label: RX(receive )
When Keyestudio Arduino (Black) Main Control Board communicates via
serial port, receive the message, RX led flashes.
Crystal Oscillator
How does Arduino calculate time? by using a crystal oscillator.
The number printed on the top of the Arduino crystal is 16.000H9H. It tells
us that the frequency is 16,000,000 Hertz or 16MHz.
Voltage Regulator
Convert an external input DC7-12V voltage into DC 5V, then switch DC 5V
to the processor and other components. Output DC 5V, the drive current is
2A.
DC Power Jack
Keyestudio Arduino (Black) Main Control Board can be supplied with an
external power DC7-12V from the DC power jack.
11
www.keyestudio.com
IOREF
Used to configure the operating voltage of microcontrollers. Use it less.
RESET Header
Connect an external button to reset the board. The function is the same as
reset button (labeled 9)
Power Pin 5V
Provides 5V output voltage
Vin
You can supply an external power input DC7-12V through this pin to
Keyestudio Arduino (Black) Main Control Board.
Analog Pins
Keyestudio Arduino(Black) Main Control Board has 6 analog inputs, labeled
A0 through A5.
These pins can read the signal from analog sensors (such as humidity
sensor or temperature sensor), and convert it into the digital value that
can read by microcontrollers)
Can also used as digital pins, A0=D14, A1=D15, A2=D16, A3=D17,
A4=D18, A5=D19.
12
www.keyestudio.com
Microcontroller
Each Keyestudio Arduino(Black) Main Control Board has its own
microcontroller. You can regard it as the brain of your board.
The main IC (integrated circuit) on the Arduino is slightly different from the
panel pair. Microcontrollers are usually from ATMEL. Before you load a new
program on the Arduino IDE, you must know what IC is on your board.
This information can be checked at the top of IC.
13
www.keyestudio.com
In this software page, on the right side you can see the version of development
You could download the software that is compatible with the operating system of
your computer.
We will take WINDOWS system as an example here. There are also two options
under Windows system, one is installed version, the other is non-installed version.
For installed version, download file and directly click “Install”. For non-installed
version, we need to download file on PC, unzip the file, and then open ARDUINO
1. Installing Driver
There are some small differences for installing driver on different computer
systems. Next, we introduce the method of installing the driver in the WIN 7
system. Firstly connect the Arduino development board to the computer, click on
14
www.keyestudio.com
15
www.keyestudio.com
Click "Next" and "Install this driver software anyway" t to start installing driver .
17
www.keyestudio.com
18
www.keyestudio.com
In the previous lesson, we successfully installed the driver for the Arduino
development board. In this lesson, let's learn how to use the Arduino IDE
19
www.keyestudio.com
20
www.keyestudio.com
21
www.keyestudio.com
22
www.keyestudio.com
Select the serial device of the Arduino board. Go to the Tools→Serial Port menu.
Computer--Property-Device Manager.
23
www.keyestudio.com
24
www.keyestudio.com
Before explaining how to upload our program to the board, we demonstrate the
F - for receiving serial data from the board and sending serial data to the board
of serial monitor
25
www.keyestudio.com
Name 0° 180°
rightmost leftmost
2 stretches out
3 draws back
Pin Control
Name IO Pin
Right Joystick X A2
Right Joystick Y A5
Left Joystick X A3
26
www.keyestudio.com
Left Joystick Y A4
Left Joystick Z 6
D1/DAT of PS2 12
D0/CMD of PS2 11
CE/SEL of PS2 10
CLK of PS2 13
1) Servo Control
Description
Here we control the angle of a single servo with servo library file.
The test result is same. Before using it, we need to put the servo folder in
the folder where the Arduino IDE is installed, and then open the Arduino ID
E, the library file will take effect.
Connection Diagram
27
www.keyestudio.com
Test Code
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup()
{
Serial.begin(9600);
delay(1000);
}
void loop()
{
myservo.attach(A0); // modify each pin to adjust
myservo.write(0); // angle value
delay(1000);
28
www.keyestudio.com
Test Result
Stack the driver shield on the Arduino board, upload the code, and wire according
to connection diagram. After powering on, press the reset button, the servo will
2) Rotating Automatically
Description
In the previous lesson, we set the angle for a single servo. In fact, we only need
to continuously change the angles of the 4 servos to enable the 4 DOF robotic
Connection Diagram
29
www.keyestudio.com
Test Code
#include <Servo.h>
Servo myservo2;
Servo myservo3;
Servo myservo4;
void setup()
30
www.keyestudio.com
myservo2.attach(A0);
myservo3.attach(8);
myservo4.attach(9);
myservo1.write(pos1);
delay(1000);
myservo2.write(pos2);
myservo3.write(pos3);
myservo4.write(pos4);
delay(1500);
void loop()
// turn right
for(pos1;pos1>0;pos1--)
myservo1.write(pos1);
31
www.keyestudio.com
delay(1000);
for(pos4;pos4<100;pos4++)
myservo4.write(pos4);
delay(1000);
for(pos2;pos2<100;pos2++)
myservo2.write(pos2);
delay(5);
for(pos3;pos3<180;pos3++)
myservo3.write(pos3);
delay(5);
delay(1500);
32
www.keyestudio.com
for(pos4;pos4>0;pos4--)
myservo4.write(pos4);
delay(1000);
for(pos3;pos3>120;pos3--)
myservo3.write(pos3);
delay(5);
delay(1000);
// turn to left
for(pos1;pos1<180;pos1++)
myservo1.write(pos1);
delay(5);
33
www.keyestudio.com
delay(1000);
for(pos3;pos3<180;pos3++)
myservo3.write(pos3);
delay(5);
delay(1000);
for(pos4;pos4<100;pos4++)
myservo4.write(pos4);
delay(1000);
for(pos3;pos3>120;pos3--)
myservo3.write(pos3);
delay(5);
34
www.keyestudio.com
delay(1000);
for(pos4;pos4>0;pos4--)
myservo4.write(pos4);
delay(1000);
Test Result
Stack the driver shield on the Arduino board, upload the code, and wire according to
connection diagram. After powering on, press the reset button, the DOF robot arm
realizes a cyclical movement: turn to the right, the paw releases, arm is stretched out,
lower down and the paw closes, then the robot arm is retracted and raised; turn to the
left, the robot arm is stretched out, lower down, claw releases, robotic arm is retracted
and raised, claw closes, and then return to the right to continue to repeat the motion.
Description
The sensor’s pin X, Y are for analog sensor, so directly read the measured analog
value. Pin Z is a digital button, first should set the pin to Input status and then
35
www.keyestudio.com
read the measured value 1 (pressed down) or 0 (not press). Check out the value
printed on the serial monitor.
Connection Diagram
Test Code
const int right_key = 7; //define the right key pin to 7(that is the value Z)
36
www.keyestudio.com
const int left_key = 6; //define the left key pin to 8(that is the value Z)
void setup()
pinMode(left_key, INPUT);
void loop()
int x1,y1,z1; // define the variable, used to save the joystick value it reads
int x2,y2,z2;
37
www.keyestudio.com
//Serial.println("**********right**********");
Serial.print(x1 ,DEC); // print out the value of right X and line wrap
Serial.print(" ");
Serial.print("right_Y = ");
Serial.print(y1 ,DEC);
Serial.print(" ");
Serial.print("right_key = ");
Serial.print(z1 ,DEC);
//Serial.println("*********left***********");
Serial.print("left_X = ");
Serial.print(x2 ,DEC);
Serial.print(" ");
Serial.print("left_Y = ");
Serial.print(y2 ,DEC);
Serial.print(" ");
Serial.print("left_key = ");
Serial.println(z2 ,DEC);
delay(200);
38
www.keyestudio.com
Test Result:
Hook it up and upload well the code. Connect the Arduino control board to
computer using a USB cable, then open the serial monitor and set the baud rate
to 9600, you will see the analog value of the right Joystick pin X,Y, digital signal 1
or 0 of pin Z.
As shown below:
39
www.keyestudio.com
Item Angle
Servo4(Servo of claw) 0°
40
www.keyestudio.com
Accessory 1
Assemble screws and copper posts on this acrylic board.
Install the batter holder to the accessory 1then we get the accessory 2.
41
www.keyestudio.com
42
www.keyestudio.com
Accessory 2
43
www.keyestudio.com
Accessory 2
Mount copper posts on the accessory 2 with screws to form the accessory 3.
44
www.keyestudio.com
Accessory 3
45
www.keyestudio.com
2 pcs M2 nuts
1 pcs 180°servo
1 Acrylic board
First set the servo to 90 °, set the servo’s angle to 90 °, stack the servo motor
Upload the test code to the servo motor driver shield to make the 180°servo
rotate 90°via Arduino software. When setting the servo angle, connect the servo
to the A0 end of the shield(there is a silk screen on the back of the shield), upload
46
www.keyestudio.com
the corresponding code, plug in power and press the reset button. Then the servo
void setup()
delay(20-pulsewidth/1000);
47
www.keyestudio.com
void loop()
// servopulse(servopin,0);
// servopulse(servopin,90);
// servopulse(servopin,180);
48
www.keyestudio.com
Remove the servo, then install it on the acrylic board with 2 pcs M2*8MM
round head screws and 2 pcs M2 nuts. Finally, we get the accessory 4.
49
www.keyestudio.com
Accessory 4
(5) Assemble the accessory 4 onto the accessory 3 with 4pcs M3 * 6MM round
50
www.keyestudio.com
Accessory 5
51
www.keyestudio.com
accessory 19
Fix the accessory 5 and the accessory 19 together with 1 pcs M2 * 5 screw. Then
52
www.keyestudio.com
53
www.keyestudio.com
Accessory 20
Next, we need to use 8pcs M3*6MM round-head screws and 4pcs M3*10MM
dual-pass hex coppers pillars to install the Arduino control board onto the
accessory 20 and stack the servo motor driver shield onto the control board.
54
www.keyestudio.com
55
www.keyestudio.com
Accessory 21
Then we interface the servo with the corresponding ports of servo motor driver
shield. The wiring method is shown below, and the accessory 22 is generated.
56
www.keyestudio.com
The brown wire of the servo1 (Base Servo) is connected to G, the red wire
The brown wire of the servo 2(left) is interfaced to G,the red wire to V and
58
www.keyestudio.com
The brown wire of the Servo 3(right))is interfaced with G,the red
59
www.keyestudio.com
Interface the brown wire of servo 4 with G, the red one with V and the
60
www.keyestudio.com
Accessory 22
61
www.keyestudio.com
Accessory 23
62
www.keyestudio.com
On the driver shield, pin G and V of joystick modules are separately connected
to G,V;
Pin X (X axis), Y (Y axis) and B(Z axis) of the right joystick module are
Pin X, Y and B of the left joystick module are separately connected to S (A3), S
63
www.keyestudio.com
64
www.keyestudio.com
65
www.keyestudio.com
Description:
In the previous section, we have introduced how to use 4 Servos to control the
robot arm. Next, combine those two experiments. Use two Joystick modules to
control 4DOF robot arm in a way that realizes different motions.
At first, set the boot posture. The Joystick control is shown as below table.
66
www.keyestudio.com
Right Left
Servo Servo
Joystick Joystick
X1<50 right, the servo that controls the X2<50 the left joystick to
arm rotation turns right, and stops the right, the claw
at 0° ) is closes)
X1>1000 the servo that controls the arm X2>1000 (push the left
Servo2 gradually
reduces to 35°
Servo 3 gradually increases to 180°
( that is, left
Y1>1000 ( that is, right joystick stretches Y2>1000
joystick stretches
out, the upper arm stretches out)
out and the lower
67
www.keyestudio.com
joystick draws
decrease)
Connection Diagram
68
www.keyestudio.com
Test Code
Servo myservo2;
Servo myservo3;
Servo myservo4;
angle,and assign the initial value (that is the boot posture angle value)
69
www.keyestudio.com
const int right_key = 7; // define the right key to 7(the value of Z axis)
const int left_key = 6; // define the left key to 6(the value of Z axis)
int x2,y2,z2;
void setup()
//start up posture
myservo1.write(pos1);
delay(1000);
myservo2.write(pos2);
myservo3.write(pos3);
myservo4.write(pos4);
delay(1500);
70
www.keyestudio.com
pinMode(left_key, INPUT);
void loop()
//Serial.println("**********right**********");
71
www.keyestudio.com
//Serial.print(x1 ,DEC); // print out the value of right X and line wrap
//Serial.print(" ");
//Serial.print("right_Y = ");
//Serial.print(y1 ,DEC);
//Serial.print(" ");
//Serial.print("right_key = ");
//Serial.print(z1 ,DEC);
//Serial.println("*********left***********");
//Serial.print("left_X = ");
//Serial.print(x2 ,DEC);
//Serial.print(" ");
//Serial.print("left_Y = ");
//Serial.print(y2 ,DEC);
//Serial.print(" ");
//Serial.print("left_key = ");
//Serial.println(z2 ,DEC);
//clamp claw
zhuazi();
//rotate
zhuandong();
72
www.keyestudio.com
//Right Servo
right_ser();
//Left Servo
left_ser();
//Claw
void zhuazi()
//Claw
//Serial.println(pos4);
closes
delay(5);
73
www.keyestudio.com
//Serial.println(pos4);
opens.
delay(5);
pos4=110;
//******************************************************
//rotate
void zhuandong()
74
www.keyestudio.com
right.
delay(5);
pos1=1;
delay(5);
pos1=180;
75
www.keyestudio.com
//**********************************************************/
//Right Servo
void right_ser()
pos3=pos3-1;
delay(5);
pos3=0;
pos3=pos3+1;
delay(5);
pos3=180;
76
www.keyestudio.com
//*************************************************************/
//Left Servo
void left_ser()
pos2=pos2+1;
delay(5);
pos2=180;
pos2=pos2-1;
77
www.keyestudio.com
delay(5);
pos2=35;
Test Result
Upload code to the main control board, stack the shield on the main control
board, and wire according to connection diagram. After powering on, the 4 DOF
robot arm is in the initial position. Shake the two joysticks to control the 4 DOF
Description
In the previous section, use the analog value of pin X,Y of 2 Joystick modules to
78
www.keyestudio.com
Connection Diagram
79
www.keyestudio.com
Test Code
Servo myservo2;
Servo myservo3;
Servo myservo4;
angle and assign the initial value( that is the boot posture angle value)
const int right_key = 7; //define the pin of right key to 7(the value of Z)
const int left_key = 6; //define the pin of right key to 6(the value of Z)
int x1,y1,z1; //define variable for storing the read value of Joystick
int x2,y2,z2;
void setup()
//posture of boot-up
myservo1.write(pos1);
delay(1000);
myservo2.write(pos2);
myservo3.write(pos3);
81
www.keyestudio.com
myservo4.write(pos4);
delay(1500);
pinMode(left_key, INPUT);
void loop()
82
www.keyestudio.com
s2=myservo2.read();
s3=myservo3.read();
s4=myservo4.read();
delay(10);
if(z2==1)
pos2=myservo2.read();
pos3=myservo3.read();
pos4=myservo4.read();
83
www.keyestudio.com
else //if angle of servo 1 is greater than the value stored in array 1.
servo
//*************************************************
84
www.keyestudio.com
if(pos2<s2)
while(pos2<s2)
myservo2.write(pos2);
pos2++;
delay(5);
else
while(pos2>s2)
myservo2.write(pos2);
pos2--;
delay(5);
//*************************************************
if(pos3<s3)
85
www.keyestudio.com
while(pos3<s3)
myservo3.write(pos3);
pos3++;
delay(5);
else
while(pos3>s3)
myservo3.write(pos3);
pos3--;
delay(5);
//*************************************************
if(pos4<s4)
while(pos4<s4)
86
www.keyestudio.com
myservo4.write(pos4);
pos4++;
delay(5);
else
while(pos4>s4)
myservo4.write(pos4);
pos4--;
delay(5);
//claw
zhuazi();
//rotate
zhuandong();
87
www.keyestudio.com
//right Servo
right_ser();
//left Servo
left_ser();
//claw
void zhuazi()
//claw
//Serial.println(pos4);
closed
delay(5);
88
www.keyestudio.com
//Serial.println(pos4);
opens.
delay(5);
pos4=110;
//******************************************************
//rotate
void zhuandong()
89
www.keyestudio.com
delay(5);
pos1=1;
delay(5);
pos1=180;
//**********************************************************/
90
www.keyestudio.com
//right Servo
void right_ser()
pos3=pos3-1;
delay(5);
pos3=0;
pos3=pos3+1;
delay(5);
pos3=180;
91
www.keyestudio.com
//*************************************************************/
//left Servo
void left_ser()
pos2=pos2+1;
delay(5);
pos2=180;
pos2=pos2-1;
92
www.keyestudio.com
delay(5);
pos2=35;
Test Result
Wire it up, stack the shield onto Arduino, upload the code. Powered on, press the
key Z1 of right Joystick to save the angle value of 4 servos control. Press the key
Z2 of left Joystick to operate a servo posture saved in the variable.
Description
In the previous section, we have set the angle of 4 servos to make the robot arm
remember and operate a posture. To extend the experiment, next make it
remember several postures, at most 10 (you can set it in the code), then make
4DOF robot arm continually operate the posture in memory. That is, make robot
arm memorize a group of actions, and you can set the memorizing speed in the
code.
93
www.keyestudio.com
Connection Diagram
94
www.keyestudio.com
Test Code
Servo myservo2;
Servo myservo3;
Servo myservo4;
angle and assign the initial value( that is the boot posture angle value)
95
www.keyestudio.com
int x1,y1,z1; //define variable for saving the read value of Joystick
int x2,y2,z2;
int s1,s2,s3,s4;
int jiyi2[10]; //(array length is 10,namely can save angle data of 0~10
servo )
int jiyi3[10]; //if need to save more data, just change the number 10 to be
int jiyi4[10];
void setup()
96
www.keyestudio.com
//posture of boot-up
myservo1.write(pos1);
delay(1000);
myservo2.write(pos2);
myservo3.write(pos3);
myservo4.write(pos4);
delay(1500);
pinMode(left_key, INPUT);
void loop()
97
www.keyestudio.com
delay(100);
//Serial.println(s1);
s2=myservo2.read();
delay(100);
//Serial.println(s2);
s3=myservo3.read();
delay(100);
//Serial.println(s3);
s4=myservo4.read();
98
www.keyestudio.com
delay(100);
//Serial.println(s4);
jiyi2[i]=s2;
jiyi3[i]=s3;
jiyi4[i]=s4;
delay(100);
delay(10);
posture
99
www.keyestudio.com
pos2 = myservo2.read();
pos3 = myservo3.read();
pos4 = myservo4.read();
//Serial.println(pos1);
else // if the current Servo 1 angle is greater than the value stored
in array 1.
100
www.keyestudio.com
//Serial.println(pos1);
//*************************************************************
**
if(pos2<jiyi2[k])
while(pos2<jiyi2[k])
myservo2.write(pos2);
delay(5);
pos2++;
//Serial.println(pos1);
101
www.keyestudio.com
else
while(pos2>jiyi2[k])
myservo2.write(pos2);
delay(5);
pos2--;
//Serial.println(pos1);
//*************************************************************
**
if(pos3<jiyi3[k])
while(pos3<jiyi3[k])
myservo3.write(pos3);
delay(5);
pos3++;
102
www.keyestudio.com
//Serial.println(pos1);
else
while(pos3>jiyi3[k])
myservo3.write(pos3);
delay(5);
pos3--;
//Serial.println(pos1);
//*************************************************************
**
if(pos4<jiyi4[k])
while(pos4<jiyi4[k])
103
www.keyestudio.com
myservo4.write(pos4);
delay(5);
pos4++;
//Serial.println(pos1);
else
while(pos4>jiyi4[k])
myservo4.write(pos4);
delay(5);
pos4--;
//Serial.println(pos1);
//claw
zhuazi();
104
www.keyestudio.com
//rotate
zhuandong();
//right Servo
right_ser();
//left Servo
left_ser();
//claw
void zhuazi()
//claw
//Serial.println(pos4);
gradually closed.
delay(5);
105
www.keyestudio.com
pos4=pos4+2; //current angle of servo 4 plus 2(change the value you plus,
//Serial.println(pos4);
opens.
delay(5);
pos4=110;
//******************************************************
106
www.keyestudio.com
//rotate
void zhuandong()
turns right
delay(5);
pos1=1;
delay(5);
pos1=180;
107
www.keyestudio.com
//**********************************************************/
//right Servo
void right_ser()
pos3=pos3-1;
delay(5);
pos3=0;
pos3=pos3+1;
108
www.keyestudio.com
delay(5);
pos3=180;
//*************************************************************/
//left Servo
void left_ser()
pos2=pos2+1;
delay(5);
pos2=180;
109
www.keyestudio.com
pos2=pos2-1;
delay(5);
pos2=35;
Test Result
Wire it up, stack the shield onto Arduino , upload the code. Powered on, press the
key Z1 of right Joystick to save the angle value of 4 servos. Press down the key Z1
to memorize different postures, at most 10 postures in the code. If need to
memorize more postures, you can set it in the code. When memorizing
successfully, press down the key Z2 of left Joystick to make the robot arm carry
out several postures stored successively.
110
www.keyestudio.com
Description
In the previous section, we have introduced how to make 4DOF robot arm to
memorize and perform a group of posture. Furthermore, let’s extend one more
loop function. That is, when robot arm performs all the memorized actions, it will
In the following experiment, press the key Z1, 4DOF robot arm will exit the
looping action. Press the key Z1 again, start to memorize the posture, after that,
Connection Diagram
111
www.keyestudio.com
Test Code
112
www.keyestudio.com
Servo myservo2;
Servo myservo3;
Servo myservo4;
angle and assign the initial value( that is the boot posture angle value)
const int right_key = 7; //define the right key pin to 7(that is Z value)
const int left_key = 6; //define the left key pin to 6(that is Z value)
int x1,y1,z1; //define the variable, used to save the joystick value.
int x2,y2,z2;
int s1,s2,s3,s4;
int jiyi1[20]; //define 4 array, separately used to save the angle of four servo.
int jiyi2[20]; //(array length is 20,namely can save angle data of 0~20 servo)
113
www.keyestudio.com
int jiyi3[20]; //if need to save more data, just change the number 20 to be
int jiyi4[20];
void setup()
// posture of boot-up
delay(1000);
delay(1500);
pinMode(left_key, INPUT);
void loop()
114
www.keyestudio.com
//delay(8); //delay, used to reduce the joystick value read, that is reduce
s1
115
www.keyestudio.com
delay(100);
monitor
s2
delay(100);
//Serial.println(s2);
to s3
delay(100);
//Serial.println(s3);
to s4
delay(100);
//Serial.println(s4);
jiyi2[i]=s2;
jiyi3[i]=s3;
jiyi4[i]=s4;
116
www.keyestudio.com
posture
pos2 = myservo2.read();
pos3 = myservo3.read();
pos4 = myservo4.read();
117
www.keyestudio.com
value
//Serial.println(pos1);
else //if the current servo 1 angle is greater than the value stored
in array 1.
//Serial.println(pos1);
118
www.keyestudio.com
//*************************************************************
**
if(pos2<jiyi2[k])
while(pos2<jiyi2[k])
myservo2.write(pos2);
delay(5);
pos2++;
//Serial.println(pos1);
else
while(pos2>jiyi2[k])
myservo2.write(pos2);
delay(5);
pos2--;
119
www.keyestudio.com
//Serial.println(pos1);
//*********************************************
if(pos3<jiyi3[k])
while(pos3<jiyi3[k])
myservo3.write(pos3);
delay(5);
pos3++;
//Serial.println(pos1);
else
while(pos3>jiyi3[k])
myservo3.write(pos3);
delay(5);
pos3--;
120
www.keyestudio.com
//Serial.println(pos1);
//*********************************************
if(pos4<jiyi4[k])
while(pos4<jiyi4[k])
myservo4.write(pos4);
delay(5);
pos4++;
//Serial.println(pos1);
else
while(pos4>jiyi4[k])
myservo4.write(pos4);
delay(5);
pos4--;
121
www.keyestudio.com
//Serial.println(pos1);
//************************************************************
array to pos
joystick control.
//pos3=jiyi3[(j-1)];
//pos4=jiyi4[(j-1)];
using array
122
www.keyestudio.com
//********************************************************
//claw
zhuazi();
//rotate
zhuandong();
//right Servo
right_ser();
//left Servo
left_ser();
//claw
void zhuazi()
//claw
123
www.keyestudio.com
//Serial.println(pos4);
gradually closed.
delay(5);
//Serial.println(pos4);
opens.
delay(5);
124
www.keyestudio.com
pos4=110;
//******************************************************
//rotate
void zhuandong()
turns right.
delay(5);
pos1=1;
125
www.keyestudio.com
delay(5);
pos1=180;
//**********************************************************/
//right Servo
void right_ser()
pos3=pos3-1;
delay(5);
pos3=0;
126
www.keyestudio.com
pos3=pos3+1;
delay(5);
pos3=180;
//*************************************************************/
//left Servo
void left_ser()
pos2=pos2+1;
127
www.keyestudio.com
delay(5);
pos2=180;
pos2=pos2-1;
delay(5);
pos2=35;
128
www.keyestudio.com
Test Result
Wire it up, stack the shield onto Arduino, upload the code. Powered on, press the
key Z1 of right Joystick to save the angle value of 4 servos. Press down the key Z1
to memorize different postures, at most 10 postures in the code. If need to
memorize more postures, can set it in the code.
When memorizing successfully, press down the key Z2 of left Joystick to make the
robot arm carry out several postures stored successively, looping.
Long press the key Z1, 4DOF robot arm will exit the looping action. Press the key
Z1 again, start to memorize the posture, after that, press the key Z2 to loop the
memorized actions.
and personal area network (UHF radio waves in the ISM band of 2.4-2.485
GHz). The kit is equipped with a bt-24 Bluetooth module, which supports
In the experiment, we default the bt-24 Bluetooth module as the slave and the
Specification
distance communication
standards
Serial port parameters: 9600, 8 data bits, 1 stop bit, invalid bit, no flow
control
Power: 5V DC
130
www.keyestudio.com
Description
Next, we are going to introduce the use method for BT-24 Bluetooth module. To
easily use the BT-24 Bluetooth module to control the robot arm, we particularly
There are 10 control keys on the App. When connect well the bt-24 Bluetooth
module to Android phone using our APP, press the control key, Android phone will
receive a corresponding value.
When programming, you can set the function for the corresponding value. So in
the experiment, we will test each key to get the corresponding value.
131
www.keyestudio.com
https://play.google.com/store/apps/details?id=com.keyestudio.keyes_arm
_123
be connected.
This are operating steps as below, the interface for Android and ios system is
same.
132
www.keyestudio.com
2. Upload code and power on, Led of Bluetooth module blinks. Start Bluetooth
133
www.keyestudio.com
connected.
134
www.keyestudio.com
Special Note: Remove the Bluetooth module please, when uploading the Test
Code. Otherwise, the program will fail to upload. After uploading the Test Code,
135
www.keyestudio.com
Connection Diagram
Test Code
char ble_val;
void setup() {
136
www.keyestudio.com
Serial.begin(9600);
void loop() {
if (Serial.available() > 0)
ble_val = Serial.read();
Serial.println(ble_val);
After connecting Bluetooth module, open serial port monitor to set baud rate
to 9600. Press control keys on App, the serial port prints out the corresponding
137
www.keyestudio.com
Test Result:
: Mode 1
138
www.keyestudio.com
Mode 2 ------------------
Description
We introduced the control method of the 4-DOF robot arm and BT-24 Bluetooth
module. In this experiment, we’ll control 4DOF robotic arm movement via APP.
Note: After uploading test code successfully, unplug the USB data cable and
power up via external power supply and control 4 DOF robot arm movement via
APP.
Connection Diagram
139
www.keyestudio.com
140
www.keyestudio.com
Test Code
Servo myservo2;
Servo myservo3;
Servo myservo4;
char val;
141
www.keyestudio.com
void setup()
//posture of boot-up
myservo1.write(pos1);
myservo2.write(pos2);
myservo3.write(pos3);
myservo4.write(pos4);
delay(1500);
void loop()
142
www.keyestudio.com
Serial.println(val);
switch(val)
//**************************************************
//turn left
void T_left()
pos1=pos1+1;
myservo1.write(pos1);
143
www.keyestudio.com
delay(5);
if(pos1>180)
pos1=180;
//turn right
void T_right()
pos1=pos1-1;
myservo1.write(pos1);
delay(5);
if(pos1<1)
pos1=1;
//********************************************
//claw closes
void arm_close()
pos4=pos4-1;
144
www.keyestudio.com
Serial.println(pos4);
myservo4.write(pos4);
delay(5);
if(pos4<0)
pos4=0;
//claw opens
void arm_open()
pos4=pos4+1;
Serial.println(pos4);
myservo4.write(pos4);
delay(5);
if(pos4>108)
pos4=108;
//******************************************
145
www.keyestudio.com
void left_f()
pos2=pos2-1;
myservo2.write(pos2);
delay(5);
if(pos2<0)
pos2=0;
void left_b()
pos2=pos2+1;
myservo2.write(pos2);
delay(5);
if(pos2>180)
pos2=180;
146
www.keyestudio.com
//***************************************
void right_f()
pos3=pos3+1;
myservo3.write(pos3);
delay(5);
if(pos3>180)
pos3=180;
void right_b()
pos3=pos3-1;
myservo3.write(pos3);
delay(5);
if(pos3<35)
pos3=35;
147
www.keyestudio.com
Test Result
Uploading Test Code,wire and power on, pair Bluetooth successfully. Control
Description
The shield comes with a PS2 Joypad connector which help you control robotic
arm easily. The PS2 Joypad( PS2 receiver)is not included in kit. You need to
purchase it online.
Firstly plug the PS2 receiver into the PS2 interface of the servo driver shield and
then connect the PS2 Joypad. After the PS2 handle is connected well, upload
code to test on Arduino IDE. Before testing, we need to put the PS2X_lib folder in
the libraries folder where the Arduino IDE is installed. After uploading the sample
code of PPS2X_lib folder, open the serial monitor, connect the PS2 Joypad, and
press each button of the PS2 Joypad to view the characters printed on monitor.
148
www.keyestudio.com
Test Code
/**************************************************************
****
* - 1e column: original
* - 2e colmun: Stef?
***************************************************************
***/
/**************************************************************
****
149
www.keyestudio.com
***************************************************************
***/
//right now, the library does NOT support hot pluggable controllers, meaning
//you must always either restart your Arduino after you connect the controller,
int error = 0;
byte type = 0;
byte vibrate = 0;
void setup(){
Serial.begin(57600);
150
www.keyestudio.com
ATTENTION*************
pressures, rumble);
error = ps2x.config_gamepad(13,11,10,12);
if(error == 0){
Serial.print("pressures = ");
if (pressures)
Serial.println("true ");
else
Serial.println("false");
Serial.print("rumble = ");
if (rumble)
Serial.println("true)");
else
151
www.keyestudio.com
Serial.println("false");
Serial.println("Try out all the buttons, X will vibrate the controller, faster as
bugs.");
else if(error == 1)
else if(error == 2)
else if(error == 3)
// Serial.print(ps2x.Analog(1), HEX);
type = ps2x.readType();
152
www.keyestudio.com
switch(type) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
void loop() {
/* You must Read Gamepad to get new values and set vibration values
0-255)
153
www.keyestudio.com
*/
return;
if(ps2x.ButtonPressed(GREEN_FRET))
if(ps2x.ButtonPressed(RED_FRET))
if(ps2x.ButtonPressed(YELLOW_FRET))
if(ps2x.ButtonPressed(BLUE_FRET))
if(ps2x.ButtonPressed(ORANGE_FRET))
if(ps2x.ButtonPressed(STAR_POWER))
154
www.keyestudio.com
pressed
Serial.println("Up Strum");
if(ps2x.Button(DOWN_STRUM))
Serial.println("DOWN Strum");
pressed
if(ps2x.Button(PSB_SELECT))
Serial.println(ps2x.Analog(WHAMMY_BAR), DEC);
pressed
155
www.keyestudio.com
if(ps2x.Button(PSB_SELECT))
pressed
Serial.println(ps2x.Analog(PSAB_PAD_UP), DEC);
if(ps2x.Button(PSB_PAD_RIGHT)){
Serial.println(ps2x.Analog(PSAB_PAD_RIGHT), DEC);
if(ps2x.Button(PSB_PAD_LEFT)){
Serial.println(ps2x.Analog(PSAB_PAD_LEFT), DEC);
if(ps2x.Button(PSB_PAD_DOWN)){
Serial.println(ps2x.Analog(PSAB_PAD_DOWN), DEC);
156
www.keyestudio.com
vibrate speed based on how hard you press the blue (X) button
if(ps2x.Button(PSB_L3))
Serial.println("L3 pressed");
if(ps2x.Button(PSB_R3))
Serial.println("R3 pressed");
if(ps2x.Button(PSB_L2))
Serial.println("L2 pressed");
if(ps2x.Button(PSB_R2))
Serial.println("R2 pressed");
if(ps2x.Button(PSB_TRIANGLE))
Serial.println("Triangle pressed");
157
www.keyestudio.com
either is TRUE
Serial.print("Stick Values:");
Serial.print(",");
Serial.print(ps2x.Analog(PSS_LX), DEC);
Serial.print(",");
Serial.print(ps2x.Analog(PSS_RY), DEC);
Serial.print(",");
Serial.println(ps2x.Analog(PSS_RX), DEC);
delay(50);
Test Result:
Stack the drive shield onto Arduino and upload the code. Connecting the PS2
Joypad, open the serial monitor and set the baud rate to 57600. When press
158
www.keyestudio.com
down the key or push the rocker, you could see the corresponding character
showed on the monitor.
Description:
In the previous section, we have showed how to use Joystick module to control
the robot arm. It is almost the same for you to control the 4DOF robot arm using
the PS2 Joypad.
Connection Diagram
159
www.keyestudio.com
Test Code
#include <PS2X_lib.h>
//right now, the library does NOT support hot pluggable controllers, meaning
//you must always either restart your Arduino after you connect the controller,
int error = 0;
byte vibrate = 0;
Servo myservo2;
Servo myservo3;
Servo myservo4;
angle and assign the initial value( that is the boot posture angle value)
void setup(){
Serial.begin(57600);
// boot posture
myservo1.write(pos1);
delay(1000);
myservo2.write(pos2);
myservo3.write(pos3);
myservo4.write(pos4);
delay(1500);
161
www.keyestudio.com
if(error == 0){
Serial.println("Try out all the buttons, X will vibrate the controller, faster as
else if(error == 1)
else if(error == 2)
//Serial.print(ps2x.Analog(1), HEX);
162
www.keyestudio.com
void loop(){
*/
163
www.keyestudio.com
if(error != 0)
return;
button is pressed
if(ps2x.Button(PSB_SELECT))
is pressed
Serial.println(ps2x.Analog(PSAB_PAD_UP), DEC);
if(ps2x.Button(PSB_PAD_RIGHT)){
Serial.println(ps2x.Analog(PSAB_PAD_RIGHT), DEC);
164
www.keyestudio.com
if(ps2x.Button(PSB_PAD_LEFT)){
Serial.println(ps2x.Analog(PSAB_PAD_LEFT), DEC);
if(ps2x.Button(PSB_PAD_DOWN)){
Serial.println(ps2x.Analog(PSAB_PAD_DOWN), DEC);
if(ps2x.Button(PSB_R3))
Serial.println("R3 pressed");
165
www.keyestudio.com
if(ps2x.Button(PSB_L3))
Serial.println("L3 pressed");
if(ps2x.Button(PSB_L2))
Serial.println("L2 pressed");
if(ps2x.Button(PSB_R2))
Serial.println("R2 pressed");
if(ps2x.Button(PSB_GREEN))
Serial.println("Triangle pressed");
JUST pressed
166
www.keyestudio.com
//rotate
zhuandong();
//clamp claw
zhuazi();
//main arm
dabi();
//forearm
xiaobi();
is TRUE
Serial.print("Stick Values:");
Serial.print(",");
Serial.print(ps2x.Analog(PSS_LX), DEC);
167
www.keyestudio.com
Serial.print(",");
Serial.print(ps2x.Analog(PSS_RY), DEC);
Serial.print(",");
Serial.println(ps2x.Analog(PSS_RX), DEC);
delay(5);
//*************************************************************
*******
// turn
void zhuandong()
//turn right
if(ps2x.Analog (PSS_RX) > 200) // if push the right joystick to the right
//Serial.println(ps2x.Analog(PSS_RX), DEC);
turn right.
// delay(5);
168
www.keyestudio.com
pos1=1;
// turn left
if(ps2x.Analog (PSS_RX) < 50) // if push the right joystick to the left
//Serial.println(ps2x.Analog(PSS_RX), DEC);
// delay(5);
pos1=180;
//*************************************************************
*********
// upper arm
void xiaobi()
169
www.keyestudio.com
pos2=pos2-1;
delay(5);
pos2=0;
pos2=pos2+1;
delay(5);
pos2=180;
170
www.keyestudio.com
//*************************************************************
**
void zhuazi()
pos4=pos4-1;
Serial.println(pos4);
gradually closed.
delay(5);
pos4=0;
171
www.keyestudio.com
pos4=pos4+8;
Serial.println(pos4);
is gradually opened
delay(5);
pos4=108;
//*********************************************************
void dabi()
pos3=pos3+1;
delay(5);
172
www.keyestudio.com
pos3=180;
pos3=pos3-1;
delay(5);
pos3=35;
Test Result:
Stack the shield onto Arduino and upload the code. Powered on and connected
the PS2 Joypad, you can use the PS2 Joypad to control the robot arm actions.
173
www.keyestudio.com
Description:
In the previous experiment, we have showed how to use Joystick module to
control the robot arm memorize several postures. Now we replace the joystick
module with PS2 Joypad. The program thought is almost the same.
Connection Diagram
Test Code
174
www.keyestudio.com
#include <PS2X_lib.h>
Servo myservo2;
Servo myservo3;
Servo myservo4;
angle and assign the initial value( that is the boot posture angle value)
//right now, the library does NOT support hot pluggable controllers, meaning
//you must always either restart your Arduino after you conect the controller,
int error = 0;
byte vibrate = 0;
int s1,s2,s3,s4;
int jiyi1[20]; // define four array, separately used to save the angle of 4
servos.
175
www.keyestudio.com
int jiyi2[20];
int jiyi3[20];
int jiyi4[20];
int i=0;
int j=0;
void setup()
Serial.begin(57600);
// boot posture
myservo1.write(pos1);
delay(1000);
myservo2.write(pos2);
myservo3.write(pos3);
myservo4.write(pos4);
delay(1500);
176
www.keyestudio.com
if(error == 0){
Serial.println("Try out all the buttons, X will vibrate the controller, faster as
else if(error == 1)
else if(error == 2)
//Serial.print(ps2x.Analog(1), HEX);
177
www.keyestudio.com
void loop()
if(error != 0)
return;
button is pressed
if(ps2x.Button(PSB_SELECT))
178
www.keyestudio.com
is pressed
Serial.println(ps2x.Analog(PSAB_PAD_UP), DEC);
if(ps2x.Button(PSB_PAD_RIGHT)){
Serial.println(ps2x.Analog(PSAB_PAD_RIGHT), DEC);
if(ps2x.Button(PSB_PAD_LEFT)){
Serial.println(ps2x.Analog(PSAB_PAD_LEFT), DEC);
if(ps2x.Button(PSB_PAD_DOWN)){
Serial.println(ps2x.Analog(PSAB_PAD_DOWN), DEC);
179
www.keyestudio.com
if(ps2x.Button(PSB_R3))
//Serial.println("R3 pressed");
// record
s1=myservo1.read();
delay(100);
Serial.println(s1);
s2=myservo2.read();
delay(100);
Serial.println(s2);
s3=myservo3.read();
delay(100);
Serial.println(s3);
s4=myservo4.read();
180
www.keyestudio.com
delay(100);
Serial.println(s4);
jiyi2[i]=s2;
jiyi3[i]=s3;
jiyi4[i]=s4;
i++;
j=i;
// delay(100);
Serial.println(i);
if(ps2x.Button(PSB_L3))
//Serial.println("L3 pressed");
i=0;
//perform
pos1 = myservo1.read();
pos2 = myservo2.read();
pos3 = myservo3.read();
pos4 = myservo4.read();
181
www.keyestudio.com
if(pos1<jiyi1[k]) //if the current servo 1 angle is less than the value
stored in array 1.
pos1++;
//Serial.println(pos1);
else //if the current servo 1 angle is greater than the value stored in
array 1.
182
www.keyestudio.com
pos1--;
//Serial.println(pos1);
//**********************************************
if(pos2<jiyi2[k])
while(pos2<jiyi2[k])
myservo2.write(pos2);
delay(5);
pos2++;
//Serial.println(pos1);
else
while(pos2>jiyi2[k])
myservo2.write(pos2);
183
www.keyestudio.com
delay(5);
pos2--;
//Serial.println(pos1);
//*****************************************************
if(pos3<jiyi3[k])
while(pos3<jiyi3[k])
myservo3.write(pos3);
delay(5);
pos3++;
//Serial.println(pos1);
else
while(pos3>jiyi3[k])
myservo3.write(pos3);
184
www.keyestudio.com
delay(5);
pos3--;
//Serial.println(pos1);
//*****************************************************
if(pos4<jiyi4[k])
while(pos4<jiyi4[k])
myservo4.write(pos4);
delay(5);
pos4++;
//Serial.println(pos1);
else
while(pos4>jiyi4[k])
myservo4.write(pos4);
185
www.keyestudio.com
delay(5);
pos4--;
//Serial.println(pos1);
if(ps2x.Button(PSB_L2))
Serial.println("L2 pressed");
if(ps2x.Button(PSB_R2))
Serial.println("R2 pressed");
if(ps2x.Button(PSB_GREEN))
Serial.println("Triangle pressed");
JUST pressed
186
www.keyestudio.com
// turn
zhuandong();
// claw
zhuazi();
// lower arm
dabi();
// upper arm
xiaobi();
is TRUE
187
www.keyestudio.com
Serial.print("Stick Values:");
Serial.print(",");
Serial.print(ps2x.Analog(PSS_LX), DEC);
Serial.print(",");
Serial.print(ps2x.Analog(PSS_RY), DEC);
Serial.print(",");
Serial.println(ps2x.Analog(PSS_RX), DEC);
delay(5);
//*************************************************************
*******
// turn
void zhuandong()
//turn right
if(ps2x.Analog (PSS_RX) > 200) // if push the right joystick to the right
188
www.keyestudio.com
//Serial.println(ps2x.Analog(PSS_RX), DEC);
// delay(5);
pos1=1;
//turn left
if(ps2x.Analog (PSS_RX) < 50) //if push the right joystick to the left
//Serial.println(ps2x.Analog(PSS_RX), DEC);
// delay(5);
pos1=180;
189
www.keyestudio.com
//*************************************************************
*********
// upper arm
void xiaobi()
pos2=pos2-1;
delay(5);
pos2=0;
pos2=pos2+1;
190
www.keyestudio.com
delay(5);
pos2=180;
//*************************************************************
**
void zhuazi()
pos4=pos4-1;
Serial.println(pos4);
gradually closed.
delay(5);
37degrees is closed)
191
www.keyestudio.com
pos4=0;
pos4=pos4+8;
Serial.println(pos4);
is gradually opened
delay(5);
pos4=108;
//*********************************************************
void dabi()
192
www.keyestudio.com
pos3=pos3+1;
delay(5);
pos3=180;
pos3=pos3-1;
delay(5);
pos3=35;
193
www.keyestudio.com
Test Result:
Stack the shield onto Arduino and upload the code. Powered on and connected
the PS2 Joypad, you can use the PS2 Joypad to control the robot arm memorize
several postures.
Description:
In the previous experiment, we have showed how to use Joystick module to
control the robot arm memorize several postures and loop. Now we replace the
Joystick module with the PS2 Joypad. The program is almost the same.
Connection Diagram
194
www.keyestudio.com
Test Code
#include <PS2X_lib.h>
Servo myservo2;
Servo myservo3;
Servo myservo4;
angle and assign the initial value( that is the boot posture angle value)
195
www.keyestudio.com
//right now, the library does NOT support hot pluggable controllers, meaning
//you must always either restart your Arduino after you conect the controller,
int error = 0;
byte vibrate = 0;
int s1,s2,s3,s4;
int jiyi1[30]; //define four array, separately used to save the angle of 4 servos.
int jiyi2[30];
int jiyi3[30];
int jiyi4[30];
int i=0;
int j=0,tt=0;
void setup()
Serial.begin(57600);
// boot posture
myservo1.write(pos1);
196
www.keyestudio.com
delay(1000);
myservo2.write(pos2);
myservo3.write(pos3);
myservo4.write(pos4);
delay(1500);
if(error == 0){
Serial.println("Try out all the buttons, X will vibrate the controller, faster as you
press harder;");
else if(error == 1)
197
www.keyestudio.com
else if(error == 2)
//Serial.print(ps2x.Analog(1), HEX);
the buttons.
void loop()
if(error != 0)
return;
198
www.keyestudio.com
button is pressed
if(ps2x.Button(PSB_SELECT))
pressed
Serial.println(ps2x.Analog(PSAB_PAD_UP), DEC);
if(ps2x.Button(PSB_PAD_RIGHT)){
Serial.println(ps2x.Analog(PSAB_PAD_RIGHT), DEC);
if(ps2x.Button(PSB_PAD_LEFT)){
Serial.println(ps2x.Analog(PSAB_PAD_LEFT), DEC);
199
www.keyestudio.com
if(ps2x.Button(PSB_PAD_DOWN)){
Serial.println(ps2x.Analog(PSAB_PAD_DOWN), DEC);
(X) button
if(ps2x.Button(PSB_R3))
//Serial.println("R3 pressed");
//record
s1=myservo1.read();
delay(100);
Serial.println(s1);
200
www.keyestudio.com
s2=myservo2.read();
delay(100);
Serial.println(s2);
s3=myservo3.read();
delay(100);
Serial.println(s3);
s4=myservo4.read();
delay(100);
Serial.println(s4);
jiyi2[i]=s2;
jiyi3[i]=s3;
jiyi4[i]=s4;
i++;
j=i;
// delay(100);
Serial.println(i);
// carry out
if(ps2x.Button(PSB_L3))
201
www.keyestudio.com
//Serial.println("L3 pressed");
i=0;
tt=1;
pos2 = myservo2.read();
pos3 = myservo3.read();
pos4 = myservo4.read();
stored in array 1.
202
www.keyestudio.com
pos1++;
//Serial.println(pos1);
else //if the current servo 1 angle is greater than the value stored in
array 1.
servo.
pos1--;
//Serial.println(pos1);
//**********************************************
if(pos2<jiyi2[k])
while(pos2<jiyi2[k])
203
www.keyestudio.com
myservo2.write(pos2);
delay(5);
pos2++;
//Serial.println(pos1);
else
while(pos2>jiyi2[k])
myservo2.write(pos2);
delay(5);
pos2--;
//Serial.println(pos1);
//*****************************************************
if(pos3<jiyi3[k])
while(pos3<jiyi3[k])
204
www.keyestudio.com
myservo3.write(pos3);
delay(5);
pos3++;
//Serial.println(pos1);
else
while(pos3>jiyi3[k])
myservo3.write(pos3);
delay(5);
pos3--;
//Serial.println(pos1);
//*****************************************************
if(pos4<jiyi4[k])
while(pos4<jiyi4[k])
205
www.keyestudio.com
myservo4.write(pos4);
delay(5);
pos4++;
//Serial.println(pos1);
else
while(pos4>jiyi4[k])
myservo4.write(pos4);
delay(5);
pos4--;
//Serial.println(pos1);
//*******************************************************
206
www.keyestudio.com
ps2x.enablePressures();
ps2x.read_gamepad(false, vibrate);
vibrate = ps2x.Analog(PSAB_BLUE);
if(ps2x.Button(PSB_R3))
tt=0;
i=0;
break;
//*********************************************************
if(ps2x.Button(PSB_L2))
Serial.println("L2 pressed");
if(ps2x.Button(PSB_R2))
Serial.println("R2 pressed");
if(ps2x.Button(PSB_GREEN))
207
www.keyestudio.com
Serial.println("Triangle pressed");
JUST pressed
JUST released
//turn
zhuandong();
//claw
zhuazi();
// lower arm
208
www.keyestudio.com
dabi();
// upper arm
xiaobi();
TRUE
Serial.print("Stick Values:");
LX, RY, RX
Serial.print(",");
Serial.print(ps2x.Analog(PSS_LX), DEC);
Serial.print(",");
Serial.print(ps2x.Analog(PSS_RY), DEC);
Serial.print(",");
Serial.println(ps2x.Analog(PSS_RX), DEC);
delay(5);
//***************************************************************
209
www.keyestudio.com
*****
// turn
void zhuandong()
// turn right
if(ps2x.Analog (PSS_RX) > 200) // if push the right joystick to the right
//Serial.println(ps2x.Analog(PSS_RX), DEC);
turns right.
// delay(5);
pos1=1;
// turn left
if(ps2x.Analog (PSS_RX) < 50) // if push the right joystick to the left
//Serial.println(ps2x.Analog(PSS_RX), DEC);
210
www.keyestudio.com
// delay(5);
pos1=180;
//***************************************************************
*******
void xiaobi()
pos2=pos2-1;
delay(5);
211
www.keyestudio.com
pos2=0;
pos2=pos2+1;
delay(5);
pos2=180;
//***************************************************************
void zhuazi()
pos4=pos4-1;
212
www.keyestudio.com
Serial.println(pos4);
gradually closed
delay(5);
pos4=0;
pos4=pos4+8;
Serial.println(pos4);
gradually opened
delay(5);
pos4=108;
213
www.keyestudio.com
//*********************************************************
void dabi()
pos3=pos3+1;
delay(5);
pos3=180;
pos3=pos3-1;
delay(5);
214
www.keyestudio.com
pos3=35;
Test Result:
Stack the shield onto Arduino and upload the code. Powered on and connected
the PS2 Joypad, you can use the PS2 Joypad to control the robot arm memorize
several postures, looping.
Resources
215