For the past couple of weeks I have been working on an RC plane. I have everything working accept for two things:
1.)I cannot get the elevator servo to work right.
#1 Description: I have tried to attach the elevator servo to the up and down motion of the joystick but every time I try to do that it moves with the ailerons(meaning three servos move at once). I have attached an image of this for a visual.
2.)My second problem is that I want the aileron servos to move in opposing directions to each other but I can't seem to figure out how to do that.
I have also attached the code of the transmitter and receiver so that you can see what I am running on my boards.
-Thanks-
Receiver:
#include<SoftwareSerial.h>
#include <Servo.h>
Servo esc;
Servo el;
Servo rudd;
Servo aile1;
Servo aile2;
String input;
int throttle, thr;
int aileron1, ail1;
int aileron2, ail2;
int elevator, ele;
int rudder, rud;
int boundLow;
int boundHigh;
const char COMMA = ',';
SoftwareSerial hc12(7, 8);
void setup() {
el.attach(11);
rudd.attach(6);
aile1.attach(5);
aile2.attach(3);
esc.attach(10);
Serial.begin(9600);
hc12.begin(9600);
esc.write(170);
delay(2000);
esc.write(90);
delay(2000);
esc.write(140);
delay(2000);
esc.write(90);
delay(2000);
Serial.write("Ports are attached and serial has begun\n");
Serial.write("ESC Callibration Complete\n");
Serial.write("Setup Complete");
}
void loop() {
if(Serial.available())
{
input = Serial.readStringUntil('\n');
if (input.length() > 0)
{
// Serial.println(input);
boundLow = input.indexOf(COMMA);
throttle = input.substring(0, boundLow).toInt();
boundHigh = input.indexOf(COMMA, boundLow+1);
aileron1 = input.substring(boundLow+1, boundHigh).toInt();
boundHigh = input.indexOf(COMMA, boundLow+1);
aileron2 = input.substring(boundLow+1, boundHigh).toInt();
boundLow = input.indexOf(COMMA, boundHigh+1);
elevator = input.substring(boundHigh+1, boundLow).toInt();
rudder = input.substring(boundLow+1).toInt();
esc.write(throttle);
el.write(elevator);
rudd.write(rudder);
aile1.write(aileron1);
aile2.write(aileron2);
delay(10);}
}
}
Transmitter:
#include <SoftwareSerial.h>
#include <Servo.h>
SoftwareSerial hc12(2, 3);
Servo esc;
int thr, ail1, ail2, ele, rud;
void setup() {
esc.attach(10);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A5, INPUT);
pinMode(A7, INPUT);
pinMode(A2, INPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
hc12.begin(9600);
}
void loop() {
ele = map(analogRead(A0), 0, 1023, 0, 180);
rud = map(analogRead(A1), 0, 1023, 0, 180);
thr = map(analogRead(A7), 0, 1023, 0, 180);
ail1 = map(analogRead(A5), 0, 1023, 0, 180);
ail2 = map(analogRead(A5), 0, 1023, 0, 180);
hc12.print(thr);
hc12.print(",");
hc12.print(ail1);
hc12.print(",");
hc12.print(ail2);
hc12.print(",");
hc12.print(ele);
hc12.print(",");
hc12.print(rud);
hc12.println("");
Serial.print(thr);
Serial.print(",");
Serial.print(ail1);
Serial.print(",");
Serial.print(ail2);
Serial.print(",");
Serial.print(ele);
Serial.print(",");
Serial.print(rud);
Serial.println("");
delay(100);
}
Reciever-Code.ino (1.56 KB)
Transmitter-Code.ino (1.05 KB)
4765909E-4496-4625-B332-1E7FFDAC688F.pdf (1.17 MB)