NEED HELP !!!!

Hi,
I’ve got an Arduino Genuino R3, HC-05 bluetooth system, Motor shield Arduino official, and two RC Motor.
I want to control my cars (all of the motor), with my phone with the bluetooth but i try some project but always fails :

//#include <SoftwareSerial.h>
//char data = 0;
int data;
//SoftwareSerial Serial(0, 1);
void setup() {
  Serial.begin(9600);
  
  //Setup Channel A
  pinMode(12, OUTPUT); //Initiates Motor Channel A pin
  pinMode(9, OUTPUT); //Initiates Brake Channel A piné

  //Setup Channel B
  pinMode(13, OUTPUT); //Initiates Motor Channel A pin
  pinMode(8, OUTPUT);  //Initiates Brake Channel A pin
  
}

void loop(){
  
  if (Serial.available()> 0){    // Send data only when you receive data:
      data = Serial.read();        //Read the incoming data & store into data
      //Serial.print(data);          //Print Value inside data in Serial monitor
      //Serial.print("\n");        
      if(data == "1")              // Checks whether value of data is equal to 1
           //Motor A forward @ full speed
{
       digitalWrite(12, HIGH); //Establishes forward direction of Channel A
       digitalWrite(9, LOW);   //Disengage the Brake for Channel A
       digitalWrite(13, HIGH);  //Establishes backward direction of Channel B
       digitalWrite(8, LOW);   //Disengage the Brake for Channel B
}
       
      else if(data == "2")
{
        //Motor B backward @ half speed
       digitalWrite(13, LOW);  //Establishes backward direction of Channel B
       digitalWrite(8, LOW);   //Disengage the Brake for Channel B
       digitalWrite(12, LOW); //Establishes forward direction of Channel A
       digitalWrite(9, LOW);   //Disengage the Brake for Channel A
}

      else if(data == "3")
{

  //tourner d'un coté
       digitalWrite(12, LOW);  //Establishes backward direction of Channel A
       digitalWrite(9, LOW);   //Disengage the Brake for Channel A
       digitalWrite(13, LOW);  //Establishes backward direction of Channel B
       digitalWrite(8, HIGH);   //Disengage the Brake for Channel B
}

     else if(data == "4")
{
  //tourner de l'autre coté
       digitalWrite(12, LOW);  //Establishes backward direction of Channel A
       digitalWrite(9, HIGH);   //Disengage the Brake for Channel A
       digitalWrite(13, LOW);  //Establishes backward direction of Channel B
       digitalWrite(8, LOW);   //Disengage the Brake for Channel B

}
}
}

Someone can help me to do my bluetooth cars ?
Cheers,
LoadzFire

but always fails

That's almost as bad as "it doesn't work".

Try here

if(data == "1")

You can't compare to a string with ==

Maybe you meant to compare to the character '1'

if(data == '1')

I try all with ' / " nothing appened. Can you help me with the serial read (i think my error is here ), i don't undernstand how to read data from my phone with my arduino . Thank for your answer. Cheers LoadzFire

How do you have the phone connected to the Arduino? You're the only one who knows what you have set up. If you want our help with it you're going to have to describe it all to us. Don't be afraid to be verbose. Get it all out there. Pictures are good too. Draw a schematic. But get the details out to us somehow.

I try all with ' / " nothing appened

What does that mean?

