Controlling 2 servo using flex sensor in 2 arduino over serial (3DR radio)
controlling 2 servo using flex sensor in 2 arduino on serial (3dr radio telemetry)
iam using mega 2560(master) , arduino uno(slave)
actually, success control 1 servo 1 sensor (flex)
but, how control 2 servos or more? read this, still confusing
http://forum.arduino.cc/index.php?topic=180369.0
and here
http://forum.arduino.cc/index.php?topic=165050.0
this code control 1 servo 1 sensor
transmiter
and rx code
thx helping
iam using mega 2560(master) , arduino uno(slave)
actually, success control 1 servo 1 sensor (flex)
but, how control 2 servos or more? read this, still confusing
http://forum.arduino.cc/index.php?topic=180369.0
and here
http://forum.arduino.cc/index.php?topic=165050.0
this code control 1 servo 1 sensor
transmiter
code: [select]
#include <servo.h>
int flexpin=a2;
//int flexpin1=a1;
int pos=90;
//int pos1=90;
servo myservo, myservo1;
int flex[20];
//int flex1[20];
int flexsum=0;
void setup()
{
serial.begin(9600); //begin serial talk serial monitor
serial1.begin(9600); //begin serial talk rx arduino
serial.println("serial monitor connected");
delay(100);
}
void loop()
{
for(int x=0; x<20; x++)
{
flex=analogread(flexpin);
//flex1=analogread(flexpin1);
flexsum=flexsum+analogread(flexpin);
//flexsum1=flexsum1+analogread(flexpin1);
delaymicroseconds(14);
}
flexsum=flexsum/20;
//flexsum1=flexsum1/20;
if(serial.available())
{
serial.println(flexsum);
// serial.println(flexsum1);
delay(100);
}
pos=map(flexsum,530,770,180,60);
//pos1=map(flexsum1,870,800,0,180);
serial.println(pos);
serial.println(flexsum);
serial1.println(pos);
// myservo.write(pos);
//myservo1.write(pos1);
delay(200);
}
and rx code
code: [select]
#include <servo.h>
int val = 0;
int incoming = 0;
int pos = 0;
servo myservo, myservo1;
void setup()
{
myservo.attach(3);
serial.begin(9600);
}
void loop()
{
incoming = serial.available();
while (incoming != 0) //while there read
{
val = serial.parseint(); //reads integers integer rather asci. else returns 0
myservo.write(val);
}
}
thx helping
Arduino Forum > Using Arduino > Programming Questions > Controlling 2 servo using flex sensor in 2 arduino over serial (3DR radio)
arduino
Comments
Post a Comment