Skip to content

Commit 3da96c0

Browse files
Trainable Robotic Arm using VB .Net app
Digital Pins are used
1 parent a94603c commit 3da96c0

File tree

1 file changed

+122
-123
lines changed

1 file changed

+122
-123
lines changed

TrainableRoboticArm.ino

Lines changed: 122 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,123 @@
1-
#include<Servo.h>
2-
3-
Servo motor[6];
4-
5-
Servo test;
6-
7-
int analogPin = A0;
8-
int data;
9-
int motorJoint = 48;//to take which joint to move
10-
int angle;
11-
int command;//read command in serial connection
12-
int pos = 0;//servo motor loop movement variable
13-
void setup() {
14-
// put your setup code here, to run once:
15-
motor[0].attach(8);
16-
motor[1].attach(9);
17-
motor[2].attach(10);
18-
motor[3].attach(11);
19-
motor[4].attach(12);
20-
motor[5].attach(13);
21-
Serial.begin(9600);
22-
23-
}
24-
25-
void motorMove(int i, int data)
26-
{
27-
for(pos = 0; pos < data; pos += 1) // goes from 0 degrees to 180 degrees
28-
{ // in steps of 1 degree
29-
motor[i].write(pos); // tell servo to go to position in variable 'pos'
30-
delay(35); // waits 15ms for the servo to reach the position
31-
}
32-
for(pos = data; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
33-
{
34-
motor[i].write(pos); // tell servo to go to position in variable 'pos'
35-
delay(35); // waits 15ms for the servo to reach the position
36-
}
37-
}
38-
39-
void loop() {
40-
// put your main code here, to run repeatedly:
41-
delay(1);
42-
Serial.println("test");
43-
if(Serial.available())
44-
{
45-
command = Serial.read();
46-
47-
switch(command)
48-
{
49-
case 113://ASCII code for q
50-
case 119:
51-
case 101:
52-
case 114:
53-
case 116:
54-
motorJoint = command;
55-
Serial.println(motorJoint);
56-
break;
57-
default:
58-
data = command;
59-
//to convert ASCII code to normal data
60-
switch(data)
61-
{
62-
case 48: data = 0;break;
63-
case 49: data = 1;break;
64-
case 50: data = 2;break;
65-
case 51: data = 3;break;
66-
case 52: data = 4;break;
67-
case 53: data = 5;break;
68-
case 54: data = 6;break;
69-
case 55: data = 7;break;
70-
case 56: data = 8;break;
71-
case 57: data = 9;break;
72-
default: break;
73-
}
74-
//Serial.println(data);
75-
if (data>=0 && data <=9)
76-
switch(motorJoint)
77-
{
78-
case 113://code for base
79-
if(data == 0)
80-
//{motorMove(0,180);
81-
//delay(500);}
82-
motor[0].write(180);
83-
else
84-
//{motorMove(0, data*10*1.8);
85-
//delay(500);}
86-
motor[0].write(data*10*1.8);
87-
Serial.println(data*10*1.8);
88-
break;
89-
case 119:
90-
if(data == 0)
91-
motorMove(1, 180);
92-
else
93-
motorMove(1, data*10*1.8);
94-
// motor[1].write(data*10*1.8);
95-
//motor[2].write(data);
96-
break;
97-
case 101:
98-
if(data == 0)
99-
motorMove(2, 180);
100-
else
101-
motorMove(2, data*10*1.8);
102-
break;
103-
case 114:
104-
if(data == 0)
105-
motorMove(4, 180);
106-
else
107-
motorMove(4, data*10*1.8);
108-
break;
109-
case 116:
110-
if(data == 0)
111-
motorMove(5,180);
112-
else
113-
motorMove(5, data*10*1.8);
114-
break;
115-
default:
116-
break;
117-
}
118-
break;
119-
}
120-
121-
}
122-
123-
}
1+
#include<Servo.h>
2+
3+
Servo motor[6];
4+
5+
Servo test;
6+
7+
int analogPin = A0;
8+
int data;
9+
int motorJoint = 48;//to take which joint to move
10+
int angle;
11+
int command;//read command in serial connection
12+
int pos = 0;//servo motor loop movement variable
13+
void setup() {
14+
// put your setup code here, to run once:
15+
motor[0].attach(8);
16+
motor[1].attach(9);
17+
motor[2].attach(10);
18+
motor[3].attach(11);
19+
motor[4].attach(12);
20+
motor[5].attach(13);
21+
Serial.begin(9600);
22+
23+
}
24+
25+
void motorMove(int i, int data)
26+
{
27+
for(pos = 0; pos < data; pos += 1) // goes from 0 degrees to 180 degrees
28+
{ // in steps of 1 degree
29+
motor[i].write(pos); // tell servo to go to position in variable 'pos'
30+
delay(35); // waits 15ms for the servo to reach the position
31+
}
32+
for(pos = data; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
33+
{
34+
motor[i].write(pos); // tell servo to go to position in variable 'pos'
35+
delay(35); // waits 15ms for the servo to reach the position
36+
}
37+
}
38+
39+
void loop() {
40+
// put your main code here, to run repeatedly:
41+
delay(1);
42+
Serial.println("test");
43+
if(Serial.available())
44+
{
45+
command = Serial.read();
46+
47+
switch(command)
48+
{
49+
case 113://ASCII code for q
50+
case 119:
51+
case 101:
52+
case 114:
53+
case 116:
54+
motorJoint = command;
55+
Serial.println(motorJoint);
56+
break;
57+
default:
58+
data = command;
59+
//to convert ASCII code to normal data
60+
switch(data)
61+
{
62+
case 48: data = 0;break;
63+
case 49: data = 1;break;
64+
case 50: data = 2;break;
65+
case 51: data = 3;break;
66+
case 52: data = 4;break;
67+
case 53: data = 5;break;
68+
case 54: data = 6;break;
69+
case 55: data = 7;break;
70+
case 56: data = 8;break;
71+
case 57: data = 9;break;
72+
default: break;
73+
}
74+
//Serial.println(data);
75+
if (data>=0 && data <=9)
76+
switch(motorJoint)
77+
{
78+
case 113://code for base
79+
if(data == 0)
80+
//{motorMove(0,180);
81+
//delay(500);}
82+
motor[0].write(180);
83+
else
84+
//{motorMove(0, data*10*1.8);
85+
//delay(500);}
86+
motor[0].write(data*10*1.8);
87+
Serial.println(data*10*1.8);
88+
break;
89+
case 119:
90+
if(data == 0)
91+
motorMove(1, 180);
92+
else
93+
motorMove(1, data*10*1.8);
94+
// motor[1].write(data*10*1.8);
95+
//motor[2].write(data);
96+
break;
97+
case 101:
98+
if(data == 0)
99+
motorMove(2, 180);
100+
else
101+
motorMove(2, data*10*1.8);
102+
break;
103+
case 114:
104+
if(data == 0)
105+
motorMove(4, 180);
106+
else
107+
motorMove(4, data*10*1.8);
108+
break;
109+
case 116:
110+
if(data == 0)
111+
motorMove(5,180);
112+
else
113+
motorMove(5, data*10*1.8);
114+
break;
115+
default:
116+
break;
117+
}
118+
break;
119+
}
120+
}
121+
122+
}
124123

0 commit comments

Comments
 (0)