You are running RC car motors from a motor shield? There is a good chance that the motor shield is not powerful enough to run motors like that. (or maybe its fine, don't know.)

If that's the case, just use an RC speed controller like the car originally would have. All you have to do is talk to it like an R/C servo using the servo.h lib. The RC speed controller will also provide power for the entire setup.

-jim lee

AWOL: What does that mean?

I mean i try my code with ' and with " and nothing change !

Show the amended code.

Delta_G:
How do you have the phone connected to the Arduino? You’re the only one who knows what you have set up. If you want our help with it you’re going to have to describe it all to us. Don’t be afraid to be verbose. Get it all out there. Pictures are good too. Draw a schematic. But get the details out to us somehow.

Here is a schema (I know it’s not great but…).

Here it is :
//#include <SoftwareSerial.h>
//char data = 0;
int data;
//SoftwareSerial Serial(0, 1);
void setup() {
Serial.begin(9600);

//Setup Channel A
pinMode(12, OUTPUT); //Initiates Motor Channel A pin
pinMode(9, OUTPUT); //Initiates Brake Channel A piné

//Setup Channel B
pinMode(13, OUTPUT); //Initiates Motor Channel A pin
pinMode(8, OUTPUT); //Initiates Brake Channel A pin

}

void loop(){

if (Serial.available()> 0){ // Send data only when you receive data:
data = Serial.read(); //Read the incoming data & store into data
//Serial.print(data); //Print Value inside data in Serial monitor
//Serial.print("\n");
if(data == “1”) // Checks whether value of data is equal to 1
//Motor A forward @ full speed
{
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
digitalWrite(13, HIGH); //Establishes backward direction of Channel B
digitalWrite(8, LOW); //Disengage the Brake for Channel B
}

else if(data == “2”)
{
//Motor B backward @ half speed
digitalWrite(13, LOW); //Establishes backward direction of Channel B
digitalWrite(8, LOW); //Disengage the Brake for Channel B
digitalWrite(12, LOW); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
}

else if(data == “3”)
{

//tourner d’un coté
digitalWrite(12, LOW); //Establishes backward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
digitalWrite(13, LOW); //Establishes backward direction of Channel B
digitalWrite(8, HIGH); //Disengage the Brake for Channel B
}

else if(data == “4”)
{
//tourner de l’autre coté
digitalWrite(12, LOW); //Establishes backward direction of Channel A
digitalWrite(9, HIGH); //Disengage the Brake for Channel A
digitalWrite(13, LOW); //Establishes backward direction of Channel B
digitalWrite(8, LOW); //Disengage the Brake for Channel B

}
}
}

     if(data == "1")

And now the corrected code, in code tags, please.

//#include <SoftwareSerial.h>
//char data = 0;
int data;
//SoftwareSerial Serial(0, 1);
void setup() {
  Serial.begin(9600);
 
  //Setup Channel A
  pinMode(12, OUTPUT); //Initiates Motor Channel A pin
  pinMode(9, OUTPUT); //Initiates Brake Channel A piné

  //Setup Channel B
  pinMode(13, OUTPUT); //Initiates Motor Channel A pin
  pinMode(8, OUTPUT);  //Initiates Brake Channel A pin
 
}

void loop(){
 
  if (Serial.available()> 0){    // Send data only when you receive data:
      data = Serial.read();        //Read the incoming data & store into data
      //Serial.print(data);          //Print Value inside data in Serial monitor
      //Serial.print("\n");       
      if(data == "1")              // Checks whether value of data is equal to 1
           //Motor A forward @ full speed
{
       digitalWrite(12, HIGH); //Establishes forward direction of Channel A
       digitalWrite(9, LOW);   //Disengage the Brake for Channel A
       digitalWrite(13, HIGH);  //Establishes backward direction of Channel B
       digitalWrite(8, LOW);   //Disengage the Brake for Channel B
}
       
      else if(data == "2")
{
        //Motor B backward @ half speed
       digitalWrite(13, LOW);  //Establishes backward direction of Channel B
       digitalWrite(8, LOW);   //Disengage the Brake for Channel B
       digitalWrite(12, LOW); //Establishes forward direction of Channel A
       digitalWrite(9, LOW);   //Disengage the Brake for Channel A
}

      else if(data == "3")
{

  //tourner d'un coté
       digitalWrite(12, LOW);  //Establishes backward direction of Channel A
       digitalWrite(9, LOW);   //Disengage the Brake for Channel A
       digitalWrite(13, LOW);  //Establishes backward direction of Channel B
       digitalWrite(8, HIGH);   //Disengage the Brake for Channel B
}

     else if(data == "4")
{
  //tourner de l'autre coté
       digitalWrite(12, LOW);  //Establishes backward direction of Channel A
       digitalWrite(9, HIGH);   //Disengage the Brake for Channel A
       digitalWrite(13, LOW);  //Establishes backward direction of Channel B
       digitalWrite(8, LOW);   //Disengage the Brake for Channel B

}
}
}

No, the corrected code, with single quotes.

That code does not compile because data is declared as an int and you are trying to compare it to a pointer to a string. Make data and what you are comparing it to the same data type ( char and ‘1’ etc would be good ) and you will have more success.

LoadzFire:

//#include <SoftwareSerial.h>

//char data = 0;
int data;
//SoftwareSerial Serial(0, 1);
void setup() {
  Serial.begin(9600);

//Setup Channel A
  pinMode(12, OUTPUT); //Initiates Motor Channel A pin
  pinMode(9, OUTPUT); //Initiates Brake Channel A piné

//Setup Channel B
  pinMode(13, OUTPUT); //Initiates Motor Channel A pin
  pinMode(8, OUTPUT);  //Initiates Brake Channel A pin

}

void loop(){

if (Serial.available()> 0){    // Send data only when you receive data:
      data = Serial.read();        //Read the incoming data & store into data
      //Serial.print(data);          //Print Value inside data in Serial monitor
      //Serial.print("\n");     
      if(data == “1”)              // Checks whether value of data is equal to 1
          //Motor A forward @ full speed
{
      digitalWrite(12, HIGH); //Establishes forward direction of Channel A
      digitalWrite(9, LOW);  //Disengage the Brake for Channel A
      digitalWrite(13, HIGH);  //Establishes backward direction of Channel B
      digitalWrite(8, LOW);  //Disengage the Brake for Channel B
}
     
      else if(data == “2”)
{
        //Motor B backward @ half speed
      digitalWrite(13, LOW);  //Establishes backward direction of Channel B
      digitalWrite(8, LOW);  //Disengage the Brake for Channel B
      digitalWrite(12, LOW); //Establishes forward direction of Channel A
      digitalWrite(9, LOW);  //Disengage the Brake for Channel A
}

else if(data == “3”)
{

//tourner d’un coté
      digitalWrite(12, LOW);  //Establishes backward direction of Channel A
      digitalWrite(9, LOW);  //Disengage the Brake for Channel A
      digitalWrite(13, LOW);  //Establishes backward direction of Channel B
      digitalWrite(8, HIGH);  //Disengage the Brake for Channel B
}

else if(data == “4”)
{
  //tourner de l’autre coté
      digitalWrite(12, LOW);  //Establishes backward direction of Channel A
      digitalWrite(9, HIGH);  //Disengage the Brake for Channel A
      digitalWrite(13, LOW);  //Establishes backward direction of Channel B
      digitalWrite(8, LOW);  //Disengage the Brake for Channel B

}
}
}

You don’t need the Software Serial library if you’re using the pins 0 and 1 from the Arduino, the Arduino will automatically see that you’re using another ‘Serial’. Also the code won’t upload if you have your wires connected to 0 and 1 on the arduino, remove those wires while you’re uploading the code and then put them back in place.

thank you i will try with the single quote !

Hi, Here is a pictureof my robot and my code (and it's not work ).

char data = 0;
void setup() {
  Serial.begin(9600);
  
  //Setup Channel A
  pinMode(12, OUTPUT); //Initiates Motor Channel A pin
  pinMode(9, OUTPUT); //Initiates Brake Channel A piné

  //Setup Channel B
  pinMode(13, OUTPUT); //Initiates Motor Channel A pin
  pinMode(8, OUTPUT);  //Initiates Brake Channel A pin
  
}

void loop(){
  
  if (Serial.available() > 0) // Send data only when you receive data:
  {   
      data = Serial.read();        //Read the incoming data & store into data
      Serial.print(data);          //Print Value inside data in Serial monitor
      Serial.print("\n");        
      if(data == '1')              // Checks whether value of data is equal to 1
           //Motor A forward @ full speed
{
       digitalWrite(12, HIGH); //Establishes forward direction of Channel A
       digitalWrite(9, LOW);   //Disengage the Brake for Channel A
       digitalWrite(13, HIGH);  //Establishes backward direction of Channel B
       digitalWrite(8, LOW);   //Disengage the Brake for Channel B
}
       
      if(data == '2')
{
        //Motor B backward @ half speed
       digitalWrite(13, LOW);  //Establishes backward direction of Channel B
       digitalWrite(8, LOW);   //Disengage the Brake for Channel B
       digitalWrite(12, LOW); //Establishes forward direction of Channel A
       digitalWrite(9, LOW);   //Disengage the Brake for Channel A
}

      if(data == '3')
{

  //turn
       digitalWrite(12, LOW);  //Establishes backward direction of Channel A
       digitalWrite(9, LOW);   //Disengage the Brake for Channel A
       digitalWrite(13, LOW);  //Establishes backward direction of Channel B
       digitalWrite(8, HIGH);   //Disengage the Brake for Channel B
}

     if(data == '4')
{
  //turn
       digitalWrite(12, LOW);  //Establishes backward direction of Channel A
       digitalWrite(9, HIGH);   //Disengage the Brake for Channel A
       digitalWrite(13, LOW);  //Establishes backward direction of Channel B
       digitalWrite(8, LOW);   //Disengage the Brake for Channel B

}
     if(data == '5')
{
  //STOP ALL
       digitalWrite(12, LOW);  //Establishes backward direction of Channel A
       digitalWrite(9, HIGH);   //Disengage the Brake for Channel A
       digitalWrite(13, LOW);  //Establishes backward direction of Channel B
       digitalWrite(8, HIGH);   //Disengage the Brake for Channel B

}
}
}

and it's not work

Whatever that means.

AWOL:
Whatever that means.

The motor dont move !