Four steps to access and use the standard arduino servo library in your sketch code:
The above code examples can be copied to the Arduino IDE software and uploaded to your device to watch servo motor position control in action. try changing the position value in the servo.write() statement to see different results. You can also try "myservo.write(random(0,180)" to randomly change the servo position value. Also note that enough time must be allowed for the servo to reach its new position before a new position value is written to it. The above example uses the "delay(1000)" statement to wait for 1 second between position writes.
To control more than one servo motor simply add steps 2 thru 4 above to your code using unique servo names as shown in the "Multi Servo Motors" code example.
These servo code examples show the basic use of the arduino servo library. Check out the Arduino Servo Reference for additional details.
It is important that the servo motors are connected properly to your micro controller board and powered properly. View the Robotio and Arduino wiring pin-out diagrams for more information.
Study the code generated by Servo-Matic to see how Microbotlabs uses the servo library to control the Armuno and Armio robot arms.
Read the Joystick Servo Control tutorial to learn how to connect and read sensor values that are then converted to servo motor position values with your arduino.
//Multi Servo Motors, Position Loop
#include <Servo.h>
Servo myservo;
Servo myservo2;
void setup()
{
myservo.attach(2);//Signal Pin
myservo2.attach(3);
}
void loop() {
myservo.write(0);//Servo Position 1
myservo2.write(20);
delay(1000);//Travel time to new position
myservo.write(90);//Servo Position 2
myservo2.write(110);
delay(1000);//Travel time to new position
myservo.write(180);//Servo Position 3
myservo2.write(random(0,180));
delay(1000);//Travel time to new position
}
Our Make & Learn Brands: MICROBOTLABS™ ARM.UNO™ ROBOTIO™ PROTIO™ ARMIO™ ANITRON™ ANITRONIC™ ARM.ONE™