keskiviikko 6. helmikuuta 2013

Arduino servo motor

It moves! This time i got black servo motor version s3003. I just wanted to see if I can control it somehow and yes, I can. "Radio Control Servos are great pieces of kit. They are essential in pretty much every robot build, from controlling arms and legs to driving wheels and tracks. Servos normally rotate up 180 degrees with the 90 degree mid-point being the center position, and can be positioned at any point in-between. "






#include <Servo.h>
Servo servoMain; // Define our Servo

void setup()
{
   servoMain.attach(A0); // servo on analog pin 0
}

void loop()
{
   servoMain.write(45);  // Turn Servo Left to 45 degrees
   delay(1000);          // Wait 1 second
   servoMain.write(0);   // Turn Servo Left to 0 degrees
   delay(1000);          // Wait 1 second
   servoMain.write(90);  // Turn Servo back to center position (90 degrees)
   delay(1000);          // Wait 1 second
   servoMain.write(135); // Turn Servo Right to 135 degrees
   delay(1000);          // Wait 1 second
   servoMain.write(180); // Turn Servo Right to 180 degrees
   delay(1000);          // Wait 1 second
   servoMain.write(90);  // Turn Servo back to center position (90 degrees)
   delay(1000);          // Wait 1 second
}

Very simple code how to control servo.


Ei kommentteja:

Lähetä kommentti