I want to make a drone with Arduino....

I’m going to use WirtualWire for this. I didnt completely write the codes. I imagined that there are 2 motors but if these codes are correct, I will complete to 4 motors. Is there anyone who can say if the codes have a mistake?:
TRANSMITTER

#include <VirtualWire.h>
//YOLLAYICI

char *msg;
int joy;
int pot;

void setup()
{

pinMode(A1,INPUT);
pinMode(A0,INPUT);
vw_set_tx_pin(12);
vw_setup(2000);
}
void loop()
{

joy=analogRead(A1);
joy=map(joy,0,1023,0,5);
pot=analogRead(A0);
pot=map(pot,0,1023,0,4);

if(pot==0)
{
msg = “0”;
}
else if(pot==1&&joy==0)
{

msg = “1”;
vw_send((uint8_t *)msg, strlen(msg));
}
else if(pot==1&&joy==1)
{
msg = “2”;
vw_send((uint8_t *)msg, strlen(msg));
}

else if(pot==1&&joy==2)
{
msg = “3”;
vw_send((uint8_t *)msg, strlen(msg));
}
else if(pot==1&&joy==3)
{
msg = “4”;
vw_send((uint8_t *)msg, strlen(msg));
}
else if(pot==1&&joy==4)
{
msg = “5”;
vw_send((uint8_t *)msg, strlen(msg));
}
else if(pot==2&&joy==0)
{
msg = “6”;
vw_send((uint8_t *)msg, strlen(msg));
}
else if(pot==2&&joy==1)
{
msg = “7”;
vw_send((uint8_t *)msg, strlen(msg));
}
else if(pot==2&&joy==2)
{
msg = “8”;
vw_send((uint8_t *)msg, strlen(msg));
}
else if(pot==2&&joy==3)
{
msg = “9”;
vw_send((uint8_t *)msg, strlen(msg));
}
else if(pot==2&&joy==4)
{
msg = “a”;
}
else if(pot==3||pot==4&&joy==0||joy==1)
{
msg = “b”;
}
else if(pot==3||pot==4&&joy==2)
{
msg = “c”;
}
else if(pot==3||pot==4&&joy==3||joy==4)
{
msg = “d”;
}

}

RECEIVER

#include <VirtualWire.h>
//ALICI

char message;
void setup()
{

vw_setup(2000);
vw_rx_start();

pinMode(6, OUTPUT);
pinMode(5, OUTPUT);

}
void loop()
{

vw_set_rx_pin(2);
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

if (vw_get_message(buf, &buflen))
{
message = buf[0];

if (message == ‘0’)
{
analogWrite(6, 0);
analogWrite(5, 0);
}
else if (message == ‘1’)
{
analogWrite(6, 255);
analogWrite(5, 64);
}
else if (message == ‘2’)
{
analogWrite(6, 191);
analogWrite(5, 64);
}
else if (message == ‘3’)
{
analogWrite(6, 64);
analogWrite(5, 64);
}
else if (message == ‘4’)
{
analogWrite(6, 64);
analogWrite(5, 191);
}
else if (message == ‘5’)
{
analogWrite(6, 64);
analogWrite(5, 255);
}
else if (message == ‘6’)
{
analogWrite(6, 255);
analogWrite(5, 127);
}
else if (message == ‘7’)
{
analogWrite(6, 191);
analogWrite(5, 127);
}
else if (message == ‘8’)
{
analogWrite(6, 127);
analogWrite(5, 127);
}
else if (message == ‘9’)
{
analogWrite(6, 127);
analogWrite(5, 191);
}
else if(message==‘a’)
{
analogWrite(6, 127);
analogWrite(5, 255);
}
else if(message==‘b’)
{
analogWrite(6, 255);
analogWrite(5, 191);
}
else if(message==‘c’)
{
analogWrite(6, 191);
analogWrite(5, 191);
}
else if(message==‘d’)
{
analogWrite(6, 191);
analogWrite(5, 255);
}
}
}

copy your code as that:

#include <VirtualWire.h>
//YOLLAYICI

char *msg;
int joy;
int pot;

void setup()
{

  pinMode(A1,INPUT);
  pinMode(A0,INPUT);
  vw_set_tx_pin(12);
  vw_setup(2000);
}
void loop()
{
  
  joy=analogRead(A1);
  joy=map(joy,0,1023,0,5);
  pot=analogRead(A0);
  pot=map(pot,0,1023,0,4);
  
  if(pot==0)
{
   msg = "0";
}
  else if(pot==1&&joy==0)
  {
    
    msg = "1";

putting it between [cod] and [/cod]
you have to write “code”

This is transmitter code:
[#include <VirtualWire.h>
//YOLLAYICI

char *msg;
int joy;
int pot;

void setup()
{

pinMode(A1,INPUT);
pinMode(A0,INPUT);
vw_set_tx_pin(12);
vw_setup(2000);
}
void loop()
{

joy=analogRead(A1);
joy=map(joy,0,1023,0,5);
pot=analogRead(A0);
pot=map(pot,0,1023,0,4);

if(pot==0)
{
msg = “0”;
}
else if(pot==1&&joy==0)
{

msg = “1”;
vw_send((uint8_t *)msg, strlen(msg));
}
else if(pot==1&&joy==1)
{
msg = “2”;
vw_send((uint8_t *)msg, strlen(msg));
}

else if(pot==1&&joy==2)
{
msg = “3”;
vw_send((uint8_t *)msg, strlen(msg));
}
else if(pot==1&&joy==3)
{
msg = “4”;
vw_send((uint8_t *)msg, strlen(msg));
}
else if(pot==1&&joy==4)
{
msg = “5”;
vw_send((uint8_t *)msg, strlen(msg));
}
else if(pot==2&&joy==0)
{
msg = “6”;
vw_send((uint8_t *)msg, strlen(msg));
}
else if(pot==2&&joy==1)
{
msg = “7”;
vw_send((uint8_t *)msg, strlen(msg));
}
else if(pot==2&&joy==2)
{
msg = “8”;
vw_send((uint8_t *)msg, strlen(msg));
}
else if(pot==2&&joy==3)
{
msg = “9”;
vw_send((uint8_t *)msg, strlen(msg));
}
else if(pot==2&&joy==4)
{
msg = “a”;
}
else if(pot==3||pot==4&&joy==0||joy==1)
{
msg = “b”;
}
else if(pot==3||pot==4&&joy==2)
{
msg = “c”;
}
else if(pot==3||pot==4&&joy==3||joy==4)
{
msg = “d”;
}

} ]

and this is receiver code:
[#include <VirtualWire.h>
//ALICI

char message;
void setup()
{

vw_setup(2000);
vw_rx_start();

pinMode(6, OUTPUT);
pinMode(5, OUTPUT);

}
void loop()
{

vw_set_rx_pin(2);
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

if (vw_get_message(buf, &buflen))
{
message = buf[0];

if (message == ‘0’)
{
analogWrite(6, 0);
analogWrite(5, 0);
}
else if (message == ‘1’)
{
analogWrite(6, 255);
analogWrite(5, 64);
}
else if (message == ‘2’)
{
analogWrite(6, 191);
analogWrite(5, 64);
}
else if (message == ‘3’)
{
analogWrite(6, 64);
analogWrite(5, 64);
}
else if (message == ‘4’)
{
analogWrite(6, 64);
analogWrite(5, 191);
}
else if (message == ‘5’)
{
analogWrite(6, 64);
analogWrite(5, 255);
}
else if (message == ‘6’)
{
analogWrite(6, 255);
analogWrite(5, 127);
}
else if (message == ‘7’)
{
analogWrite(6, 191);
analogWrite(5, 127);
}
else if (message == ‘8’)
{
analogWrite(6, 127);
analogWrite(5, 127);
}
else if (message == ‘9’)
{
analogWrite(6, 127);
analogWrite(5, 191);
}
else if(message==‘a’)
{
analogWrite(6, 127);
analogWrite(5, 255);
}
else if(message==‘b’)
{
analogWrite(6, 255);
analogWrite(5, 191);
}
else if(message==‘c’)
{
analogWrite(6, 191);
analogWrite(5, 191);
}
else if(message==‘d’)
{
analogWrite(6, 191);
analogWrite(5, 255);
}
}
}
]

The code may work (for some definitions of work) but you will never be able to control a drone (I assume that you mean a multirotor) with it.

  joy=analogRead(A1);
  joy=map(joy,0,1023,0,5);
  pot=analogRead(A0);
  pot=map(pot,0,1023,0,4);

What do you imagine that you are going to control with a 5 position pot and a 4 position joystick ?

Insert [­code] before your code and [­/code] after it or select it in the forum editor and click the code icon (</>) top/left to have the forum do it for you.

[code]You put your code here[/code]

It will have only 3 high values.
[else if(pot==3||pot==4&&joy==3||joy==4)
{
msg = "d";
}/]
in these codes, while pot = 3 and 4, drone will be at the same height.

  joy=analogRead(A1);
  joy=map(joy,0,1023,0,5);
  pot=analogRead(A0);
  pot=map(pot,0,1023,0,4);

Can I ask... Did your code compile?

in these codes, while pot = 3 and 4, drone will be at the same height.

What will keep the drone at a fixed height ? Come to that, what will keep the drone level ?

harunresit:
I'm going to use WirtualWire for this. I didnt completely write the codes.

...

Sad to say this, but your level of programming expertise is not even close to successfully controlling a quad-copter or any other dynamic system.

You need to learn to walk before you can run ... not top mention fly.

:slight_smile:

Start with simpler tasks, and learn programming while doing it.

hello i completed the code and compiled but compiler didnt find a mistake

 #include <VirtualWire.h>
//YOLLAYICI

char *msg;
int joysag;
int joysol;
int pot;

void setup()
{

  pinMode(A1,INPUT);
  pinMode(A0,INPUT);
  pinMode(A2,INPUT);
  vw_set_tx_pin(12);
  vw_setup(2000);
}
void loop()
{
  joysag=analogRead(A2);
  joysag=map(joysag,0,1023,0,2);
  joysol=analogRead(A1);
  joysol=map(joysol,0,1023,0,2);
  pot=analogRead(A0);
  pot=map(pot,0,1023,0,2);
  
  if(pot==0)
{
   msg = "0";
   vw_send((uint8_t *)msg, strlen(msg));
}
  else if(pot==1&&joysag==1&&joysol==1)
  {
    
    msg = "1";
    vw_send((uint8_t *)msg, strlen(msg));
     }
  else if(pot==1&&joysol==1&&joysag==0)
  {
     msg = "2";
    vw_send((uint8_t *)msg, strlen(msg));
  }
   
  else if(pot==1&&joysol==1&&joysag==2)
  {
    msg = "3";
    vw_send((uint8_t *)msg, strlen(msg));
     }
  else if(pot==1&&joysol==0&&joysag==1)
  {
    msg = "4";
    vw_send((uint8_t *)msg, strlen(msg));
     }
  else if(pot==1&&joysol==2&&joysag==1)
  {
     msg = "5";
    vw_send((uint8_t *)msg, strlen(msg));
  }
  else if(pot==2&&joysol==1&&joysag==1)
  {
      msg = "6";
    vw_send((uint8_t *)msg, strlen(msg));
     }
  else if(pot==2&&joysol==1&&joysag==0)
  {
      msg = "7";
    vw_send((uint8_t *)msg, strlen(msg));
     }
  else if(pot==2&&joysol==1&&joysag==2)
  {
       msg = "8";
    vw_send((uint8_t *)msg, strlen(msg));
     }
  else if(pot==2&&joysol==0&&joysag==1)
  {
       msg = "9";
    vw_send((uint8_t *)msg, strlen(msg));
     }
     else if(pot==2&&joysol==2&&joysag==1)
     {
      msg = "a";
     }
     

}
 #include <VirtualWire.h>
//ALICI



char message;
void setup()
{

  vw_setup(2000);
  vw_rx_start();
  
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);


}
void loop()
{
 

 
  vw_set_rx_pin(2);
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
    
  if (vw_get_message(buf, &buflen))
  {
    message = buf[0];


    if (message == '0')
    {
      analogWrite(6, 0);
      analogWrite(5, 0);
      analogWrite(9, 0);
      analogWrite(10,0);
    }
    else if (message == '1')
    {
      analogWrite(6, 127);
      analogWrite(5, 127);
      analogWrite(9,127);
      analogWrite(10,127);
    }
    else if (message == '2')
    {
      analogWrite(6, 127);
      analogWrite(5, 255);
      analogWrite(9,127);
      analogWrite(10,127);
    }
    else if (message == '3')
    {
      analogWrite(6, 255);
      analogWrite(5, 127);
      analogWrite(9,127);
      analogWrite(10,127);
    }
    else if (message == '4')
    {
      analogWrite(6, 127);
      analogWrite(5, 127);
      analogWrite(9,255);
      analogWrite(10,127);
    }
    else if (message == '5')
    {
      analogWrite(6, 127);
      analogWrite(5, 127);
      analogWrite(9,127);
      analogWrite(10,255);
    }
    else if (message == '6')
    {
      analogWrite(6, 200);
      analogWrite(5, 200);
      analogWrite(9,200);
      analogWrite(10,200);
    }
    else if (message == '7')
    {
      analogWrite(6, 200);
      analogWrite(5, 255);
      analogWrite(9,200);
      analogWrite(10,200);
    }
    else if (message == '8')
    {
      analogWrite(6, 255);
      analogWrite(5, 200);
      analogWrite(9,200);
      analogWrite(10,200);
    }
    else if (message == '9')
    {
      analogWrite(6, 200);
      analogWrite(5, 200);
      analogWrite(9,255);
      analogWrite(10,200);
    }
    else if(message=='a')
    {
      analogWrite(6, 200);
      analogWrite(5, 200);
      analogWrite(9,200);
      analogWrite(10,255);
    }
  }
}

harunresit:
hello i completed the code and compiled but compiler didnt find a mistake

Then upload it and watch what happens. And fix your drone to the ground. Uncontrolled quads are dangerous.

lg, couka

Just checking: you know that Arducopter exists, right?

Just checking : Please tell me that you do not really intend to try and control a "drone" (horrible word) with your code.

UKHeliBob:
Just checking : Please tell me that you do not really intend to try and control a "drone" (horrible word) with your code.

What's wrong with the word "drone"?

Power_Broker:
What's wrong with the word "drone"?

It evokes memories of bagpipes.

Power_Broker:
What's wrong with the word "drone"?

The media have adopted it to describe multirotor radio controlled models but it is also used to describe remotely controlled weapons of war.

The battle is lost, but I am fairly sure that many members of the general public do not understand the difference and screaming headlines like "Airliner hit by drone at Heathrow airport" do not help. Of course, there were no headlines when it turned out that it was probably a plastic bag rather than an unmanned aerial vehicle that the pilot had seen, but that is the media for you.

harunresit:
hello i completed the code and compiled but compiler didnt find a mistake

Just to clarify here: The compiler isn't looking for mistakes (as in "that's a bad idea") but just syntactic errors.

The compiler may accept your code, that doesn't mean it will do what you want it to.

For example, this sentence: "I am going to make money by robbing a bank." is syntactically OK, but a bad idea.

yeah i am going to try to control drone with this code