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 4321 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?
Parents
  • 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
  • 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 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
  • billabott
    0 billabott over 12 years ago in reply to Former Member

    coder27 was doing a fine job looking after the software.  The sketch does not seem to be the problem.

     

    So, let us now move on to the physical hardware.

     

    The only way (not true, see Note below) what you describe could happen with your code is for the

     

    anolog 0,1,2,3 connected to the breadboard are shorted together somehow


    OR


    PWM pins 3,5,6,9 are shorted together somehow.

     

    So, if I were there I would turn off all the power and start checking for shorts across the inputs and the outputs using an ohmmeter.  image

     

    May we assume that you are using insulated hookup wires?

     

    Correction Note:  It appears that the ADC will misreport the true values of the Analog pins if they are unconnected when read due to slow discharge of the internal sample and hold capacitor.   But why would anyone attempt to read an input pin that does not have a valid data value on it?

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

    It would be interesting to know how the pots are wired. It seems like at least one is wired incorrectly so changing the value of one causes the voltage drop across the others to change. So maybe the wiper out of one is wired to the others inputs.

     

    It is difficult to tell without seeing the wiring. But as others have mentioned double, double check wiring. That's what makes all of this fun, you start out with multiple unknowns. Unproven code on unproven hardware, it doesn't get much better than that.

     

     

    Mike

    • 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

    Anna,  at one point you mention that you are using only one pot at the moment, if I understand correctly. If that is the case then it is important that the other three inputs are driven in some way, e.g. connect to ground. If that is not the case then I suspect what is happening is that the one input level from the pot is being stored in the input to the A/D capacitance. When the multiplexer switches to the next input there is no drive so the voltage stays the same as for the pot input. Even if there is some change it will only be a little bit away from the pot input so the servo will move.

    Chris

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

    I was about to suggest the same thing as Chris.

    I wrote a sketch to measure 6 analogue voltages and display the 6 readings on an LCD.  I found that if i applied a voltage to one input only, then the other channels would indicate a non zero value, generally decreasing from one input to the next one being read. So i suggest fitting the other pots or resistors to mimic them.

    For diagnostic purposes you could write the values read from your potentiometers to the serial interface and read them off on your PC monitor.

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

    I was about to suggest the same thing as Chris.

    I wrote a sketch to measure 6 analogue voltages and display the 6 readings on an LCD.  I found that if i applied a voltage to one input only, then the other channels would indicate a non zero value, generally decreasing from one input to the next one being read. So i suggest fitting the other pots or resistors to mimic them.

    For diagnostic purposes you could write the values read from your potentiometers to the serial interface and read them off on your PC monitor.

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

    @Mark

     

    Do you know what exactly is the problem with the UNO ADC?  timing?  proximity?  I don't get it.

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

    William

    No sorry I don't.

    It's proably something that either didn't get tested, or they don't bother with.

    After all why be interested in the adc reading if the pin is floating?

     

    As an ADC input you don't use the pullup resistor (you can but you get modified results) so the input will be VERY high impedance.

     

    Never the less I've learnt something for the future, and I'm sure it will come up again, so hopefully we can be quick to spot it.

     

    Someone else who is more capable (and has more time than me) can probably work out why, BUT can we fix it.??

     

     

    Mark

    • 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