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!!!
