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);
}
}