Let's Make Robots!


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

thanks that works great!!!

ye I've used both sweep and knob for one servo so I've gotten that far!!!!How do you declare two servos?

// Controlling a servo position using a potentiometer (variable resistor) 

// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott


#include <Servo.h> 


Servo myservo;  // create servo object to control a servo 

Servo servotwo;


int potpin = 0;  // analog pin used to connect the potentiometer

int potpintwo = 1;

int valtwo;

int val;    // variable to read the value from the analog pin 


void setup() 

  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 



void loop() 

  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)

  valtwo = analogRead(potpintwo);

  valtwo = map(valtwo, 0, 1023, 0, 179);

  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 

  myservo.write(val);                  // sets the servo position according to the scaled value 


  delay(15);                           // waits for the servo to get there 

Where are you so far? Have you gotten one servo to move? Did you use the "knob" or "sweep" example?

As an overview, you will need to declare 2 servos, attach them and also declare 2 variables that you can use to store the position of each servo. From there, it will be identical to either of the examples shown in the IDE, except you will have a 2 sets of servo commands and 2 sets of variables containing the positions.