full working code for bluetooth controlled quadcopter

Not that it means anything at this stage, but your original question can be answered by...
Do nothing to the original flight control logic.

What you need to approach first is serialising the 6-ch R/C control channels into a single BT data stream. Transmit and receive.

Don't fiddle with a working flight platform until you have a reliable way to interact with it.

@all
thanks for the reply guyz...i m working on to develop my arduino programming skills...BY using pwm pins it will be easy but the thing is original library code by YMFC uses interrupt to generate pwm pulses...and i figured it out that without any inputs the drone remains in flight without crashing down.... and i have other option instead of sending few values to the quadcopter i can send various values according to position of seekbar....this code is for motor attached to pwm pin...but its very difficult to design PID control thats why i want to modify the exisitng code by YMFC..

#include <String.h>
#include <Servo.h>
//----------------------------------------------------------------------------------------
int n=4;
char Byte_received;
//String  read;
char prefix;
char text[4];
Servo motor;
int minimum=10,maximum=150;
//----------------------------------------------------------------------------------------
void change_speed(int speed) 
{
  speed = map(speed,0,100,minimum,maximum);
  motor.write(speed);  
}
//--------------------------------------
void arm_motor()
{
  // arm the speed controller by setting speed to 0 and delay for 1 second. 
  // Some speed controllers may need longer delay.
  change_speed(minimum);
  delay(2000);
  change_speed(78);
  delay(200);
  change_speed(minimum);  
}
//--------------------------------------
void send_data() 
{
  //
}
//----------------------------------------------------------------------------------------
void setup()
{
  Serial.begin(9600);
  motor.attach(9);
  arm_motor();
  Serial.write("Ready System");
  Serial.println ();
}
//----------------------------------------------------------------------------------------
void loop ()
{
  int y = Serial.available();
  //Serial.println(y);
  int cont=0;
  int suffix=0;   
  //--------------------------------------
  while (cont!=y && cont<n)
  {
    Byte_received = Serial.read();
    //read += Byte_received;
    text[cont]=Byte_received;
    cont++;
  }
  //--------------------------------------
  if (y>0)
  {
    //Serial.println(read);
    suffix = (atoi(&text[1]));
    Serial.print(text[0]);
    Serial.print("-");
    Serial.println(suffix);
 
    switch (text[0])
    {
      case 'M'://Speed               
        if(suffix >65 && suffix < maximum)
        {
          change_speed(suffix);
        }
        //speed += step;      
        //suffix=0;      
        //cont=0;
        //index=0;
        break;
  case '0'://Speed 
         change_speed(minimum);
        break;            
      default:
        break;  
    }
  }
  //--------------------------------------  
    
 send_data();   
 delay(500);  
}
//----------------------------------------------------------------------------------------

@lastchancename "Yes thats the thing i want to do...6 ch R/C into single bit stream of BT...help me with that"
@srnet i am trying my best i work day to night on same code to find out every possible way..but i dont know i m capable of cracking code still i m trying my best to understand...help me with that..yes it has flight controller designed by using arduino and i want to add just bluetooth command in it...it can remain stable through entire flight without having input..
@robin2 thank you..

@all
i will send one code today or tomorrow please let me know that it will map the 6 channels to one serial bluetooth data...

