5 Flex Sensors with 5 Servos
good evening
m working on project includes controlling 5 servos 5 flex sensors.
have written code , works fine 1 flex sensor attach more servos
and more flex sensors. after addition of more flex sensors whenever flex 1 of
sensors servos start moving synced or attached same flex sensor.
would appreciate help. code can viewed in attachment , pasted below.
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <servo.h>
// include servo library
servo servomotor1,servomotor2,servomotor3,servomotor4,servomotor5;
// creates instance of servo object control servo
int analogpin1 = 0;
int analogpin2 = 1;
int analogpin3 = 2;
int analogpin4 = 3;
int analogpin5 = 4;
// analog pin sensor on
int analogvalue1= 0;
int analogvalue2= 0;
int analogvalue3= 0;
int analogvalue4= 0;
int analogvalue5= 0;
// value returned analog sensor
int servopin1 = 2;
int servopin2 = 3;
int servopin3 = 4;
int servopin4 = 5;
int servopin5 = 6;
// control pin servo motor. of arduino 0017, can pin
void setup()
{
servomotor1.attach(servopin1);
// attaches servo on pin 2 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 analog value (0-256) servo angle (0-179)
servomotor1.write(analogvalue1);
// write new mapped analog value set servo position
delay(5000);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
{
analogvalue2 =analogread(analogpin2);
// read analog input (value between 0 , 1023)
analogvalue2 =map(analogvalue2, 0, 256, 0, 179);
// map analog value (0-1023) servo angle (0-179)
servomotor2.write(analogvalue2);
delay(5000);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
{
analogvalue3 =analogread(analogpin3);
// read analog input (value between 0 , 1023)
analogvalue3 =map(analogvalue3, 0, 256, 0, 179);
// map analog value (0-1023) servo angle (0-179)
servomotor3.write(analogvalue3);
delay(5000);
}
{
/////////////////////////////////////////////////////////////////////////////////////////////////////
{
analogvalue4 =analogread(analogpin4);
// read analog input (value between 0 , 1023)
analogvalue4 =map(analogvalue4, 0, 256, 0, 179);
// map analog value (0-1023) servo angle (0-179)
servomotor4.write(analogvalue4);
delay(5000);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
{
analogvalue5 =analogread(analogpin5);
// read analog input (value between 0 , 1023)
analogvalue5 =map(analogvalue5, 0, 256, 0, 179);
// map analog value (0-1023) servo angle (0-179)
servomotor5.write(analogvalue5);
delay(5000);
}
}
m working on project includes controlling 5 servos 5 flex sensors.
have written code , works fine 1 flex sensor attach more servos
and more flex sensors. after addition of more flex sensors whenever flex 1 of
sensors servos start moving synced or attached same flex sensor.
would appreciate help. code can viewed in attachment , pasted below.
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <servo.h>
// include servo library
servo servomotor1,servomotor2,servomotor3,servomotor4,servomotor5;
// creates instance of servo object control servo
int analogpin1 = 0;
int analogpin2 = 1;
int analogpin3 = 2;
int analogpin4 = 3;
int analogpin5 = 4;
// analog pin sensor on
int analogvalue1= 0;
int analogvalue2= 0;
int analogvalue3= 0;
int analogvalue4= 0;
int analogvalue5= 0;
// value returned analog sensor
int servopin1 = 2;
int servopin2 = 3;
int servopin3 = 4;
int servopin4 = 5;
int servopin5 = 6;
// control pin servo motor. of arduino 0017, can pin
void setup()
{
servomotor1.attach(servopin1);
// attaches servo on pin 2 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 analog value (0-256) servo angle (0-179)
servomotor1.write(analogvalue1);
// write new mapped analog value set servo position
delay(5000);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
{
analogvalue2 =analogread(analogpin2);
// read analog input (value between 0 , 1023)
analogvalue2 =map(analogvalue2, 0, 256, 0, 179);
// map analog value (0-1023) servo angle (0-179)
servomotor2.write(analogvalue2);
delay(5000);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
{
analogvalue3 =analogread(analogpin3);
// read analog input (value between 0 , 1023)
analogvalue3 =map(analogvalue3, 0, 256, 0, 179);
// map analog value (0-1023) servo angle (0-179)
servomotor3.write(analogvalue3);
delay(5000);
}
{
/////////////////////////////////////////////////////////////////////////////////////////////////////
{
analogvalue4 =analogread(analogpin4);
// read analog input (value between 0 , 1023)
analogvalue4 =map(analogvalue4, 0, 256, 0, 179);
// map analog value (0-1023) servo angle (0-179)
servomotor4.write(analogvalue4);
delay(5000);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
{
analogvalue5 =analogread(analogpin5);
// read analog input (value between 0 , 1023)
analogvalue5 =map(analogvalue5, 0, 256, 0, 179);
// map analog value (0-1023) servo angle (0-179)
servomotor5.write(analogvalue5);
delay(5000);
}
}
what powering servos?
Arduino Forum > Using Arduino > Project Guidance > 5 Flex Sensors with 5 Servos
arduino
Comments
Post a Comment