element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum How to drive servos with arduino uno?
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 7 replies
  • Answers 1 answer
  • Subscribers 392 subscribers
  • Views 892 views
  • Users 0 members are here
  • multiple_servos
  • robot
  • servos
  • uno
  • arduino
Related

How to drive servos with arduino uno?

nschreiber0813
nschreiber0813 over 10 years ago

Dear: Element 14

You should know I am trying to drive two servos and one ir sensor with arduino uno. The ir sensor will be used to make my steampunk robot RC while the servos will drive the robot. Also you should know that one servo moves the other one doesn't. The servo connected to pin 12 will not move which is the left servo. I know this servo works because I have tested it several times. Also I think it is a problem of PWM because power and ground pins are clearly working. Can arduino uno drive two servos or not because it says nothing in the datasheet.

From: Noah

 

#include <Servo.h>

Servo myServoLeft;

Servo myServoRight;

int IRpin = A0;

void setup()

{

  Serial.begin(9600);

  pinMode(10, OUTPUT);

  pinMode(11, OUTPUT);

  pinMode(9, OUTPUT);

  Move(360,360);

}

void loop()

{

  digitalWrite(10, HIGH);

  digitalWrite(11, HIGH);

  boolean Signal = digitalRead(IRpin);

  Serial.println(Signal);

}

void Move(int LeftDirection, int RightDirection)

{

  if (!myServoLeft.attached())

  {

    myServoLeft.attach(12);

  }

  myServoLeft.write(LeftDirection);

  if (!myServoRight.attached())

  {

    myServoRight.attach(13);

  }

  myServoRight.write(RightDirection);

}

void Stop(boolean DetachLeft, boolean DetachRight)

{

  if (DetachLeft == true && myServoLeft.attached())

  {

    myServoLeft.detach();

 

  }

  if (DetachRight == true && myServoRight.attached())

  {

    myServoLeft.detach();

  }

}

 

 

image

  • Sign in to reply
  • Cancel
Parents
  • Robert Peter Oakes
    0 Robert Peter Oakes over 10 years ago

    Noah

     

    The code you provide makes no calls to any of the move commands with the exception of the one from startup() so it most lightly will just sit there after the initial move (Depending on the servos)

     

    what servos are you using, provide picture, make  and model number

    provide detailed and clear picture of the schematic your using so we can verify the wiring

     

    also there is no code to handle the IR receiver

     

    what is on pins 9, 10, 11 ?

     

    Please provide all the code if you have it, if not then that's your problem.. missing code

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • nschreiber0813
    0 nschreiber0813 over 10 years ago in reply to Robert Peter Oakes

    What do you mean Peter I am missing code? First of all the ir sensor works fine alon with everything else it is just that one servo that isn't working. Are you not getting my code or am I missing something. Also here is my servo.

    RadioShack Standard Servo : Motors | RadioShack.com

    You should also know pin 10 supplies power to one of the servos while pin 11 supplies power to the ir sensor. Is there anything else you are not getting.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • nschreiber0813
    0 nschreiber0813 over 10 years ago in reply to Robert Peter Oakes

    What do you mean Peter I am missing code? First of all the ir sensor works fine alon with everything else it is just that one servo that isn't working. Are you not getting my code or am I missing something. Also here is my servo.

    RadioShack Standard Servo : Motors | RadioShack.com

    You should also know pin 10 supplies power to one of the servos while pin 11 supplies power to the ir sensor. Is there anything else you are not getting.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • Robert Peter Oakes
    0 Robert Peter Oakes over 10 years ago in reply to nschreiber0813

    The servo you linked in looks like a standard remote model servo and is designed to have a limited range of perhaps 270deg rotation, these are not for continuous rotation required to drive a wheel for example. The one you may want to consider is more like this if it is for driving the wheels

     

    http://www.radioshack.com/parallax-continuous-rotation-servo/2730457.html

     

     

     

    Powering the servos from the pins of an Arduino is NOT recommended, the pins can only provide about 10mA and will be a little less than 5V, most servos, even small ones will consume significantly more than this and can be in excess of 100mA

     

    Powering an LED is ok as this often only requires a few mA to work for the small LEDs and providing a limiting resistor is included

     

     

     

    If one of your servos is already rotated to its max in one direction, telling it to go to 360deg will result in no rotation

     

    Try setting them both to 10deg first, wait a couple of seconds then send a new rotation command of say 180deg

     

     

     

    Hope this helps

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • nschreiber0813
    0 nschreiber0813 over 10 years ago in reply to Robert Peter Oakes

    Thank you peter but I have one more important question. Since I am already using the 5V pin then what pin can I use to power the servos?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 10 years ago in reply to nschreiber0813

    Can you solder, if so make up a breakout connector from 1 wire to many

     

    If not connect them via a breadboard

     

    Regards

     

    Peter

     

    Sent from my iPhone

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
  • nschreiber0813
    0 nschreiber0813 over 10 years ago in reply to Robert Peter Oakes

    Dear: Peter

    Thank you I have done that before for soldering wires. I will give it a shot. If not I will reply back to you.

    From: Noah

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • nschreiber0813
    0 nschreiber0813 over 10 years ago in reply to Robert Peter Oakes

    Dear: Peter

    Thank you for your help. You should know I have finally found a bread board and I finally managed to use it for my robot. Merry Christmas and Happy New Year even though it is a little bit early.

    From Noah

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube