One one side of the bread board the five flex sensors are powered by the Arduino's 5v and each flex sensor has a 10k resistor . On the other side of the bread board the 5 servos is powered by battery 4 pack delivering 6v.
I am using the Arduino's 5 analog inputs A0-A4 and attaching it the servos using digital output pins 2,3,4,5 and 7
When I bend flex A0 Servo2 moves independently
When I bend flex A1 Servos 3,4,5 and 7 moves simultaneous and not independently as I as had hope.
Any thoughts as to what is wrong
Can the Arduino Uno support operating 5 servos on 5 separate pins independently. or is the Arduino mega better suited for this project?
Another thing is this..two servos will work fine. When that three servo is added A0 and Servo2 works but when the third servo is added A1 operates Servos 2 and 3 simultaneous and A2 does not operate any of the servos.
pins A2-A4 don't work when everything is put together but they do work when tested by it self
Code: Select all
#include <Servo.h>
int flexpin=A0;
int flexpin1=A1;
int flexpin2=A2;
int flexpin3=A3;
int flexpin4=A4;
int pos=0;
int pos1=0;
int pos2=0;
int pos3=0;
int pos4=0;
Servo myservo;
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
int flex[20];
int flex1[20];
int flex2[20];
int flex3[20];
int flex4[20];
int flexsum=0;
int flexsum1=0;
int flexsum2=0;
int flexsum3=0;
int flexsum4=0;
void setup()
{
myservo.attach(2);
myservo1.attach(3);
myservo2.attach(4);
myservo3.attach(5);
myservo4.attach(7);
Serial.begin(9600);
}
void loop()
{
for(int x=0; x<20; x++)
{
flex[x]=analogRead(flexpin);
flex1[x]=analogRead(flexpin1);
flex2[x]=analogRead(flexpin2);
flex3[x]=analogRead(flexpin3);
flex4[x]=analogRead(flexpin4);
flexsum=flexsum+analogRead(flexpin);
flexsum1=flexsum1+analogRead(flexpin1);
flexsum2=flexsum1+analogRead(flexpin2);
flexsum3=flexsum1+analogRead(flexpin3);
flexsum4=flexsum1+analogRead(flexpin4);
delayMicroseconds(14);
}
flexsum=flexsum/20;
flexsum1=flexsum1/20;
flexsum2=flexsum2/20;
flexsum3=flexsum3/20;
flexsum4=flexsum4/20;
if(Serial.available())
{
Serial.println(flexsum);
Serial.println(flexsum1);
Serial.println(flexsum2);
Serial.println(flexsum3);
Serial.println(flexsum4);
delay(100);
}
pos=map(flexsum,870,800,0,180);
pos1=map(flexsum1,870,800,0,180);
pos2=map(flexsum2,870,800,0,180);
pos3=map(flexsum3,870,800,0,180);
pos4=map(flexsum4,870,800,0,180);
myservo.write(pos);
myservo1.write(pos1);
myservo2.write(pos2);
myservo3.write(pos3);
myservo4.write(pos4);
delay(200);
}