Rc boat

Hey guys i'm making a rc boat. it is using 2 motors for thrust and a sevo to control a rudder to steer. the servo is controlled using a joystick pot. im using a l293d to control the motors since they both run on 9v each. the wireless transmission is done via rf modules. im using 2 arduino uno's. this is my first arduino projects so i am not very familiar with the arduino ide. can you guys help me with the code.Thnx in advance.

can you guys help me with the code.

Here's a start:

// Add some stuff here

void setup()
{
   // Add some stuff here
}

void loop()
{
   // Add some stuff here
}

When you understand what you want to do, just follow the comments.

i need help with the "add some stuff here".

PaulS:
Here's a start:

// Add some stuff here

void setup()
{
  // Add some stuff here
}

void loop()
{
  // Add some stuff here
}




When you understand what you want to do, just follow the comments.

:smiley:

Times two, since he's using two arduinos!

suersaiyangod:
Hey guys i'm making a rc boat. it is using 2 motors for thrust and a sevo to control a rudder to steer. the servo is controlled using a joystick pot. im using a l293d to control the motors since they both run on 9v each. the wireless transmission is done via rf modules. im using 2 arduino uno's. this is my first arduino projects so i am not very familiar with the arduino ide. can you guys help me with the code.Thnx in advance.

Perhaps start at ... the beginning? Can you program? Did you understand the blink sketch? Have you tried reading buttons? Do you know how to make functions()? Classes?

There's so much to learn, and have fun doing it. :slight_smile:

Starting with a way-too-advanced project relative to skills, just results in confusion and demotivation.

As I said before, this is a resource group, not a manufacturing team. Please consider that I'm not offended, nor angry or upset. Just trying to urge you to do something that you can learn from, and not something that leaves you clueless. Ok?

:slight_smile:

Oh, and if you are in fact not clueless as to how to do this, you may ask questions about whether your reasoning and implementation ideas are sound.

:slight_smile:

i need help with the "add some stuff here".

Send me your address, and your credit card number. I'll book a flight and be right there.
I'll whack with a clue by four until you understand that coding is about the last thing that you do.

You write code to implement requirements. You do not write a thing until you understand the requirements that have been provided by the customer.

Since you are the customer, and you haven't provided any requirements, there is no coding to do yet.

suersaiyangod:
Hey guys i'm making a rc boat. it is using 2 motors for thrust and a sevo to control a rudder to steer. the servo is controlled using a joystick pot. im using a l293d to control the motors since they both run on 9v each. the wireless transmission is done via rf modules. im using 2 arduino uno's. this is my first arduino projects so i am not very familiar with the arduino ide. can you guys help me with the code.Thnx in advance.

It sounds from this as if you have some part of the program working. If so please post the code and explain what extra stuff you are having trouble with.

What RF modules are you using?

...R

Hi,

What RF modules do you have?

Tom... :slight_smile:

Hey guys i found this code from a website:

//Define the input pins for the joystick and the variables to keep track of its state

int vertical = A0,horizontal = A1,vVal,hVal,vZero,hZero;

void setup()

{//Here we set up everyting....

  Serial.begin(4800);

  //Set the initial "zero" vertical position value of the joystick

  vZero = map(analogRead(vertical),0,1023,0,255);

  //Set the initial "zero" horizontal position value of the joystick  

  hZero = map(analogRead(horizontal),0,1023,0,255);

}

void loop()

{ //This will happen over and over and over and over again......

  //Read the vertical pot value

  vVal = map(analogRead(vertical),0,1023,0,255);

  //Read the horizontal pot value  

  hVal = map(analogRead(horizontal),0,1023,0,255);

  //Declare variables to store the cardinal distances from the "zero" point

  //and an offset point to activate a direction  

  int FVal = 0,BVal = 0,RVal = 0,LVal = 0,centerOffset = 2;

  //Find the distance from the ("zero" position value +/- the offset value) 

  //for forward and backwards

  //If the joystick is pushed up passed the "zero" point + the offset value         

  if(vVal > (vZero + centerOffset))

  {

    //store the distance up from the "zero" point

    FVal = vVal - vZero;

    //clear any previous distance from the bottom side    

    BVal = 0;

  }

  //If the joystick is pushed down passed the "zero" point - the offset value

  else if(vVal < (vZero - centerOffset))

  {

    //store the distance down from the "zero" point

    BVal = vZero - vVal;

    //clear any previous distance from the top side    

    FVal = 0;

  }

  //Find the distances from the ("zero" position value +/- the offset value) 

  //for left and right

  //If the joystick is pushed left passed the "zero" point + the offset value

  if(hVal > (hZero + centerOffset))

  {

    //store the distance left from the "zero" point

    LVal = hVal;

    //clear any previous distance from the right side    

    RVal = 0;

  }

  //If the joystick is pushed right passed the "zero" point - the offset value

  else if(hVal < (hZero - centerOffset))

  {

    //store the distance right from the "zero" point

    RVal = hZero - hVal + hZero;

    //clear any previous distance from the left side    

    LVal = 0;

  }

  //Find the largest of the four and that's the direction we are going

  //If the joystick is pushed furthest forward 

  

  //If the joystick is pushed furthest left 

  if(LVal > RVal && LVal > FVal && LVal > BVal)

  {

    //then send 'L' through usart

    Serial.write("L");

    //Show what happened in the serial monitor

    Serial.println("L");

  }

  //If the joystick is pushed furthest right 

  else if(RVal > LVal && RVal > FVal && RVal > BVal)

  {

    //then send 'R' through usart

    Serial.write("R");

    //Show what happened in the serial monitor    

    Serial.println("R");

  }
 
  else if(FVal > LVal && FVal > RVal && FVal > BVal)

  {
  Serial.write("F");
  Serial.println("F");  
  }

  else if(BVal > FVal && BVal > LVal && BVal > RVal)
  {
    Serial.write("B");
    Serial.println("B");
    }
  else

  {

    //The character U keeps continuous 0's and 1's on the serial line which

    Serial.write('U');

    //helps with synchronization at the receiver side    

    Serial.println("Not Moving");

  }

}

and i changed it to this:

//Define the input pins for the joystick and the variables to keep track of its state

int horizontal = A0,hVal,hZero;
String Vala;
int Valb;
int buttonStatef = 0;
int buttonStateb = 0;
void setup()

{//Here we set up everyting....

 Serial.begin(4800);
 //Set the initial "zero" horizontal position value of the joystick  

 hZero = map(analogRead(horizontal),0,1023,0,255);


pinMode(6, OUTPUT);
pinMode(7, OUTPUT);

pinMode(12, INPUT);
pinMode(11, INPUT);
}

void loop()

{ //This will happen over and over and over and over again......
 

 hVal = map(analogRead(horizontal),0,1023,0,255);

 //Declare variables to store the cardinal distances from the "zero" point

 //and an offset point to activate a direction  

 int FVal = 0,BVal = 0,RVal = 0,LVal = 0,centerOffset = 2;

buttonStatef = digitalRead(12);
buttonStateb = digitalRead(11);

if(buttonStatef == HIGH && buttonStateb == HIGH)
{
 Vala = 0;
}

else if( buttonStateb == HIGH)
{
  Vala = "B";
}

 else if ( buttonStatef == HIGH)

{
Vala = "F";
}

else { 
 Vala = 0;
}
 if(hVal > (hZero + centerOffset))

 {

   //store the distance left from the "zero" point

   LVal = hVal;

   //clear any previous distance from the right side    

   RVal = 0;

 }

 //If the joystick is pushed right passed the "zero" point - the offset value

 else if(hVal < (hZero - centerOffset))

 {

   //store the distance right from the "zero" point

   RVal = hZero - hVal + hZero;

   //clear any previous distance from the left side    

   LVal = 0;

 }

 //Find the largest of the four and that's the direction we are going

 //If the joystick is pushed furthest forward 

 

 //If the joystick is pushed furthest left 

 if(LVal > RVal)

 {
Valb = LVal;

 }

 //If the joystick is pushed furthest right 

 else if(RVal > LVal)

 {

 Valb = RVal;

 }

 else

 {

 Valb = 0;

   
 }

{
Serial.write(Valb && Vala);
Serial.println(Valb && Vala);
}


}

