I am in the final stages of creating an 'Inmoov Robotic Hand'. It's a 3D printed robotic hand controlled by flex sensors which a certain servo reenacts.
A DC power supply is connected to the Arduino to provide power to all servos (set on 6v), and the voltage from the Arduino itself powers the flex sensors. All works well, other than if multiple flex sensors are flexed. This causes multiple servos to move (e.g. 3 Servos from 3 Flexed Sensors); when this happens, the system stops working and bugs out. I think it is due to the drawn current from the multiple servos acting at the same time.
Here's my code:
#include <Servo.h>
int pos1 = 0; //Set first servo to an initial position of 0
int pos2 = 0; //Set second servo to an initial position of 0
int pos3 = 0; //Set third servo to an initial position of 0
int pos4 = 0; //Set fourth servo to an initial position of 0
int pos5 = -300; //Set fifth servo to an initial position of 0
Servo myservo; // create 1st servo object to control a servo
Servo myservo01; // create 2nd servo object to control a servo
Servo myservo02; // create 3rd servo object to control a servo
Servo myservo03; // create 4th servo object to control a servo
Servo myservo04; // create 5th servo object to control a servo
int servoPin1 = 5;
int servoPin2 = 6;
int servoPin3 = 9;
int servoPin4 = 10;
int servoPin5 = 11;
int flexPin1 = A0;
int flexPin2 = A1;
int flexPin3 = A2;
int flexPin4 = A3;
int flexPin5 = A4;
void setup()
{
Serial.begin(9600);
myservo.attach(9); // attaches servo on pin 9 to the servo object
myservo01.attach(10); //attaches sevo on pin 10 to the servo object
myservo02.attach(6); //attaches sevo on pin 6 to the servo object
myservo03.attach(11); //attaches sevo on pin 11 to the servo object
myservo04.attach(3); //attaches sevo on pin 3 to the servo object
}
void loop()
{
//This is the programming for #24 flex sensor
int myservo1 = analogRead(A1) - 630;
pos1 = map(myservo1, 0, 190, 0, 180);
//delay(24);
//Serial.println(pos1);
myservo.write(pos1); // tell servo to go to position in variable 'pos1'
//delay(25); // waits 15ms for the servo to reach the position
//////////////////////////////////////////////////////////////////////////////////////////
//This is the programming for #38 flex sensor
int myservo2 = analogRead(A2) - 450;
pos2 = map(myservo2, 170, 400, 0, 180);
// delay(24);
//Serial.println(pos2);
myservo01.write(pos2); // tell servo to go to position in variable 'pos2'
// delay(25); // waits 15ms for the servo to reach the position
//////////////////////////////////////////////////////////////////////////////////////////
//This is the programming for #34 flex sensor
int myservo3 = analogRead(A3) - 608;
pos3 = map(myservo3, 0, 160, 0, 180);
//delay(24);
//Serial.println(pos3);
myservo02.write(pos3); // tell servo to go to position in variable 'pos3'
//delay(24); // waits 15ms for the servo to reach the position
//////////////////////////////////////////////////////////////////////////////////////////
//This is the programming for #17 flex sensor
int myservo4 = analogRead(A0) - 550;
pos4 = map(myservo4, 0, 100, 0, 180);
// delay(24);
//Serial.println(pos3);
myservo03.write(pos4); // tell servo to go to position in variable 'pos4'
//delay(24); // waits 15ms for the servo to reach the position
//////////////////////////////////////////////////////////////////////////////////////////
//This is the programming for #30 flex sensor
int myservo5 = analogRead(A4) - 600;
pos5 = map(myservo5, 0, 170, 0, 180);
// delay(24);
//Serial.println(pos3);
myservo04.write(pos5); // tell servo to go to position in variable 'pos5'
// delay(24); // waits 15ms for the servo to reach the position
//////////////////////////////////////////////////////////////////////////////////////////
Serial.println(myservo1);
Serial.print(" ");
Serial.print(myservo2);
Serial.print(" ");
Serial.print(myservo3);
Serial.print(" ");
Serial.print(myservo4);
Serial.print(" ");
Serial.print(myservo5);
Serial.print(" ");
delay(200);
}
Any help would be appreciated, thank you.