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() {
[Link](9); // attaches the servo on pin 9 to the servo
object
[Link](10);
[Link](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;
[Link]("value of x - ");
[Link](val1);
[Link]("value of y - ");
[Link](val2);
[Link](val1);
[Link](val2);