
7-27
7-28
141Chapter 7: 3D Robotic Arms
Once you have fully written, compiled, and uploaded
the code, you should see the base of your robotic
arm rotate from 0 to 90 degrees and then motors 2
and 3 rotate from 45 to 135 degrees (Figures
7-27
and
7-28
).
Next, we need to integrate motor 4, which should be
much simpler than the previous two motors, as only
one motor controls this joint:
#include <Servo.h>
Servo servoOne;
Servo servoTwo;
Servo servoThree;
Servo servoFour;
int pos;
void setup() {
servoOne.attach(3);
servoTwo.attach(5);
servoThree.attach(6);
servoFour.attach(9);
}
void loop() {
for (pos = 0; pos <= 90; pos++) {
servoOne.write(pos);
delay