How to use array of servo motor?

How to use array of servo motor with Arduino? How to use multiple servo motors with Arduino?

Answer

Array of servo motor code

#include <Servo.h> #define SERVO_NUM 5 Servo servoArray[SERVO_NUM]; // create aaray of servo object void setup() { servoArray[0].attach(2); // attaches the servo on pin 2 servoArray[0].attach(3); // attaches the servo on pin 3 servoArray[0].attach(4); // attaches the servo on pin 4 servoArray[0].attach(5); // attaches the servo on pin 5 servoArray[0].attach(6); // attaches the servo on pin 6 // rotate all servo motors to 90° for (int i = 0; i < SERVO_NUM; i++) { servoArray[i].write(90); } } void loop() { }

※ NOTE THAT:

Please do not provide power to multiple servo motors via Arduino 5V pin. Use external power source instead. See below wiring diagram for multiple servo motors

Arduino Servo Motor Extra Power

Image is developed using Fritzing. Click to enlarge image

Buy Arduino

1 × Arduino UNO Buy on Amazon
1 × USB 2.0 cable type A/B Buy on Amazon
1 × Jumper Wires Buy on Amazon
Please note: These are affiliate links. If you buy the components through these links, We may get a commission at no extra cost to you. We appreciate it.

The Best Arduino Starter Kit

※ OUR MESSAGES