#include <String.h>
#include <Servo.h>
//----------------------------------------------------------------------------------------
int receiver_input_channel_1, receiver_input_channel_2, receiver_input_channel_3, receiver_input_channel_4;
int n=5;
char Byte_received;
char prefix;
char text[5];
//----------------------------------------------------------------------------------------
void setup()
{
  Serial.begin(9600);
}
//----------------------------------------------------------------------------------------
void loop ()
{
  int y = Serial.available();
  Serial.println(y);
  int cont=0;
  int suffix=0;   
  //--------------------------------------
  while (cont!=y && cont<n)
  {
    Byte_received = Serial.read();
    text[cont]=Byte_received;
    cont++;
  }
  //--------------------------------------
  if (y>0)
  {
    suffix = (atoi(&text[1]));
    Serial.print(text[0]);
    Serial.print("-");
    Serial.println(suffix);
  
    switch (text[0])
    {
      case 'R':    
         if(suffix >999 && suffix < 2001) 
         {      
         receiver_input_channel_1 = (suffix);
         Serial.println("Roll : ");
         Serial.println(receiver_input_channel_1);
         }
         break;
       case 'P':          
         if(suffix >999 && suffix < 2001) 
         {
         Serial.println("Pitch : ");  
         receiver_input_channel_2 = (suffix);
         Serial.println(receiver_input_channel_2);
         }
         break;
       case 'T':  
         if(suffix >999 && suffix < 2001)           
         {
         receiver_input_channel_3 = (suffix);
         Serial.println("Throttle : ");
         Serial.println(receiver_input_channel_3);
         }
         break;
       case 'Y':            
         if(suffix >999 && suffix < 2001)
         {
         Serial.println("Yaw : ");
         receiver_input_channel_4 = (suffix);
         Serial.println(receiver_input_channel_4);
         }
         break;       
       default:
         break;  
    }
  }
}
  //--------------------------------------

Is It going to work if i send
R1000
P1500
T2000
Y1898
through bluetooth to arduino???

little bit confused about this instruction
suffix = (atoi(&text[1]));

if i send P1000 then case P will get selected?? and suffix will contain 1000?? right??

Why change out a working RF system that has maybe a mile or so range with something that has what? 50yd range?

The quads I've built & flown would be in & out of bluetooth range in a couple seconds. Why is this something you want to do? What problem is it solving for you?

-jim lee

Anyway, Lets assume you have a wonderful reason. Sombody in Zambia is offering you $560,087,876 to develop this thing.

Here's what you do.

#1 Get your machine working the "Normal way". Your favorite flight controller, maybe AfroNaze, Mulitwii what have you and a good reliable RC setup. There is a good brand people are using now but I forget the name.

#2 You are now flying and gaining confidence. Good! Probably learning a LOT as you go. Now the next step is to add a second processor (arduino) between your receiver & your flight controller. For now just use it to "listen" to the control signals and run some LEDs. Be able to switch them from your RC transmitter.
Example : Second Aduino controlling lights

#3 We can see the inputs, we can act on them. Good! Now instead of just listening to the RC, lets change it so it passes through the signals from the receiver to the flight controller. You are still flying using the RC transmitter, but now all the info. is being passed through your secondary Arduino. And you can tweak it in code..

See where this is going?

#4 Add your bluetooth to the secondary Arduino. Set it up so its choosen as a flight controller by a switch on your RC transmitter. This way if some.. WHEN something goes wrong you can switch it back and possibly save your machine.

This should keep you busy for a bit.

Good luck & have fun!

-jim lee

nickstotle:
BY using pwm pins it will be easy

This reinforces the concerns I expressed in Reply #17

I cannot imagine what role the PWM pins will have in any communication system. In any case I presume they are already in use for controlling the speed of the motors.

I agree 100% with what @jimlee said "#1 Get your machine working the "Normal way".

...R

The motor controllers emulate servos. So you just "talk" to them as if they were.

-jim lee

jimLee:
The motor controllers emulate servos. So you just "talk" to them as if they were.

Fair enough. Then they don't need the PWM pins. But I still don't know what the OP thinks he is going to use the PWM pins for!

...R

Why do you want a Bluetooth controlled copter?
Bluetooth is designed for short range, and as it shares the same frequency spectrum as wifi its prone to interferance from wifi, hardly ideal for flying something around in the open.

