#include Servo myservo; // create servo object to control a servo Servo myservo2; int potpin = D0; // analog pin used to connect the potentiometer int val; // variable to read the value from the analog pin int val1; int val2; int servo = D4; // D10 is NOT PWM pin int servo2 = D5; // D0 to D9 are PWM pins void setup() { Serial.begin(9600); myservo.attach(servo,500,2400); myservo2.attach(servo2,500,2400); // attaches the servo on pin (servo2) D9 to the servo object, min pulse width, max pulse width // min (optional): the pulse width, in microseconds, corresponding to the minimum (0 degree) angle on the servo (defaults to 544) // max (optional): the pulse width, in microseconds, corresponding to the maximum (180 degree) angle on the servo (defaults to 2400) } void loop() { val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) Serial.println(val); val1 = map(val, 0, 1023, 100, 30); // scale it to use it with the servo (value between 30 and 100 degree) val2 = map(val, 0, 1023, 30, 100); myservo.write(val1); myservo2.write(val2); // sets the servo2 position according to the scaled value delay(15); // waits for the servo to get there }