5 Flex Sensors with 5 Servos

Good Evening
I m working on a Project which includes controlling 5 Servos with 5 Flex Sensors. I

have written the code and it works fine with one Flex Sensor but as soon as i attach more servos

and more flex sensors. After addition of more Flex Sensors whenever i flex any one of the

sensors all the Servos start moving like they all are synced or attached to the Same Flex Sensor. I

would really appreciate any help. Code can be viewed in the attachment and is also pasted below.

/////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <Servo.h>
// include the servo library

Servo servoMotor1,servoMotor2,servoMotor3,servoMotor4,servoMotor5;

// creates an instance of the servo object to control a servo

int analogPin1 = 0;
int analogPin2 = 1;
int analogPin3 = 2;
int analogPin4 = 3;
int analogPin5 = 4;
// the analog pin that the sensor is on

int analogValue1= 0;
int analogValue2= 0;
int analogValue3= 0;
int analogValue4= 0;
int analogValue5= 0;

// the value returned from the analog sensor
int servoPin1 = 2;
int servoPin2 = 3;
int servoPin3 = 4;
int servoPin4 = 5;
int servoPin5 = 6;

// Control pin for servo motor. As of Arduino 0017, can be any pin
void setup()
{

servoMotor1.attach(servoPin1);
// attaches the servo on pin 2 to the servo object;
servoMotor2.attach(servoPin2);
servoMotor3.attach(servoPin3);
servoMotor4.attach(servoPin4);
servoMotor5.attach(servoPin5);
}
void loop()
{
{
analogValue1 =analogRead(analogPin1);

analogValue1 =map(analogValue1, 0, 256, 0, 179);
// map the analog value (0-256) to the servo angle (0-179)
servoMotor1.write(analogValue1);
// write the new mapped analog value to set the servo position
delay(5000);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
{

analogValue2 =analogRead(analogPin2);
// read the analog input (value between 0 and 1023)
analogValue2 =map(analogValue2, 0, 256, 0, 179);
// map the analog value (0-1023) to the servo angle (0-179)
servoMotor2.write(analogValue2);
delay(5000);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////
{
analogValue3 =analogRead(analogPin3);
// read the analog input (value between 0 and 1023)
analogValue3 =map(analogValue3, 0, 256, 0, 179);
// map the analog value (0-1023) to the servo angle (0-179)
servoMotor3.write(analogValue3);
delay(5000);
}
{
/////////////////////////////////////////////////////////////////////////////////////////////////////
{
analogValue4 =analogRead(analogPin4);
// read the analog input (value between 0 and 1023)
analogValue4 =map(analogValue4, 0, 256, 0, 179);
// map the analog value (0-1023) to the servo angle (0-179)
servoMotor4.write(analogValue4);
delay(5000);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
{
analogValue5 =analogRead(analogPin5);
// read the analog input (value between 0 and 1023)
analogValue5 =map(analogValue5, 0, 256, 0, 179);
// map the analog value (0-1023) to the servo angle (0-179)
servoMotor5.write(analogValue5);
delay(5000);
}
}

What is powering the servos?

We are using External Battery with constant voltage for that purpose. Everything else is fine just the servos are not working according to the flex sensors. Thanks for the reply though.

What tedious code. You will have to learn about using loops and arrays and make that code a fifth of the size.

http://www.thebox.myzen.co.uk/Tutorial/Arrays.html

Anyway, how have you got the flex sensors wired up. Do you have a separate pull up resistor on each one, if so what value do you use?

One quick solution would be to read each analogue input twice to allow them to settle:-

analogValue3 =analogRead(analogPin3);
analogValue3 =analogRead(analogPin3);

But if they are wired up correctly there will be no need for that.

mjaved03:
We are using External Battery with constant voltage for that purpose.

Humour us and show us the schematic.....

I just needed suggestions and corrections in the code on how to stop all servos working together

as soon as i Flex only one Sensor. That is the main and big problem i have. All other things are just

fine.

I just needed suggestions and corrections in the code

It will take you 5 minutes to draw a schematic by hand, take a photo with your mobile, and post it.

Hi, "External Battery with constant voltage" does not exist.
Please a circuit diagram and what is your "Battery".
Have you got the neg of the "Battery" connected to the neg/gnd of the arduino?
Which Arduino are you using?

Tom....... :slight_smile:

TomGeorge:
Have you got the neg of the "Battery" connected to the neg/gnd of the arduino?

This is exactly what I was hoping a schematic would show...

mjaved03:
I just needed suggestions and corrections in the code on how to stop all servos working together

as soon as i Flex only one Sensor. That is the main and big problem i have. All other things are just

fine.

WHAT IS WRONG WITH YOU!!!
I gave you a suggestion to try. Have you tried it? Who knows because you did not say. Why should any one else bother to help you if you are being so ****.

I tried and it does not work. I m working on multiple projects that is why i dont have time to reply asap. Thanks for the reply Grump_Mike.

Well wen you have time post a schematic, until then nothing else can happen.

The way that your code is written, each sensor is read every 25 seconds because of the delay(5000) instructions. While this is probably not the cause of the jitter it does not lead to a very responsive system.