How To Control 12 Servos With Potentiometers Via HC-05 Bluetooth Modules

I am building a robot with 12 Servos. (5 for each arm, and 2 for the head.)

I have built a control box containing 12 Potentiometers and HC-05 Bluetooth Module connected to Arduino Mega.

The robot is 12 Servos connected to another Arduino Mega with its own Bluetooth Module.

My goal is this: Turn potentiometer 1 and servo 1 moves, turn potentiometer 2 and servo 2 moves. and so on.......

I found some code online but the problem is, it is only for 1 servo.

I can't figure out how to send multiple potentiometer values at the same time.

I hope this isn't a stupid question but i need to finish this project in the next week, so please help.

//control box

#include <Servo.h>

Servo myServo;
int state = 20;

void setup() {
myServo.attach(9);
Serial.begin(9600);
}

void loop() {
if(Serial.available() > 0){
state = Serial.read();
}

myServo.write(state);
delay(10);
}

//robot

int potValue = 0;

void setup() {
Serial.begin(9600);
}

void loop() {

potValue = analogRead(A0);
int potValueMapped = map(potValue, 0, 1023, 0, 255);
Serial.write(potValueMapped);
delay(10);
}

1_Servo_Bluetooth__control_box.ino|attachment (247 Bytes)

_1_Servo_Bluetooth_Robot.ino (213 Bytes)

well you just read all the pots and then send the signal to all the servos. I don't know how to work with the Bluetooth Module, but when you would have everything connected to the arduino itself the code would look like this:

#include <Servo.h>

Servo Servo0, Servo1,.....,Servo12;

int servopin0 = 9;
.
.
int servopin0 = 21; //or whatever pins are PWM enabled


int potpin0=0;
.
.
int potpin0=12; //again whatever pins are analog capable



void setup() {
  Servo0.attach(servopin0); 
  .
  .
  Servo12.attach(servopin12);
  
}

void loop() {
  int reading0 = analogRead(potpint0); //first read all the pots
  .
  .
  int reading12 = analogRead(potpint12);

  angle0 = map(reading0,0,1023,0,180): //then map all the pots
  .
  .
  angle12 = map(reading12,0,1023,0,180):

  Servo0.write(angle0); //finally write all the servos
  .
  .
  Servo12.write(angle12);

  
}

The basic idea is to first read all the pots, then map the readings to angles and then write to the servos. You could probably write a lot cleaner code if you use arrays and for loops but this is the basic idea. BTW if you want to drive 12 servos I'd recommend the adafruit 16 channel servo driver for much better control and power management.

Hi did you find the answer