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
    About the element14 Community
  • 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 421 subscribers
  • Views 5896 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

e14 Contributor
e14 Contributor over 13 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 13 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 13 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…
  • e14 Contributor
    e14 Contributor over 13 years ago +1
    Annasta, Did you intend for server0 and potpin3 to both use pin 3?
Parents
  • e14 Contributor
    0 e14 Contributor over 13 years ago

    Ok I think I figured this out,

    All unique servos are contected to a unique 10k pot.

    Each 10k pot is reading 0 upto 1023 (using 0,1023, 0, 179)

    There is one servo aka: servo 3; that at this time I believe I have traced down its jitter.  Since the wires are not super secur at this time (in the control box secured) there is room for the wires to move around.

    What I am going to do is the following (once that the issue is 100% confirmed) I will then brush rubber cement over the wires on the breadboard to secure them. 

    I am gonig to use 1000μF caps (x4) connecting the positive side to the servo power, and the ground closest to the servo ground.  This part is already done, but again not 100% secure, but doing the job.

     

    One question on the caps....I have them connected to female jumper wires and then, obviously I am connecting the other end into the given locations as stated above.  Anyone have and issues that they would like to state regarding that hook up?

     

    ~Anna

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 13 years ago in reply to e14 Contributor

    Annasta

     

    From your message above, it appears the problem has been resolved, and you now have a few minor wiring concerns.?

     

    If you have followed your excellent drawing, and you seem to want this to be the final method of connections, can I make some suggestions.

    1.     The power for each of the servos, could go onto the power rail, eliminating two jumpers per servo (total 8)

    2.      The power for the pots can go onto the 5v power rail eliminating two jumpers per pot (total 8)

    3.      The 4x ground wire you have connected between the pot side and the servo side, can be a single wire from the second ground pin on the Arduino to the servo ground rail.

    This ensures that any noise is sent to the Arduino ground and not mixed into the pot information to cause extra jitter.

     

    The end game is to get the body of the capacitor as close to the servo motor as possible, but if the size prevents that and you need wires added onto them, then so be it.

    Generally you try to remove as many joints as possible, hence the suggestion above which removes 16 extra joints.

    Your capacitors can still go across the servo power rail just next to the wires going off to the servo, although I suggested you should only need 1 at 1000uF.

     

    Generally breadboards are not designed as permanent wiring, and it should work without resorting to rubber cement.

     

    You may find that if the component/wires are not shiny, they don't make good contact, and plugging them in and pulling them out a few times tends to improve their contact with the breadboard.

     

    So can you please modify the first message to include ANSWERED and give Chris ( http://www.element14.com/community/message/76244#76244 ) and John (http://www.element14.com/community/message/76250#76250 ) the points for solving the problem.

     

     

    Thanks

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 13 years ago in reply to e14 Contributor

    Sorry typo - that is STRIPED, not STRIPPED image

    ~Anna

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 13 years ago in reply to e14 Contributor

    Annasta

    Well done, that layout looks so much better, and you've removed 32 extra connections (16 wires) that you really didn't need.

     

    Yes the stripe is negative (-ve) and connects to the ground.

    That one should be fine.

    The voltage is the maximum voltage that the capacitor can work at, due to the construction, materials used, etc.

    As the voltage rating increases, so does the size. If the size is an issue, then use the lower voltage ones you have.

    A 16v capacitor will work just as well at 5v as it does at 16v.

     

    You can always add another (with a voltage of 5v or greater) if you find it necessary when all the servos are operating and moving whatever they move.

    The current drawn from the 5v servo supply will be more, and more electrical noise will be generated.

     

    One comment that doesn't affect the operation.

    When you connect the power rails, its a good practice to have the +ve on the outside, and the -ve (gnd) closest to the middle for BOTH sides.

    It means if the breadboard is rotated, you are still the same.

     

    Sometimes mistakes get made because our human brains try to eliminate what they think they know .... hence the practice that helps stop that burning smell.

     

    FYI there is one other minor item that someone making this cct can bear in mind.

    The servo noise is high in frequency due to the motors, and the speed of the motor shaft.

    Adding a 0.1uF capacitor between the wiper and the gnd side of the pots, can help smooth out some of this noise.

    You are trying to measure a DC voltage, and the user is unlikely to be able to move the knob/pot fast enough to cause false readings.

     

    It is always best to remove the noise at the source (servos) and hence the addition of the large (1000uF or more) filtering capacitor on the servo supply.

     

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 13 years ago in reply to mcb1

    @Bill,

    I don't think there is a problem with the A/D, as Mark says what would you expect the reading to be if the input is not connected to anything?

    I have just had a look at the data sheet for the details of the A/D circuit and the particular type corresponds with what I suspected. There is a single succesive approximation converter which is fed from an input multiplexer. The input to the comparator of the converter has a sample and hold capacitor. This needs to be large enough that the voltage changes less than than the least significant bit value during the conversion. This means that the voltage held will be pretty close to this long after the conversion is complete. The input bias current of the comparitor is what will discharge it and the capacitor will be sized to cope with the worst case value of this. Typically and at room temperature it will be much less.  When another input is selected by the multiplexer the charge will remain on the capacitor unless the input is actually driving it to a new voltage. If an input is selected that has no connection there is nothing to change the voltage, so the reading obtained will be close to the previous channel. This could be avoided by the manufacturers including a pull up or pull down resistor on each input, but this is pointless as you shouldn't be reading unconnected channels in the first place, and if you do should not expect a meaningful reading from them. Adding such a resistor has a downside also in that it is additional loading on anything actually connected and driving it.

    Chris

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billabott
    0 billabott over 13 years ago in reply to e14 Contributor

    @Anna

    I have one trivial observation:  On the fritzing diagram, to make it a real beauty, you could rotate the BB 90 degrees clockwise, the UNO 90 degrees clockwise, put the pots north of the BB, and the servos on the south side.  Inputs across the top and outputs across the bottom.  The Goal would be to run all 8 i/o lines down the center of the BB.  To have room for all those wires you need to make use of columns B through I instead of just E and F on the BB.  Oh, and replace the white wires with green wires.  Green and orange are nice secondary colors.     image

     

    If you are totally left to right biased, moving the UNO to the top of the diagram and servos on the right would be cool too.

     

    Am still waiting on your announcement that the pots control the servos correctly with the new circuit.  thanks.

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

    Bill

    I think this is the closest we are going to get.

    http://www.element14.com/community/thread/23967?start=49&tstart=0

     

    Shame because there were some many suggestions and no answers/confirmations to our suggestions.

    This doesn't help someone in exactly the same situation later.

     

    Mark

     

    edit. Link corrected thanks to Coder27. So why doesn't E14 give the right linking??

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 13 years ago in reply to mcb1

    Here's a direct link to message #49

     

    http://www.element14.com/community/thread/23967?start=49&tstart=0

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 13 years ago in reply to e14 Contributor

    Guys - thanks so much...

     

    Here is a link to the 2nd portion of this project, if your willing to continue http://www.element14.com/community/message/76606#76606/l/how-do-i-add-a-liquid-crystal-display-to-my-current-project

     

    ~Anna

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 13 years ago in reply to e14 Contributor

    Guys, sorry but I dont understand how to set a question to answer.

    I have looked and unless someone wants to be more exact, I dont see anywhere that I can do that.

    Tell me what I need to do and I will do it..

     

    Anna

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 13 years ago in reply to e14 Contributor

    Annasta

    I think this might give a clue.

    http://www.element14.com/community/message/70611#70611/l/re-how-do-i-change-the-answered-status-of-a-discussion

     

    I haven't actually started a discussion, so I can't do much more than that.

    Somehow you can also tag someone with helpful, although whether you can do more than one person ...again not sure.

     

    Cheers

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 13 years ago in reply to e14 Contributor

    Sent from my Verizon Wireless Sony Ericsson XperiaTm PLAY.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • e14 Contributor
    0 e14 Contributor over 13 years ago in reply to e14 Contributor

    Sent from my Verizon Wireless Sony Ericsson XperiaTm PLAY.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • e14 Contributor
    0 e14 Contributor over 13 years ago in reply to e14 Contributor

    Ummm ok John....I'll bite.....whats your input?

     

     

    ~Anna

    • 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 © 2026 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.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube