Hey, I am trying to build a prop hand, but I am having some issues controlling five servo motors using five flex sensors. I just started learning about Arduino and basic electronics a couple of weeks ago, so I'm still not sure how a lot of it works at this point. I started with one servo using a flex sensor and was able to make that work, then I tried expanding on that set up for five flex sensors and servos, but the servos are unresponsive. They seem to be making a low buzzing sound when I turn on the Arduino and the flex sensors show no changes in the serial monitor when I bend them. Ive tried searching the internet for a solution, I've tried a variety of codes and circuit arrangements for this setup, but they all yield the same result. I've tested each servo individually with each flex sensor and they all work, just not all at once. Ive tried powering the servos from the Arduinos 5V(which I read was fine considering these servos operate around 4.8V), but Ive also tried to power them separately using a 4 AA battery pack(still didn't work). I am using the Arduino UNO rev3, five 2.2'' flex sensors, five 220 ohm resistors, one Tower Pro SG90 micro servo and four Turnigy TG9e micro servos. Any help or explanations as to what I did wrong or should do and why(I'm very interested in learning about all of this) would be greatly appreciated. Thanks.
Here is the code I have running at the moment:
#include <Servo.h>
Servo servo_thumb;
Servo servo_index;
Servo servo_middle;
Servo servo_ring;
Servo servo_pinky;
const int flexpin_thumb = A0;
const int flexpin_index = A1;
const int flexpin_middle = A2;
const int flexpin_ring = A3;
const int flexpin_pinky = A4;
void setup()
{
Serial.begin(9600);
servo_thumb.attach(6);
servo_index.attach(5);
servo_middle.attach(4);
servo_ring.attach(3);
servo_pinky.attach(2);
}
void loop()
{
int flexposition_thumb;
int flexposition_index;
int flexposition_middle;
int flexposition_ring;
int flexposition_pinky;
int servoposition_thumb;
int servoposition_index;
int servoposition_middle;
int servoposition_ring;
int servoposition_pinky;
flexposition_thumb = analogRead(flexpin_thumb);
flexposition_index = analogRead(flexpin_index);
flexposition_middle = analogRead(flexpin_middle);
flexposition_ring = analogRead(flexpin_ring);
flexposition_pinky = analogRead(flexpin_pinky);
servoposition_thumb = map(flexposition_thumb, 745, 945, 0, 180);
servoposition_thumb = constrain(servoposition_thumb, 0, 180);
servoposition_index = map(flexposition_index, 745, 945, 0, 180);
servoposition_index = constrain(servoposition_index, 0, 180);
servoposition_middle = map(flexposition_middle, 745, 945, 0, 180);
servoposition_middle = constrain(servoposition_middle, 0, 180);
servoposition_ring = map(flexposition_ring, 745, 945, 0, 180);
servoposition_ring = constrain(servoposition_ring, 0, 180);
servoposition_pinky = map(flexposition_pinky, 745, 945, 0, 180);
servoposition_pinky = constrain(servoposition_pinky, 0, 180);
servo_thumb.write(servoposition_thumb);
delay(20);
servo_index.write(servoposition_index);
delay(20);
servo_middle.write(servoposition_middle);
delay(20);
servo_ring.write(servoposition_ring);
delay(20);
servo_pinky.write(servoposition_pinky);
delay(20);
Serial.print("sensor_thumb: ");
Serial.print(flexposition_thumb);
Serial.print("servo_thumb: ");
Serial.println(servoposition_thumb);
Serial.print("sensor_idex: ");
Serial.print(flexposition_index);
Serial.print("servo_index: ");
Serial.println(servoposition_index);
Serial.print("sensor_middle: ");
Serial.print(flexposition_middle);
Serial.print("servo_middle: ");
Serial.println(servoposition_middle);
Serial.print("sensor_ring: ");
Serial.print(flexposition_ring);
Serial.print("servo_ring: ");
Serial.println(servoposition_ring);
Serial.print("sensor_pinky: ");
Serial.print(flexposition_pinky);
Serial.print("servo_pinky: ");
Serial.println(servoposition_pinky);
}
I've attached a Fritzing diagram of the components. The diagram does not include an image of the battery (4AA pack) powering the servos