
29Chapter 1: The Foundation of Robotic Arms
STEP 4
#include <Servo.h>
Servo servoOne;
int pos;
void setup() {
Serial.begin(9600);
servoOne.attach(3);
}
void loop() {
pos = analogRead(A0);
pos = map(pos, 0, 1023, 0, 180);
servoOne.write(pos);
Serial.print("Servo Position: ");
Serial.println(pos);
delay(100);
}
OK—we have added the code for our servo back in, and if all goes as
planned, once you upload the latest version of the code, as you turn the knob
on your potentiometer, your servo should move accordingly. With that, we
now have a few servo control examples under our belt, and we’re ready to
build our first robotic arm.
WRAPPING THINGS UP
Here in chapter 1, ...