Maker 101
Published © GPL3+

Up to 9 servos control board via Bluetooth

Explore Using a Customized Arduino Nano-based Board to Wirelessly Control Up to 9 Servo Motors Via Bluetooth

IntermediateFull instructions provided1 hour280
Up to 9 servos control board via Bluetooth

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Resistor 220 ohm
Resistor 220 ohm
×9
Resistor 1k ohm
Resistor 1k ohm
×1
Through Hole Resistor, 2.2 kohm
Through Hole Resistor, 2.2 kohm
×1
Capacitor 470 µF
Capacitor 470 µF
×2
Capacitor 100 µF
Capacitor 100 µF
×1
1N5819 – 1A Schottky Barrier Rectifier
1N5819 – 1A Schottky Barrier Rectifier
×1
Wire-To-Board Terminal Block, 5 mm
Wire-To-Board Terminal Block, 5 mm
×1
2x15 Pin Headers Socket 2.54mm Male & Female 4 Pair Connector
M5Stack 2x15 Pin Headers Socket 2.54mm Male & Female 4 Pair Connector
×1
2x15 Pin Headers Socket 2.54mm Male & Female 4 Pair Connector
M5Stack 2x15 Pin Headers Socket 2.54mm Male & Female 4 Pair Connector
×1

Software apps and online services

Arduino IDE
Arduino IDE
MIT App Inventor
MIT App Inventor

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Cable Cutter, 143mm
Cable Cutter, 143mm

Story

Read more

Schematics

Schematic

Bill of Meterials

App Inventor AIA File

Code

multipleServo-maker101io.ino

Arduino
Multiple Servo Motor Control Code
/*
  https://www.youtube.com/@maker101io

  In this section, we add the Servo library and then define 9 servo motors as an array. 
  We specify the pin numbers to which the servo motors are connected as an array. 
  We specify the start and end positions, we also set the delay time between the loop.
*/

#include <Servo.h>

Servo servos[9];  // Define servo objects as an array

int servoPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10};  // Define servo pin numbers as an array
int startPos = 5;  // Servo start position
int endPos = 175;  // Servo end position
int delayTime = 5;  // Delay time

void setup() {
  for (int i = 0; i < 9; i++) {
    servos[i].attach(servoPins[i]);  // Connect servo objects to pins
    servos[i].write(startPos);  // Set servo start position
    delay(10);
  }
}

/*
  There are two loops in the loop() function. In the first loop, we move the servo motors in 
  increasing order within a certain angle range. In the second loop, we move the servo motors in 
  the opposite direction in descending order in the same angle range. In the transition between the 
  two loops, we control each servo motor in turn.
*/

void loop() {
  for (int pos = startPos; pos <= endPos; pos++) {
    for (Servo &servo : servos) {
      servo.write(pos);
      delay(delayTime);
    }
  }

  for (int pos = endPos; pos >= startPos; pos--) {
    for (Servo &servo : servos) {
      servo.write(pos);
      delay(delayTime);
    }
  }
}

/*
  
  'for (Servo &servo : servos)'

  This expression uses a "range-based for loop" feature in C++. 
  This is used to traverse an array or other range.

  - 'Servo &servo:' This specifies the type of each element in the loop. 
  So in this loop, each element of the servos array is an object of type Servo.

  - ': servos:' This specifies the range to be travelled in the loop. 
  Each element of the servos array will be assigned to the variable servo in turn.

  This statement allows to navigate through the array by assigning each Servo object in 
  turn to a reference named servo. This avoids rewriting the same operations for each servo motor 
  and makes the code cleaner.
*/

multipleServoBLE_maker101io.ino

Arduino
Multiple Servo Motor Control via Vluetooth
/* https://www.youtube.com/@maker101io */

//Includes the Servo library for servo motor control
#include <Servo.h>

//The Servo object is created. This object will be used to control the servo motor.
Servo servos[9];  // Define servo objects as an array

int servoPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10};  // Define servo pin numbers as an array

//It is the function that configures the initial settings of the Arduino. This function works only once.
void setup() {
  //The Servo object is connected to pin on the Arduino. This means that we will send the control signal of the servo motor to this pin.
  for (int i = 0; i < 9; i++) {
    servos[i].attach(servoPins[i]);  // Connect servo objects to pins
  }
  //Serial communication is initiated. This is a port used to communicate information serially with a computer or other device.
  Serial.begin(9600);
}

//It is the main loop of the Arduino that runs continuously.
void loop() {
  //Checks if data is received over the serial connection. If there is data, it enters the block.
  if (Serial.available() > 0) {
    //It reads a byte from the serial connection and assigns this value to the 'servopos' variable. This value will be used as the new position of the servo motor.
    int servopos = Serial.read();
    //Sets the position of the servo motor to the specified 'servopos' value. This moves the servomotor to the specified position.
    for (Servo &servo : servos) {
      servo.write(servopos);
    }
  }
}

Credits

Maker 101

Maker 101

50 projects • 178 followers
Maker 101; Beginner and intermediate level Maker projects!

Comments