element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • 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
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • 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 ~ ANSWERED ~ If this is a repeat, my apologies - 4 servos all turning at once with one potentiometer...This is NOT the way the project is to work.  Please help
  • 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 67 replies
  • Answers 3 answers
  • Subscribers 406 subscribers
  • Views 4319 views
  • Users 0 members are here
  • answered
Related

~ ANSWERED ~ If this is a repeat, my apologies - 4 servos all turning at once with one potentiometer...This is NOT the way the project is to work.  Please help

Former Member
Former Member over 12 years ago

Hello all,

I am working on a project with 4 servos, and 4 potentiometers.

I will include my coding momentarily.  Here is my dilemma.

As the title states: "4 servos all turning at once with one potentiometer...This is NOT the way the project is to work."

The project is to turn each servo unit with its own potentiometer (dial style).  I have compiled my coding and it all comes out ok, I then upload it with no issue.

I then attempt to turn the pot and all 4 turn, and if I may add, with quite a bit of jitterness.

Can you please take a moment, look at the code and advise where you think the problem is.

This code was the KNOB example from the Arduino UNO example library.  I removed the name of the person as I have continued to add to the program.

You will see the things I have added as I have notated them.

 

Thanks in advance,

Anna

 

Now the code:

 

#include <Servo.h>

Servo myservo0;  // create servo object to control a servo
Servo myservo1;  // i added
Servo myservo2;  // i added
Servo myservo3;  // i added

 

int potpin0 = 0;  // analog pin used to connect the potentiometer (i added the zero to the potpin before the equal sign)
int val0;    // variable to read the value from the analog pin

int potpin1 = 1;  // i added
int val1;         // i added

 

int potpin2 = 2;  // i added
int val2;         // i added 

 

int potpin3 = 3;  //  i added
int val3;         //  i added


void setup()
{
  myservo0.attach(3);  // attaches the servo on pin 3 to the servo object --- I changed it to 3 from previously 9 - Anna
  myservo1.attach(5);  // i added
  myservo2.attach(6);  // i added
  myservo3.attach(9);  // i added
}

void loop()
{
  val0 = analogRead(potpin0);            // reads the value of the potentiometer (value between 0 and 1023)
  val0 = map(val0, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
  myservo0.write(val0);                  // sets the servo position according to the scaled value
  delay(15);                             // waits for the servo to get there

 

val1 = analogRead(potpin1);            // i added
  val1 = map(val1, 0, 1023, 0, 179);     // i added
  myservo1.write(val1);                  // i added 
  delay(15);

 

  val2 = analogRead(potpin2);            // i added
  val2 = map(val2, 0, 1023, 0, 179);     // i added
  myservo2.write(val2);                  // i added
  delay(15);

 

  val3 = analogRead(potpin3);            // i added
  val3 = map(val3, 0, 1023, 0, 179);     // i added
  myservo3.write(val3);                  // i added
  delay(15);
}

 

Message was edited by: Annasta Brandon My project question was answered, now on to part 2... http://www.element14.com/community/thread/24030

  • Sign in to reply
  • Cancel

Top Replies

  • mcb1
    mcb1 over 12 years ago in reply to billabott +2
    I had a look at this discussion last night, but unfortunately our IT department does some weird java filtering, so I can't reply. Thanks Bill for the invite. The suggestions made so far look correct, but…
  • terrydark
    terrydark over 12 years ago in reply to mcb1 +2
    Hi Just to confirm Mark's statements... "The Arduino reference has mixed messages regarding the name to use for the Analogue inputs. A0, 0 all seem to work BUT it has to know its doing an analogue reading…
  • Former Member
    Former Member over 12 years ago +1
    Annasta, Did you intend for server0 and potpin3 to both use pin 3?
  • Former Member
    0 Former Member over 12 years ago

    Annasta,

      Did you intend for server0 and potpin3 to both use pin 3?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago in reply to Former Member

    I must be missing something....can you advise further

     

    Anna

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago in reply to Former Member

    you have:

     

       int potpin3 = 3;  //  i added

       ...

       myservo0.attach(3);  // attaches the servo on pin 3 to the servo object --- I changed it to 3 from previously 9 - Anna

     

    both apparently attached to pin 3.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • billabott
    0 billabott over 12 years ago

    @Anna

     

    Do you have an adequate separate power supply for the servos?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago in reply to billabott

    Billabott -

    Yes.  I have a seperate power 5 volt power supply with common ground.

    Anna

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago in reply to Former Member

    at coder27 -

    int potpin3 = 3 (this is my analog, should i place an A infront? like A3?)

    the other 3 is for my servo attached to pwm 3

     

    Anna

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billabott
    0 billabott over 12 years ago in reply to Former Member

    That is good.  What is the current capacity of the 5V servo supply?  I recall that updating the servos too quickly causes the thrashing of their little bitty motors.  Check to see if delay(300) cures it and then you can find something lower like delay(175).

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago in reply to Former Member

    You don't need an A in front.

    I think you're right that pwm 3 wouldn't conflict with analog pin 3.

    I'm not experienced enough to know, but that was the only thing

    that looked suspicious.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago in reply to billabott

    @Bill,

    I have no idea what the capacity is of the 5v servo supply.  I know it works...the problem is this:

    I have anolog 0,1,2,3 connected to the breadboard, the pot signals are each connected to one of those analog pins via the breadboard, power to the pots is being ran off the 5v arduino board with the common ground.

    PWM pins 3,5,6,9 are connected to the side of the breadboard to which the servos are connected, again each PWM wire (solid wire) is going to 1 of the 4 servos (as in ~3 connects to i1, ~5 connects to i5, ~6 to i9, and ~9 to i13

    So what is currentl happening, because I wanted to test each servo and connection, i have just one pot set up at the moment.  In order to check each one, I simply remove the signal wire, and move it to the next servo breadboard connection.  ALL the servos are turning with the use of 1 pot, 2 are turning to the right, 2 are turning to the left.  This is not suppose to happen.

    If i was to remove 3 of the 4 servo connections, then the servo works fine.  I add a second one back and i now get the dual turning of both servos when the signal isnt even hooked up to the second servo.

    So I dont understand where changing the delay will have anything to do with this issue.  Looks like I will need to dig deeper into this.

    ~Anna

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago in reply to Former Member

    There is very similar code here:

     

    http://www.element14.com/community/message/75522#75522/l/re-in-need-of-assistance-please

     

    which uses only one delay at the end, instead of 4 separate delays.

    Maybe that would help.

    • 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