Author Topic: program to run servo motor  (Read 2276 times)

0 Members and 1 Guest are viewing this topic.

Offline darthTopic starter

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
program to run servo motor
« on: September 26, 2011, 06:20:45 AM »
i wanna run 2 servo motors that are connected to my arduino uno. i just wanna know basic program to move servo frwd, back, right and left that will work while i am using ardino0022 software from site in windows.

Offline Adityav95

  • Full Member
  • ***
  • Posts: 64
  • Helpful? 0
Re: program to run servo motor
« Reply #1 on: September 26, 2011, 09:49:09 AM »
Hi darth,
To move the robot forward use the following code
Code: [Select]
#include <servo.h>
Servo servo1; //defining a servo
Servo servo2;

void setup()
{servo1.attach("pin number"); //type the pin in which you want to attach ur servo
servo2.attach("pin number"); //type the pin dor servo 2

void loop()
{ servo1.write(position) ;//enter the servo b/w -180 and +180.

Depending on the position you enter the robot will move forward, backward etc.