while compiling this code i got an error saying “ambiguous overload for ‘operator=’ (operand types are ‘String’ and ‘int’)”

i dont know what this means because string can hold both characters and numbers. i might be wrong as i have only learnt visual basics and a bit of ‘c’ before the summer holidays.

Serial.write(Valb && Vala);
Serial.println(Valb && Vala);

What's that?

AWOL:
What's that?

And why are Vala and Valb different types?

i am using 433 MGz rf modules. like this one

AWOL:

Serial.write(Valb && Vala);

Serial.println(Valb && Vala);



What's that?

it sends the values through the rf transmitter and displays them in serial monitor.
Vala telles the motor move through these keys “F” for forward, “B” for backwards and 0 (the motors dont move), since it has both characters and numbers i kept it as string and since Valb only tells the pot position which is in numbers i kept is as int

You completely misunderstand what the && does. You can NOT use it that way.

so then how can i send the value of both Vala and Valb? shud i first send Vala and then send Valb like this:

Serial.write(Valb);
Serial.write(Vala);

So i changed the code a bit and it got compiled without any errors. will it work:

//Define the input pins for the joystick and the variables to keep track of its state

int horizontal = A0,hVal,hZero;
String Vala;
int Valb;
int buttonStatef = 0;
int buttonStateb = 0;
void setup()

{//Here we set up everyting....

  Serial.begin(4800);
  //Set the initial "zero" horizontal position value of the joystick  

  hZero = map(analogRead(horizontal),0,1023,0,255);


pinMode(6, OUTPUT);
pinMode(7, OUTPUT);

pinMode(12, INPUT);
pinMode(11, INPUT);
}

void loop()

{ //This will happen over and over and over and over again......
  

  hVal = map(analogRead(horizontal),0,1023,0,255);

  //Declare variables to store the cardinal distances from the "zero" point

  //and an offset point to activate a direction  

  int FVal = 0,BVal = 0,RVal = 0,LVal = 0,centerOffset = 2;

buttonStatef = digitalRead(12);
buttonStateb = digitalRead(11);

if(buttonStatef == HIGH && buttonStateb == HIGH)
{
  Vala = "U";
}

else if( buttonStateb == HIGH)
{
   Vala = "B";
}
 
  else if ( buttonStatef == HIGH)

{
 Vala = "F";
}

 else { 
  Vala = "U";
 }
  if(hVal > (hZero + centerOffset))

  {

    //store the distance left from the "zero" point

    LVal = hVal;

    //clear any previous distance from the right side    

    RVal = 0;

  }

  //If the joystick is pushed right passed the "zero" point - the offset value

  else if(hVal < (hZero - centerOffset))

  {

    //store the distance right from the "zero" point

    RVal = hZero - hVal + hZero;

    //clear any previous distance from the left side    

    LVal = 0;

  }

  //Find the largest of the four and that's the direction we are going

  //If the joystick is pushed furthest forward 

  

  //If the joystick is pushed furthest left 

  if(LVal > RVal)

  {
Valb = LVal;

  }

  //If the joystick is pushed furthest right 

  else if(RVal > LVal)

  {

  Valb = RVal;

  }
 
  else

  {

  Valb = 0;

    
  }

{
Serial.write(Valb && Vala);
Serial.println(Valb && Vala);
}


}

suersaiyangod:
So i changed the code a bit and it got compiled without any errors. will it work:

Don't ask us. Tell us.

The only way to answer your question is to test the program.

...R

Serial.write(Valb && Vala);
Serial.println(Valb && Vala);

I'm sure I've asked this before, but I'll try again - what's that?

i dont have any clue on how to sort the information when the reciever reciers the code. can u guys give me pointers on the reciever code?thnx

suersaiyangod:
i dont have any clue on how to sort the information when the reciever reciers the code.

You have to explain much more clearly what you are having a problem with.

I get the impression you have grabbed a program from somewhere and you don’t understand how it works. And to make things even more complicated you made changes to it.

There are so many ways for a program to be wrong that it is essential to learn how it works before you do anything else. If you are making a curry you may get away with experimentally adding a bit of that or a little of the other. But you can’t do that with a program.

…R