#include Servo myservo1; // create servo object to control a servo Servo myservo2; // create servo object to control a servo int pot_1_pin = A0; // analog pin used to connect the potentiometer int pot_2_pin = A1; // analog pin used to connect the potentiometer int val_1; // variable to read the value from the analog pin int val_2; // variable to read the value from the analog pin int past_1 = 0; int past_2 = 0; void setup() { Serial.begin(115200); pinMode(5, OUTPUT); myservo1.attach(10); // attaches the servo on pin 9 to the servo object myservo2.attach(11); // attaches the servo on pin 9 to the servo object } void loop() { val_1 = analogRead(pot_1_pin); // reads the value of the potentiometer (value between 0 and 1023) val_1 = map(val_1, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180) val_2 = analogRead(pot_2_pin); // reads the value of the potentiometer (value between 0 and 1023) val_2 = map(val_2, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180) myservo1.write(val_1); // sets the servo position according to the scaled value myservo2.write(val_2); // sets the servo position according to the scaled value Serial.print(val_1); Serial.print(" "); Serial.println(val_2); delay(15); // waits for the servo to get there if ((val_1 != past_1) || (val_2 != past_2)) { digitalWrite(5, HIGH); } else { digitalWrite(5, LOW); } past_1 = val_1; past_2 = val_2; }