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
Passive Components
  • Technologies
  • More
Passive Components
Forum My 4 servos are all turning simultaneously with one Potentiometer Why??? Please see my code...thanks
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Passive Components to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 3 replies
  • Subscribers 108 subscribers
  • Views 652 views
  • Users 0 members are here
Related

My 4 servos are all turning simultaneously with one Potentiometer Why??? Please see my code...thanks

Former Member
Former Member over 12 years ago

Hi everyone,

As the title states: "My 4 servos are all turning simultaneously with one Potentiometer"  That is not the way the project is suppose to work.

Each servo is to work independently of the other 3, with its own potentiometer.

I don't know what is happening..but here is the code, I am hoping someone can help me with this.

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 9 to the servo object

  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);

}

 

Thank you in advance for any and all assistance I may receive.

 

Anna

  • Sign in to reply
  • Cancel

Top Replies

  • element14jamie
    element14jamie over 11 years ago in reply to Former Member +1
    Thank you coder27 it is appreciated. Jamie
Parents
  • element14jamie
    0 element14jamie over 11 years ago

    Hello Annasta,

    I am moving this discussion to the Variable Resistor Solutions area of the Community, and thank you for being a menmber.

     

     

     

    Thank you,

     

    Jamie

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • element14jamie
    0 element14jamie over 11 years ago

    Hello Annasta,

    I am moving this discussion to the Variable Resistor Solutions area of the Community, and thank you for being a menmber.

     

     

     

    Thank you,

     

    Jamie

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

    this question was answered here:

    http://www.element14.com/community/thread/23967

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
  • element14jamie
    0 element14jamie over 11 years ago in reply to Former Member

    Thank you coder27 it is appreciated.

     

     

    Jamie

    • Cancel
    • Vote Up +1 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