@all i am not arduino designer i work for android and iots so i want basic bluetooth controlled quadcopter for my apps to get work with...please let me knw if it going to work or not...Soon i will try my code that it is working fine or not..wish me luck...thus code in post #22 works or not...
@jimlee i m trying it on leds my first program works fine in that i have mapped 6 differtn value according to characters now i m going to try my new code thus it is going to work or not...
@robin2 i m working on hardware part and making YMFC DIY quadcopter but i don't want to invest money on RF tx and rx it will cost 2500INR thats why i m asking you guyz can it will help or not if i don't find out any way then good to be using two arduino boards one or flight controller using RF tx n rx and one for bluetooth...
tell me about code i have made in post #22 thus it separate my A2000 to A and 2000 "suffix = (atoi(&text[1]));"

nickstotle:
@robin2 i m working on hardware part and making YMFC DIY quadcopter but i don't want to invest money on RF tx and rx it will cost 2500INR thats why i m asking you guyz can it will help or not if i don't find out any way then good to be using two arduino boards one or flight controller using RF tx n rx and one for bluetooth...

I am not able to make any connection between this comment and the remarks I made in Replies #17, #25 or #27

Maybe you are trying to say that you want to avoid testing the quadcopter with a conventional RC system because that would cost a lot extra. While I can understand the desire not to waste money I strongly recommend that you develop your modified system step-by-step from a working standard system.

And as I have already said, I don't think your understanding of programming concepts is sufficient to enable you to get the modified system to work EVEN IF the standard system works. Sorry if that sounds harsh, but if money is in short supply you should face up to reality before spending anything.

Build your programming knowledge with other projects and come back to the quadcopter in 6 or 12 months.

...R

@robin2 i know that i can't make it..but i have to give the try...i am modifying existing library that means that i am not able to design by my own...i have figured out way to send inputs at the same time by using string format"R1000P1000T1000Y1000" through cell phone or bluetooth controller..then i will decode this existing string by using my decoder code..as follows

int receiver_input_channel_1, receiver_input_channel_2, receiver_input_channel_3, receiver_input_channel_4;
int n=26;
String stringOne;
void setup() {
  // put your setup code here, to run once:
 Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:


if (Serial.available() > 0 && Serial.available() < n) 
  {
     stringOne = Serial.read();
     String text0 =stringOne.substring(0,5);
     String text1 =stringOne.substring(5,10); 
     String text2 =stringOne.substring(10,15);
     String text3 =stringOne.substring(15,20); 
     char charBuf0[6];
       text0.toCharArray(charBuf0, 6) ;
     char charBuf1[6];
       text1.toCharArray(charBuf1, 6) ;
     char charBuf2[6];
       text2.toCharArray(charBuf2, 6) ;
     char charBuf3[6];
       text3.toCharArray(charBuf3, 6) ;
     char decBuf[5]={charBuf0[0],charBuf1[0],charBuf2[0],charBuf3[0]};

  //--------------------------------------
  if (strcmp(decBuf,"RPTY")==0){
    
  //Serial.println("Matched");
  int suffixR = (atoi(&charBuf0[1]));//receiver_input_channel_1=(atoi(&charBuf0[1]));
  int suffixP = (atoi(&charBuf1[1]));
  int suffixT = (atoi(&charBuf2[1]));
  int suffixY = (atoi(&charBuf3[1]));
  if(suffixR >999 && suffixR < 2001) 
         {      
         receiver_input_channel_1 = (suffixR);
         Serial.println("Roll : ");
         Serial.println(receiver_input_channel_1);
         }
  if(suffixP >999 && suffixP < 2001) 
         {      
         receiver_input_channel_1 = (suffixP);
         Serial.println("Pitch : ");
         Serial.println(receiver_input_channel_2);
         }
  if(suffixT >999 && suffixT < 2001) 
         {      
         receiver_input_channel_1 = (suffixT);
         Serial.println("Throttle : ");
         Serial.println(receiver_input_channel_3);
         }
  if(suffixY >999 && suffixY < 2001) 
         {      
         receiver_input_channel_1 = (suffixY);
         Serial.println("Yaw : ");
         Serial.println(receiver_input_channel_4);
         }
    }
}

now the problem is..is it going to work or not...thnks all....

I can't think of any more to contribute that would be useful.

...R

now the problem is..is it going to work or no

No it will not work. Not even close.