Arduino - Declaring Multiple Servos and Pots (with for Loops)

Introduction: Arduino - Declaring Multiple Servos and Pots (with for Loops)

This instructable will show you how to declare a theoretically infinite number of servos that is controlled with potentiometers using the servo library and the shortest possible code. Yes, no need to copy and paste code if you want to add more servos. Only change two variables and add/change your pin numbers.

Step 1: Setting Up the Code

You can download the .ino file with the code here.

  1. Find int numServos = 3 and change the 3 to the number of servos you want to use.
  2. Next, find Servo servo[3] and change the 3 to the number of servos you want to use.
  3. In int PotPin[ ] = {0,1,2}; Change the values to the analog pins you will connect your potentiometers to.
  4. Do the same with the values in int ServoPin[ ] = {3,5,6}; These are the digital pins you will connect the signal wires of the servos to.
  5. Upload the code to your arduino

Step 2: Connecting the Dots (wires)

This is the wiring I used to connect my servos and potentiometers. If there are any mistakes feel free to point them out.

If you struggle with the wiring, there is a large number of instructables that shows you how to do this. The main reason I am writing this instructable is to show you how to declare multiple servos without the need to copy and paste code rather than explaining the wiring. I haven't seen anybody else utilize for loops to declare multiple servos.

Step 3: Have Fun!!*

You can now use this for any project you want!!!

I used this as part of a project to build a robot arm. If you are interested in building your own robot arm and would like me to post a complete instructable on the robot arm build, please let me know. If you did something better or with more servos please tell me in the comments below.

Invention Challenge 2017

Participated in the
Invention Challenge 2017

Power Supply Contest

Participated in the
Power Supply Contest

Be the First to Share


    • Cheese Challenge

      Cheese Challenge
    • Fandom Contest

      Fandom Contest
    • Halloween Contest

      Halloween Contest



    1 year ago

    A breve provero questo progetto.
    Per piacere puoi postare come costruire un robot con servo motori?
    Grazie .


    5 years ago

    Thanks for sharing :)