1.
Open up the Arduino IDE
2. Copy and paste the code below into the IDE
3. Connect the Arduino to the computer using a cable
4. Click on “Tools” and select the Port and Board
5. Click the arrow in the top left hand corner to upload the code onto
the Arduino
6. Spend a lesson changing the values to control the motion of the
crane
#include <Servo.h>
Servo myservo1; // create servo object to control a servo
Servo myservo2;
int potpin1 = A0;
int potpin2 = A1; // analog pin used to connect the potentiometer
int val1;
int val2; // variable to read the value from the analog pin
void setup() {
myservo1.attach(9); // attaches the servo on pin 9 to the servo
object
myservo2.attach(10);
Serial.begin(9600);
}
void loop() {
val1 = analogRead(potpin1); // reads the value of the
potentiometer (value between 0 and 1023)
val1 = map(val1, 0, 1023, 0, 200);
val2 = analogRead(potpin2);
val2 = map(val2, 0, 1023, 0, 200); // scale it to use it with the
servo (value between 0 and 180)
int potpin = A0;
Serial.print("value of x - ");
Serial.println(val1);
Serial.print("value of y - ");
Serial.println(val2);
myservo1.write(val1);
myservo2.write(val2);