Servos and flex sensors

Im currently using 5 mini servos and 5 flex sensors bought from sparkfun. Im using an arduino Uno board and the sketch which im running is posted below:

#include <Servo.h>

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;

int flexsensor1 = 0; // analog pin used to connect the flex sensors
int flexsensor2 = 1;
int flexsensor3 = 2;
int flexsensor4 = 3;
int flexsensor5 = 4;

int val1; // variables to read the values from the analog pins
int val2;
int val3;
int val4;
int val5;

void setup()
{
servo1.attach(3); // attaches the servo on pin 3,5,6,9,10 to the servo object
servo2.attach(5);
servo3.attach(6);
servo4.attach(9);
servo5.attach(10);

Serial.begin(9600); //serial communication, just for debugging
}

void loop()
{
val1 = analogRead(flexsensor1); // reads the value of the potentiometer (value between 0 and 1023)
val1 = map(val1, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
servo1.write(val1); // sets the servo position according to the scaled value
Serial.print("\t flexsensor1 value = " ); //prints the sensor value on the screen
Serial.print(val1);
delay(15);

val2 = analogRead(flexsensor2);
val2 = map(val2, 0, 1023, 0, 179);
servo2.write(val2);
Serial.print("\t flexsensor2 value = ");
Serial.println(val2);
delay(15);

val3 = analogRead(flexsensor3);
val3 = map(val3, 0, 1023, 0, 179);
servo3.write(val3);
Serial.print("\t flexsensor3 value = ");
Serial.println(val3);
delay(15);

val4 = analogRead(flexsensor4);
val4 = map(val4, 0, 1023, 0, 179);
servo4.write(val4);
Serial.print("\t flexsensor4 value = ");
Serial.println(val4);
delay(15);

val5 = analogRead(flexsensor5);]
val5 = map(val5, 0, 1023, 0, 179);
servo5.write(val5);
Serial.print("\t flexsensor5 value = ");
Serial.println(val5);
delay(15);
}

My wiring is very similar to this
http://img.azega.com/wp-content/uploads/2011/02/Arduino_Servo_1_thumb.png


the only difference is that there are 5 servos and 5 flex sensors.

The problem is that when im flex any of the sensors the servo which is equivalen to the sensor that im flex moves, but the rest of the servos are moving a little bit too.

Any help will be appreciated!!!

Probably not the cheapest ($20), but Sparkfun have just brought out this one:

I think it's one typically used by audio mixier manufacturers, so it would definitely fit the use case.

Thanks for your reply but the a problem is with the software and not with the hardware because every flex sensor must move only one servo. In my case when i flex a sensor all the servos are slightly moving unstable.

Could be power related. Servos usually don't work well being powered by just the arduino board and if you ever tried to move all servos at the same time you might really see problems. Also the flex devices are using the +5vdc in a voltage divider circuit so any servo induced noise on the +5vdc could cause variation in the analog read functions. If you could power just the servo power wires from say 4 AA cells that would take the servo load off the boards power. Also some bypass caps from servo power to servo ground could help. You will need to experiment some, as your code seems simple enough and correct as far as I can tell.

Lefty

One possible thing - when you read a different analog pin from the previous call to analogRead the analog circuitry may not have time to settle if the source is high-impedance. You can test this hypothesis by calling analogRead twice in succession for the same pin and ignoring the first result.

What's happening electrically is that the analog multiplexer circuit is reconfigured immediately before the conversion (for a low impedance source this is fine, but stray capacitance will mean a high-impedance source may not settle fast enough.

Symptom would be cross-talk between a sensor and the next servo down the loop.

Incidentally you would make the code much smaller and cleaner by using arrays for the sensors and servos variables.

Dear Lefty
Thanks for your Help!! If i connect all the servos with an external power source, what voltage sould be applied and how many amperes???
Because im a begginer i would like to explain me how can i apply bypass caps and how they will affect my circuit.

HarisD:
Dear Lefty
Thanks for your Help!! If i connect all the servos with an external power source, what voltage sould be applied and how many amperes???

As I said 4 fresh AA alkiline batteries wired in series should work well enough for testing purposes. The power wires of the servos (usually red) would wire to the positive of the battery pack, the servos gound wires (usually black) would wire to the battery packs negative terminal. There is also a need to run a wire from battery negitive to arduino ground pin.

How many amps your 5 servos might draw is hard to answer as it depends on how large they are and how much mechanical load they are turning and if they are all to be able to move at the same time. I usually budget one amp of power capacity for each servo, but if they are small ones they proably will demand less then that. Again for just testing purposes 4 AA cells should work. Most servos need 4.5 to 6vdc voltage.

Because im a begginer i would like to explain me how can i apply bypass caps and how they will affect my circuit.

A typical bypass capacitor (.1ufd) is wired from the power wire to the ground wire at the device. I would first just try a proper power source for the servos and see if that corrects the problem or not.

Lefty

If you have a multimeter you can measure the stall current of one of the servos by moving it from the default position, then preventing it from moving and powering it up - don't hold it for long, its not rated for continuous stall load.

Hi.
MarkT can you help me?
I have used Arduino Uno, Flex Sensor 2.2, and Servo SG90
My servo is working but the angels are not correct of my Servo.
This is my code its an example of the Arduino CC

const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to

int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}

void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);

// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);

// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(2);
}

the angels are not correct

Hate it when that happens

I dont think so that it's servo issue

It can be the issue of flex sensor resistor