Hello, I am newbie in Arduino and I try to make a robot commended by bluetooth

const int enA = 4;
const int enB = 9;
const int Apin = 38;
const int Bpin = 32;
const int Cpin = 50;
const int Dpin = 45;
int trig = 12;
int echo = 11;
long lecture_echo;
long cm;
int x;
char m;
String inputString="";
void setup(){
pinMode(4,OUTPUT);
pinMode(9,OUTPUT);
pinMode(38,OUTPUT);
pinMode(32,OUTPUT);
pinMode(50,OUTPUT);
pinMode(45,OUTPUT);
Serial.begin(9600); // set the baud rate to 9600, same should be of your Serial Monitor
pinMode(12, OUTPUT);
digitalWrite(12, LOW);
pinMode(11, INPUT);

}

void loop(){

x == 0;

if(Serial.available()){
while(Serial.available() )
{
char inChar = (char)Serial.read(); //read the input
inputString += inChar; //make a string of the characters coming on serial
}
Serial.println(inputString);
while (Serial.available() > 0)
{ m = Serial.read() ; } // clear the serial buff
if(inputString == "f"){
do while(x==0){
detobe();
}
}
else if(inputString== "g"){
do while(x==1){
blue();

}

}

inputString = "";

}

void detobe(){
digitalWrite(enA,170);
digitalWrite(enB,170);
digitalWrite(trig, HIGH);
delayMicroseconds(10); // envoi d'une impulsion sur trig de 10 microsecondes
digitalWrite(trig, LOW);
lecture_echo = pulseIn(echo, HIGH);
cm = lecture_echo / 58; // lecture_echo340/(210000)

if( cm > 8 )
{

digitalWrite(Apin,LOW);
digitalWrite(Bpin,HIGH);
digitalWrite(Cpin,HIGH);
digitalWrite(Dpin,LOW);
//digitalWrite(ledPin2,HIGH);
//digitalWrite(ledPin1,HIGH);
//delay (2000);
//digitalWrite(ledPin2,HIGH);
//digitalWrite(ledPin1,LOW);

// digitalWrite(Apin,HIGH);
//digitalWrite(Bpin,LOW);
//digitalWrite(Cpin,LOW);
//digitalWrite(Dpin,LOW);
}

else
{

digitalWrite(Apin,HIGH);
digitalWrite(Bpin,LOW);
digitalWrite(Cpin,HIGH);
digitalWrite(Dpin,LOW);

}
if(Serial.available()){
while(Serial.available() )
{
char inChar = (char)Serial.read(); //read the input
inputString += inChar; //make a string of the characters coming on serial
}
Serial.println(inputString);
while (Serial.available() > 0)
{ m = Serial.read() ; } // clear the serial buff
if(inputString == "h"){
x == 1;
}
}
void blue() {

digitalWrite(enA,170);
digitalWrite(enB,170);
if(Serial.available()){
while(Serial.available() )
{
char inChar = (char)Serial.read(); //read the input
inputString += inChar; //make a string of the characters coming on serial
}
Serial.println(inputString);
while (Serial.available() > 0)
{ m = Serial.read() ; } // clear the serial buff

if(inputString == "a"){ //in case of 'a' turn the LED on
digitalWrite(Apin,HIGH);
digitalWrite(Bpin,LOW);
digitalWrite(Cpin,LOW);
digitalWrite(Dpin,HIGH);
}else if(inputString == "b"){ //incase of 'b' turn the LED off

digitalWrite(Apin,HIGH);
digitalWrite(Bpin,LOW);
digitalWrite(Cpin,HIGH);
digitalWrite(Dpin,LOW);
}
if(inputString== "c"){

digitalWrite(Apin,LOW);
digitalWrite(Bpin,HIGH);
digitalWrite(Cpin,LOW);
digitalWrite(Dpin,HIGH);
}else if (inputString == "d"){

digitalWrite(Apin,LOW);
digitalWrite(Bpin,HIGH);
digitalWrite(Cpin,HIGH);
digitalWrite(Dpin,LOW);
}

if (inputString== "e" ){

digitalWrite(Apin,LOW);
digitalWrite(Bpin,LOW);
digitalWrite(Cpin,LOW);
digitalWrite(Dpin,LOW);
}
if(inputString == "h"){
x == 1;
}

inputString = "";
}
}

Hello, I am newbie in Arduino and I try to make a robot commended by bluetooth. but I have a problem , when I check the program it tells me that the function is not declared

Please post the exact error message and USE CODE TAGS when posting code.

void loop(){

x == 0;

Pointless.

  if(inputString == "h"){
      x == 1;
    }

Ditto

Where does the loop() function end ?

It is difficult to see in your code, but if you select it the IDE and Auto Format it you will see that loop() has no end brace, hence the problem.

Once you have formatted it, if you post it here again please use code tags as described in read this before posting a programming question
which you either did not read or ignored.

When I compile this code I get a "In function 'void loop()': error: 'detobel' was not declared in this scope".
Why am I getting this error?

I use the variable x to exit from one function to another

thebest789456:
When I compile this code I get a "In function 'void loop()': error: 'detobel' was not declared in this scope".
Why am I getting this error?

Please modify your post and use the code button </>

so your code looks like this

and is easy to copy to a text editor. See How to use the Forum Your code is too long to study quickly without copying to a text editor.

When I can easily copy it to my text editor I may be able to help.

...R

I change some things to be more corecte , but it steal the same problem :roll_eyes:

const int enA = 4;
const int enB = 9;
const int Apin = 38;
const int Bpin = 32;
const int Cpin = 50;
const int Dpin = 45;
int trig = 12; 
int echo = 11; 
long lecture_echo; 
long cm;
int x;
char m;
String inputString="";
void setup(){
   pinMode(4,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(38,OUTPUT);
  pinMode(32,OUTPUT);
  pinMode(50,OUTPUT);
  pinMode(45,OUTPUT);
  Serial.begin(9600);   // set the baud rate to 9600, same should be of your Serial Monitor
  pinMode(12, OUTPUT); 
  digitalWrite(12, LOW); 
  pinMode(11, INPUT); 
  
}



void loop(){

x == 0;

  if(Serial.available()){
  while(Serial.available() )
    {
    char inChar = (char)Serial.read(); //read the input
      inputString += inChar;        //make a string of the characters coming on serial
    }
    Serial.println(inputString);
    while (Serial.available() > 0)  
    { m = Serial.read() ; }      // clear the serial buff
    if(inputString == "f"){
     do {
        detobe();
      }while(x==0);
    }
     else if(inputString== "g"){
    
      blue();   
        
     
     
    
    }

  
   inputString = "";
  
}
}

void detobe()
{
  digitalWrite(enA,170);
  digitalWrite(enB,170);
  digitalWrite(trig, HIGH); 
  delayMicroseconds(10); // envoi d'une impulsion sur trig de 10 microsecondes
  digitalWrite(trig, LOW); 
  lecture_echo = pulseIn(echo, HIGH); 
  cm = lecture_echo / 58; // lecture_echo*340/(2*10000)
  
    if( cm > 8 )
    {
      
      
      digitalWrite(Apin,LOW);
      digitalWrite(Bpin,HIGH);
      digitalWrite(Cpin,HIGH);
      digitalWrite(Dpin,LOW);
      //digitalWrite(ledPin2,HIGH);
      //digitalWrite(ledPin1,HIGH);
      //delay (2000);
//digitalWrite(ledPin2,HIGH);
      //digitalWrite(ledPin1,LOW);
      
     // digitalWrite(Apin,HIGH);
      //digitalWrite(Bpin,LOW);
      //digitalWrite(Cpin,LOW);
      //digitalWrite(Dpin,LOW);
    }
    
    else
    {
      
      digitalWrite(Apin,HIGH);
      digitalWrite(Bpin,LOW);
      digitalWrite(Cpin,HIGH);
      digitalWrite(Dpin,LOW);
      
    }
    if(Serial.available()){
  while(Serial.available() )
    {
    char inChar = (char)Serial.read(); //read the input
      inputString += inChar;       //make a string of the characters coming on serial
    } 
    Serial.println(inputString);
    while (Serial.available() > 0)  
    { m = Serial.read() ; }      // clear the serial buff
    if(inputString == "h"){
      x == 1;
    }
}

void blue() {
   do {
  digitalWrite(enA,170);
  digitalWrite(enB,170);
  if(Serial.available()){
  while(Serial.available() )
    {
    char inChar = (char)Serial.read(); //read the input
      inputString += inChar;       //make a string of the characters coming on serial
    } 
    Serial.println(inputString);
    while (Serial.available() > 0)  
    { m = Serial.read() ; }      // clear the serial buff
 
  
  
   if(inputString == "a"){  //in case of 'a' turn the LED on
      digitalWrite(Apin,HIGH);
      digitalWrite(Bpin,LOW);
      digitalWrite(Cpin,LOW);
      digitalWrite(Dpin,HIGH); 
    }else if(inputString == "b"){   //incase of 'b' turn the LED off
      
      digitalWrite(Apin,HIGH);
      digitalWrite(Bpin,LOW);
      digitalWrite(Cpin,HIGH);
      digitalWrite(Dpin,LOW);
    }
    if(inputString== "c"){
     
      digitalWrite(Apin,LOW);
      digitalWrite(Bpin,HIGH);
      digitalWrite(Cpin,LOW);
      digitalWrite(Dpin,HIGH);
    }else if (inputString == "d"){
      
       digitalWrite(Apin,LOW);
      digitalWrite(Bpin,HIGH);
      digitalWrite(Cpin,HIGH);
      digitalWrite(Dpin,LOW);
    }
    
    if (inputString== "e" ){
     
       digitalWrite(Apin,LOW);
      digitalWrite(Bpin,LOW);
      digitalWrite(Cpin,LOW);
      digitalWrite(Dpin,LOW);
    }
    if(inputString == "h"){
      x == 1;
    }
    
     inputString = "";
  }
  }while(x==1);
}

You still haven't fixed these:

x == 0;

x == 1;

== is a comparison, as written the code is asking "Does x equal 0?" and then doing nothing with the answer.
= is an assignment. "Make x have the value of 0", or "Make x have the value of 1".
Change them to x=0; and x=1;

You have done it again.

Where does the detobe() function end ? Somewhere before the start of the blue() function would be a good idea.

Why don't you try Auto Format as previously suggested ? The problem shows up immediately.

yes thank you so mutch UkHeliBob ;D

Did you add the missing } before this line?
void blue() {

CROSS ROADS YES i do ;D

How about these lines?
x==0;
x==1;
Did you change those to 1 = sign?

Here's another question for your logic flow:
This line,
while (x==0);
is the same as having

while (x==0){
// hang out here until x changes to not a 0
}

but you have no code that can change x to not a 0. What is the plan to let something change x?
You have the same later on with
while (x==1);

crossRoads
x is a variable that i use to exit from a function to another
if inputString = f i move to detobe function , then in detobe function when i'd lik to move to blue function i change the variable x to 1 what is mean x = 1 and finly i write "g" what is mean inputString = "g"
i hope that there is no fault :smiley: